Skip to content

Commit

Permalink
[Decode]Log enhancement for DPB log
Browse files Browse the repository at this point in the history
  • Loading branch information
huangli2018 authored and gfxVPLsdm committed Dec 6, 2024
1 parent 2d12bea commit 2c86789
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 0 deletions.
1 change: 1 addition & 0 deletions _studio/shared/include/mfx_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mfx_trace.h"
#include "mfx_utils_logging.h"
#include "mfx_utils_perf.h"
#include "mfx_decode_dpb_logging.h"
#include "mfx_timing.h"
#include "mfxsurfacepool.h"
#include "mfx_error.h"
Expand Down
2 changes: 2 additions & 0 deletions _studio/shared/mfx_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ target_sources(mfx_logging
include/mfx_unified_h264d_logging.h
include/mfx_unified_av1d_logging.h
include/mfx_unified_vp9d_logging.h
include/mfx_decode_dpb_logging.h
src/mfx_utils_logging.cpp
src/mfx_utils_perf.cpp
src/mfx_unified_decode_logging.cpp
src/mfx_unified_h265d_logging.cpp
src/mfx_unified_h264d_logging.cpp
src/mfx_unified_av1d_logging.cpp
src/mfx_unified_vp9d_logging.cpp
src/mfx_decode_dpb_logging.cpp
)

target_include_directories(mfx_logging
Expand Down
41 changes: 41 additions & 0 deletions _studio/shared/mfx_logging/include/mfx_decode_dpb_logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <stdint.h>
#include <string>
#include <fstream>
#include <sstream>
#include <memory>

#define MFX_MAX_DPBLOG_FILENAME_LEN 260
#define MFX_MAX_PATH_LENGTH 256


#define DPBLOG_PRINT(funtion,line, change, frame, count) \
if(dpb_logger) \
{ \
uintptr_t address = reinterpret_cast<uintptr_t>(frame); \
dpb_logger->Addlog(funtion, line, change, address, count); \
}

class DPBLog
{
public:

DPBLog();
~DPBLog();
void Addlog(const std::string& funtion, int line, std::string change, uintptr_t frameaddress, uint32_t refoucnter);
int32_t getPid();
int32_t getTid();
static DPBLog* getInstance();

//flush
void Flushlog();
static std::string dpbFilePath;

private:
std::ostringstream Logbuffer;
static std::shared_ptr<DPBLog> instance;
};

extern DPBLog* dpb_logger;

152 changes: 152 additions & 0 deletions _studio/shared/mfx_logging/src/mfx_decode_dpb_logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#include "mfx_config.h"
#include <iostream>
#include <stdarg.h>
#include <iomanip>
#include <pthread.h>
#include "unistd.h"
#include <sys/stat.h>

#include "mfx_decode_dpb_logging.h"


DPBLog* dpb_logger = nullptr;
std::string DPBLog::dpbFilePath = "Initialize";
std::shared_ptr<DPBLog> DPBLog::instance = nullptr;


int32_t DpbSecureStringPrint(char* buffer, size_t bufSize, size_t length, const char* const format, ...)
{
int32_t iRet = 0;
va_list var_args;

va_start(var_args, format);
iRet = vsnprintf(buffer, bufSize, format, var_args);
va_end(var_args);

return iRet;
}

#define Dpb_SecureStringPrint(buffer, bufSize, length, format, ...) \
DpbSecureStringPrint(buffer, bufSize, length, format, ##__VA_ARGS__)

DPBLog::DPBLog()
{
instance = nullptr;
}


DPBLog::~DPBLog()
{
if (instance)
{
try
{
Flushlog();
}
catch (...)
{

}
}
}


std::string GetFunctionName(const std::string& input)
{
// find last ':'
size_t pos = input.rfind(':');
if (pos == std::string::npos)
{
// if not find ':', return empty
return "";
}
// extract ':'
return input.substr(pos + 1);
}

void DPBLog::Addlog(const std::string& funtion, int line, std::string change, uintptr_t frameaddress, uint32_t refoucnter)
{
//get function name
std::string function_name = GetFunctionName(funtion);
if (!function_name.empty())
{
Logbuffer << std::left
<< std::setw(25) << function_name << ":"
<< std::setw(10) << std::dec << line
<< std::setw(16) << std::hex<< std::uppercase << frameaddress << "refcounter "
<< std::setw(5) << std::dec << change
<< std::setw(5) << std::dec << refoucnter << std::endl;
}
else
{
Logbuffer << "Not find function name" << std::endl;
}
}

void DPBLog::Flushlog()
{

int32_t pid = getPid();
int32_t tid = getTid();

const char* const dpb_log_path_fmt = "%s/dpb_pid%d_tid%d.txt";


char logfilename[MFX_MAX_DPBLOG_FILENAME_LEN + 1] = { '\0' };
Dpb_SecureStringPrint(logfilename, MFX_MAX_PATH_LENGTH + 1, MFX_MAX_PATH_LENGTH + 1,
dpb_log_path_fmt, dpbFilePath.c_str(), pid, tid);


if (access(dpbFilePath.c_str(), 0) == -1)
{
int folder_exist_status = mkdir(dpbFilePath.c_str(), S_IRWXU);
if (folder_exist_status == -1)
{
return;
}
}

std::ofstream file(logfilename);
if (file.is_open()) {
file << Logbuffer.str(); // write into file
Logbuffer.str(""); // reset buffer
Logbuffer.clear(); // clear buffer
file.close();
}
else {
std::cerr << "Failed to open log file." << std::endl;
}
}


DPBLog* DPBLog::getInstance()
{
if (instance == nullptr)
{
instance = std::make_shared<DPBLog>();
if (!instance)
{
return nullptr;
}
}

return instance.get();
}

int32_t DPBLog::getPid()
{
int32_t pid = getpid();
return pid;
}

int32_t DPBLog::getTid()
{
int32_t tid = pthread_self();
return tid;
}






12 changes: 12 additions & 0 deletions _studio/shared/mfx_trace/src/mfx_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mfxdefs.h"
#include "mfx_trace.h"
#include "mfx_utils_perf.h"
#include "mfx_decode_dpb_logging.h"

static mfx_reflect::AccessibleTypesCollection g_Reflection;

Expand Down Expand Up @@ -271,6 +272,17 @@ mfxTraceU32 MFXTrace_GetRegistryParams(void)
PerfUtility::perfFilePath = iter->second;
}
}
else if (iter->first == "VPL DPB LOG" && stoi(iter->second))
{
dpb_logger = DPBLog::getInstance();
}
else if (iter->first == "VPL DPB PATH")
{
if (!iter->second.empty())
{
DPBLog::dpbFilePath = iter->second;
}
}
}
}
}
Expand Down

0 comments on commit 2c86789

Please sign in to comment.