[Project64] Cleanup Trace Files
This commit is contained in:
parent
146f295b10
commit
ac1211eb76
|
@ -5,240 +5,240 @@ BOOL TraceClosed = FALSE;
|
|||
|
||||
class CTraceLog
|
||||
{
|
||||
std::vector<CTraceModule *> m_Modules;
|
||||
CriticalSection m_CS;
|
||||
std::vector<CTraceModule *> m_Modules;
|
||||
CriticalSection m_CS;
|
||||
|
||||
public:
|
||||
CTraceLog()
|
||||
{
|
||||
}
|
||||
~CTraceLog() { CloseTrace(); }
|
||||
CTraceLog()
|
||||
{
|
||||
}
|
||||
~CTraceLog() { CloseTrace(); }
|
||||
|
||||
CTraceModule * AddTraceModule(CTraceModule * TraceModule);
|
||||
CTraceModule * RemoveTraceModule(CTraceModule * TraceModule);
|
||||
void CloseTrace(void);
|
||||
void WriteTrace(TraceType Type, LPCTSTR Message);
|
||||
void WriteTraceF(TraceType Type, LPCTSTR strFormat, va_list args);
|
||||
CTraceModule * AddTraceModule(CTraceModule * TraceModule);
|
||||
CTraceModule * RemoveTraceModule(CTraceModule * TraceModule);
|
||||
void CloseTrace(void);
|
||||
void WriteTrace(TraceType Type, LPCTSTR Message);
|
||||
void WriteTraceF(TraceType Type, LPCTSTR strFormat, va_list args);
|
||||
};
|
||||
|
||||
CTraceModule * CTraceLog::AddTraceModule(CTraceModule * TraceModule)
|
||||
{
|
||||
CGuard Guard(m_CS);
|
||||
CGuard Guard(m_CS);
|
||||
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if (m_Modules[i] == TraceModule)
|
||||
{
|
||||
return TraceModule;
|
||||
}
|
||||
}
|
||||
m_Modules.push_back(TraceModule);
|
||||
return TraceModule;
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if (m_Modules[i] == TraceModule)
|
||||
{
|
||||
return TraceModule;
|
||||
}
|
||||
}
|
||||
m_Modules.push_back(TraceModule);
|
||||
return TraceModule;
|
||||
}
|
||||
|
||||
CTraceModule * CTraceLog::RemoveTraceModule(CTraceModule * TraceModule)
|
||||
{
|
||||
CGuard Guard(m_CS);
|
||||
CGuard Guard(m_CS);
|
||||
|
||||
for (std::vector<CTraceModule *>::iterator itr = m_Modules.begin(); itr != m_Modules.end(); itr++)
|
||||
{
|
||||
if ((*itr) == TraceModule)
|
||||
{
|
||||
m_Modules.erase(itr);
|
||||
return TraceModule;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
for (std::vector<CTraceModule *>::iterator itr = m_Modules.begin(); itr != m_Modules.end(); itr++)
|
||||
{
|
||||
if ((*itr) == TraceModule)
|
||||
{
|
||||
m_Modules.erase(itr);
|
||||
return TraceModule;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CTraceLog::CloseTrace(void)
|
||||
{
|
||||
CGuard Guard(m_CS);
|
||||
CGuard Guard(m_CS);
|
||||
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if (m_Modules[i])
|
||||
delete m_Modules[i];
|
||||
}
|
||||
m_Modules.clear();
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if (m_Modules[i])
|
||||
delete m_Modules[i];
|
||||
}
|
||||
m_Modules.clear();
|
||||
}
|
||||
|
||||
void CTraceLog::WriteTraceF(TraceType Type, LPCTSTR strFormat, va_list args)
|
||||
{
|
||||
const int nMaxSize = 32 * 1024;
|
||||
TCHAR pBuffer[nMaxSize];
|
||||
const int nMaxSize = 32 * 1024;
|
||||
TCHAR pBuffer[nMaxSize];
|
||||
|
||||
_vsntprintf(pBuffer, nMaxSize, strFormat, args);
|
||||
pBuffer[nMaxSize - 1] = 0;
|
||||
WriteTrace(Type, pBuffer);
|
||||
_vsntprintf(pBuffer, nMaxSize, strFormat, args);
|
||||
pBuffer[nMaxSize - 1] = 0;
|
||||
WriteTrace(Type, pBuffer);
|
||||
}
|
||||
|
||||
void CTraceLog::WriteTrace(TraceType Type, LPCTSTR Message)
|
||||
{
|
||||
CGuard Guard(m_CS);
|
||||
CGuard Guard(m_CS);
|
||||
|
||||
if (Type != TraceNone)
|
||||
{
|
||||
bool WriteToLog = false;
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
WriteToLog = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!WriteToLog) { return; }
|
||||
}
|
||||
if (Type != TraceNone)
|
||||
{
|
||||
bool WriteToLog = false;
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
WriteToLog = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!WriteToLog) { return; }
|
||||
}
|
||||
|
||||
if ((Type & TraceNoHeader) == 0)
|
||||
{
|
||||
TCHAR pBuffer[300];
|
||||
int nPos = 0;
|
||||
if ((Type & TraceNoHeader) == 0)
|
||||
{
|
||||
TCHAR pBuffer[300];
|
||||
int nPos = 0;
|
||||
|
||||
SYSTEMTIME sysTime;
|
||||
::GetLocalTime(&sysTime);
|
||||
SYSTEMTIME sysTime;
|
||||
::GetLocalTime(&sysTime);
|
||||
|
||||
nPos = _stprintf(pBuffer, _T("%04d/%02d/%02d %02d:%02d:%02d.%03d %05d: "), sysTime.wYear,
|
||||
sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds,
|
||||
::GetCurrentThreadId()
|
||||
);
|
||||
nPos = _stprintf(pBuffer, _T("%04d/%02d/%02d %02d:%02d:%02d.%03d %05d: "), sysTime.wYear,
|
||||
sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds,
|
||||
::GetCurrentThreadId()
|
||||
);
|
||||
|
||||
// show the debug level
|
||||
if (Type == TraceNone) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("None : ")); }
|
||||
else if ((Type & TraceError) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Error : ")); }
|
||||
else if ((Type & TraceSettings) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Setting: ")); }
|
||||
else if ((Type & TraceGfxPlugin) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Gfx : ")); }
|
||||
else if ((Type & TraceDebug) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Debug : ")); }
|
||||
else if ((Type & TraceRecompiler) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Recomp : ")); }
|
||||
else if ((Type & TraceRSP) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("RSP : ")); }
|
||||
else if ((Type & TraceTLB) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("TLB : ")); }
|
||||
else if ((Type & TraceValidate) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Valid : ")); }
|
||||
else if ((Type & TraceAudio) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Audio : ")); }
|
||||
else { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Unknown: ")); }
|
||||
// show the debug level
|
||||
if (Type == TraceNone) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("None : ")); }
|
||||
else if ((Type & TraceError) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Error : ")); }
|
||||
else if ((Type & TraceSettings) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Setting: ")); }
|
||||
else if ((Type & TraceGfxPlugin) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Gfx : ")); }
|
||||
else if ((Type & TraceDebug) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Debug : ")); }
|
||||
else if ((Type & TraceRecompiler) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Recomp : ")); }
|
||||
else if ((Type & TraceRSP) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("RSP : ")); }
|
||||
else if ((Type & TraceTLB) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("TLB : ")); }
|
||||
else if ((Type & TraceValidate) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Valid : ")); }
|
||||
else if ((Type & TraceAudio) != 0) { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Audio : ")); }
|
||||
else { nPos += _stprintf(pBuffer + nPos, _T("%s"), _T("Unknown: ")); }
|
||||
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
m_Modules[i]->Write(pBuffer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
m_Modules[i]->Write(Message, true);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
m_Modules[i]->Write(pBuffer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < (int)m_Modules.size(); i++)
|
||||
{
|
||||
if ((m_Modules[i]->GetTraceLevel() & Type) != 0)
|
||||
{
|
||||
m_Modules[i]->Write(Message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CTraceLog & GetTraceObjet(void)
|
||||
{
|
||||
static CTraceLog TraceLog;
|
||||
return TraceLog;
|
||||
static CTraceLog TraceLog;
|
||||
return TraceLog;
|
||||
}
|
||||
|
||||
void WriteTrace(TraceType Type, LPCTSTR Message)
|
||||
{
|
||||
if (TraceClosed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GetTraceObjet().WriteTrace(Type, Message);
|
||||
if (TraceClosed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GetTraceObjet().WriteTrace(Type, Message);
|
||||
}
|
||||
|
||||
void WriteTraceF(TraceType Type, LPCTSTR strFormat, ...)
|
||||
{
|
||||
if (TraceClosed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, strFormat);
|
||||
GetTraceObjet().WriteTraceF(Type, strFormat, args);
|
||||
va_end(args);
|
||||
if (TraceClosed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, strFormat);
|
||||
GetTraceObjet().WriteTraceF(Type, strFormat, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
CTraceModule * AddTraceModule(CTraceModule * TraceModule)
|
||||
{
|
||||
if (TraceClosed)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
GetTraceObjet().AddTraceModule(TraceModule);
|
||||
return TraceModule;
|
||||
if (TraceClosed)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
GetTraceObjet().AddTraceModule(TraceModule);
|
||||
return TraceModule;
|
||||
}
|
||||
|
||||
CTraceModule * RemoveTraceModule(CTraceModule * TraceModule)
|
||||
{
|
||||
return GetTraceObjet().RemoveTraceModule(TraceModule);
|
||||
return GetTraceObjet().RemoveTraceModule(TraceModule);
|
||||
}
|
||||
|
||||
void CloseTrace(void)
|
||||
{
|
||||
TraceClosed = true;
|
||||
GetTraceObjet().CloseTrace();
|
||||
TraceClosed = true;
|
||||
GetTraceObjet().CloseTrace();
|
||||
}
|
||||
|
||||
CTraceFileLog::CTraceFileLog(LPCTSTR FileName, bool FlushFile) :
|
||||
m_FlushFile(FlushFile)
|
||||
{
|
||||
m_hLogFile.SetFlush(false);
|
||||
m_hLogFile.SetTruncateFile(true);
|
||||
m_hLogFile.SetMaxFileSize(5 * MB);
|
||||
m_hLogFile.Open(FileName, Log_Append);
|
||||
m_hLogFile.SetFlush(false);
|
||||
m_hLogFile.SetTruncateFile(true);
|
||||
m_hLogFile.SetMaxFileSize(5 * MB);
|
||||
m_hLogFile.Open(FileName, Log_Append);
|
||||
}
|
||||
|
||||
CTraceFileLog::CTraceFileLog(LPCTSTR FileName, bool FlushFile, LOG_OPEN_MODE eMode, size_t dwMaxFileSize) :
|
||||
m_FlushFile(FlushFile)
|
||||
{
|
||||
enum { MB = 1024 * 1024 };
|
||||
enum { MB = 1024 * 1024 };
|
||||
|
||||
m_hLogFile.SetFlush(false);
|
||||
m_hLogFile.SetTruncateFile(true);
|
||||
m_hLogFile.SetFlush(false);
|
||||
m_hLogFile.SetTruncateFile(true);
|
||||
|
||||
if (dwMaxFileSize < 3 || dwMaxFileSize > 2047)
|
||||
{ /* Clamp file size to 5 MB if it exceeds 2047 or falls short of 3. */
|
||||
dwMaxFileSize = 5;
|
||||
}
|
||||
m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB);
|
||||
if (dwMaxFileSize < 3 || dwMaxFileSize > 2047)
|
||||
{ /* Clamp file size to 5 MB if it exceeds 2047 or falls short of 3. */
|
||||
dwMaxFileSize = 5;
|
||||
}
|
||||
m_hLogFile.SetMaxFileSize(dwMaxFileSize * MB);
|
||||
|
||||
m_hLogFile.Open(FileName, eMode);
|
||||
m_hLogFile.Open(FileName, eMode);
|
||||
}
|
||||
|
||||
CTraceFileLog::~CTraceFileLog()
|
||||
{
|
||||
TraceClosed = true;
|
||||
TraceClosed = true;
|
||||
}
|
||||
|
||||
void CTraceFileLog::Write(LPCTSTR Message, bool EndOfLine)
|
||||
{
|
||||
if (!m_hLogFile.IsOpen()) { return; }
|
||||
if (!m_hLogFile.IsOpen()) { return; }
|
||||
|
||||
CGuard Section(m_CriticalSection);
|
||||
m_hLogFile.Log(Message);
|
||||
if (EndOfLine)
|
||||
{
|
||||
m_hLogFile.Log(_T("\r\n"));
|
||||
if (m_FlushFile)
|
||||
{
|
||||
m_hLogFile.Flush();
|
||||
}
|
||||
}
|
||||
CGuard Section(m_CriticalSection);
|
||||
m_hLogFile.Log(Message);
|
||||
if (EndOfLine)
|
||||
{
|
||||
m_hLogFile.Log(_T("\r\n"));
|
||||
if (m_FlushFile)
|
||||
{
|
||||
m_hLogFile.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CTraceFileLog::SetFlushFile(bool bFlushFile)
|
||||
{
|
||||
m_FlushFile = bFlushFile;
|
||||
m_FlushFile = bFlushFile;
|
||||
}
|
||||
|
||||
void CDebugTraceLog::Write(const char * Message, bool EndOfLine)
|
||||
{
|
||||
OutputDebugString(Message);
|
||||
if (EndOfLine)
|
||||
{
|
||||
OutputDebugString("\n");
|
||||
}
|
||||
}
|
||||
OutputDebugString(Message);
|
||||
if (EndOfLine)
|
||||
{
|
||||
OutputDebugString("\n");
|
||||
}
|
||||
}
|
|
@ -8,12 +8,12 @@ class CTraceModule
|
|||
TraceLevel m_Type;
|
||||
|
||||
public:
|
||||
CTraceModule () { m_Type = TrLvError; }
|
||||
virtual ~CTraceModule () {}
|
||||
CTraceModule() { m_Type = TrLvError; }
|
||||
virtual ~CTraceModule() {}
|
||||
|
||||
inline void SetTraceLevel ( TraceLevel Type ) { m_Type = Type; }
|
||||
inline TraceLevel GetTraceLevel ( void ) const { return m_Type; }
|
||||
virtual void Write ( const char * Message, bool EndOfLine ) = 0;
|
||||
inline void SetTraceLevel(TraceLevel Type) { m_Type = Type; }
|
||||
inline TraceLevel GetTraceLevel(void) const { return m_Type; }
|
||||
virtual void Write(const char * Message, bool EndOfLine) = 0;
|
||||
};
|
||||
|
||||
class CTraceFileLog : public CTraceModule
|
||||
|
@ -25,19 +25,19 @@ class CTraceFileLog : public CTraceModule
|
|||
bool m_FlushFile;
|
||||
|
||||
public:
|
||||
CTraceFileLog (const char * FileName, bool FlushFile = true);
|
||||
CTraceFileLog(const char * FileName, bool FlushFile = true);
|
||||
CTraceFileLog(const char * FileName, bool FlushFile, LOG_OPEN_MODE eMode, size_t dwMaxFileSize = 5);
|
||||
virtual ~CTraceFileLog ();
|
||||
virtual ~CTraceFileLog();
|
||||
|
||||
void Write ( const char * Message, bool EndOfLine );
|
||||
void SetFlushFile ( bool bFlushFile );
|
||||
void Write(const char * Message, bool EndOfLine);
|
||||
void SetFlushFile(bool bFlushFile);
|
||||
};
|
||||
|
||||
class CDebugTraceLog : public CTraceModule
|
||||
{
|
||||
public:
|
||||
void Write ( const char * Message, bool EndOfLine );
|
||||
void Write(const char * Message, bool EndOfLine);
|
||||
};
|
||||
|
||||
CTraceModule * AddTraceModule ( CTraceModule * TraceModule ); // Must be created with new
|
||||
CTraceModule * RemoveTraceModule ( CTraceModule * TraceModule ); // Is not automaticly deleted
|
||||
CTraceModule * AddTraceModule(CTraceModule * TraceModule); // Must be created with new
|
||||
CTraceModule * RemoveTraceModule(CTraceModule * TraceModule); // Is not automaticly deleted
|
||||
|
|
|
@ -2,30 +2,30 @@
|
|||
|
||||
enum TraceType
|
||||
{
|
||||
TraceNone = 0x00000000,
|
||||
TraceError = 0x00000001,
|
||||
TraceSettings = 0x00000002,
|
||||
TraceGfxPlugin = 0x00000004,
|
||||
TraceDebug = 0x00000010,
|
||||
TraceRecompiler = 0x00000020,
|
||||
TraceRSP = 0x00000040,
|
||||
TraceTLB = 0x00000080,
|
||||
TraceValidate = 0x00000100,
|
||||
TraceAudio = 0x00000200,
|
||||
TraceProtectedMem = 0x00000400,
|
||||
TraceNoHeader = 0x80000000,
|
||||
TraceNone = 0x00000000,
|
||||
TraceError = 0x00000001,
|
||||
TraceSettings = 0x00000002,
|
||||
TraceGfxPlugin = 0x00000004,
|
||||
TraceDebug = 0x00000010,
|
||||
TraceRecompiler = 0x00000020,
|
||||
TraceRSP = 0x00000040,
|
||||
TraceTLB = 0x00000080,
|
||||
TraceValidate = 0x00000100,
|
||||
TraceAudio = 0x00000200,
|
||||
TraceProtectedMem = 0x00000400,
|
||||
TraceNoHeader = 0x80000000,
|
||||
};
|
||||
|
||||
enum TraceLevel
|
||||
{
|
||||
//Handle Existing Code
|
||||
TrLvError = TraceError,
|
||||
TrLv1 = TraceSettings | TrLvError,
|
||||
TrLv2 = TrLv1 | TraceDebug,
|
||||
TrLvError = TraceError,
|
||||
TrLv1 = TraceSettings | TrLvError,
|
||||
TrLv2 = TrLv1 | TraceDebug,
|
||||
TrlvGfxPlugin = TraceGfxPlugin,
|
||||
TrLvAll = ~TraceNoHeader,
|
||||
TrLvAll = ~TraceNoHeader,
|
||||
};
|
||||
|
||||
void WriteTrace ( TraceType Type, const char * Message );
|
||||
void WriteTraceF ( TraceType Type, const char * strFormat, ... );
|
||||
void CloseTrace ( void ); //Free's all memory associated with trace
|
||||
void WriteTrace(TraceType Type, const char * Message);
|
||||
void WriteTraceF(TraceType Type, const char * strFormat, ...);
|
||||
void CloseTrace(void); //Free's all memory associated with trace
|
||||
|
|
Loading…
Reference in New Issue