mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-04 18:09:53 +03:00
add additional logging information
This commit is contained in:
@@ -365,6 +365,23 @@ const tchar* GetProcessorVendorId()
|
||||
#endif
|
||||
}
|
||||
|
||||
// Return the build's architecture
|
||||
const tchar* GetProcessorArchName()
|
||||
{
|
||||
#if defined( __x86_64__) || defined(_M_X64)
|
||||
return "amd64";
|
||||
#elif defined(__i386__) || defined(_X86_) || defined(_M_IX86)
|
||||
return "i386";
|
||||
#elif defined __aarch64__
|
||||
return "aarch64";
|
||||
#elif defined __arm__ || defined _M_ARM
|
||||
return "arm";
|
||||
#else
|
||||
#error "Unknown architecture"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Returns non-zero if Hyper-Threading Technology is supported on the processors and zero if not. This does not mean that
|
||||
// Hyper-Threading Technology is necessarily enabled.
|
||||
static bool HTSupported(void)
|
||||
|
||||
@@ -50,6 +50,10 @@
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
extern const tchar* GetProcessorArchName();
|
||||
|
||||
#define MAX_MSGS 4196
|
||||
|
||||
class CDbgLogger : public IDbgLogger
|
||||
{
|
||||
public:
|
||||
@@ -58,18 +62,35 @@ public:
|
||||
|
||||
void Init(const char *logfile);
|
||||
void Write(const char *data);
|
||||
void Disable();
|
||||
|
||||
private:
|
||||
FILE *file;
|
||||
float flStartTime;
|
||||
bool bShouldLog;
|
||||
|
||||
char *pMsgs[MAX_MSGS];
|
||||
size_t iMsg;
|
||||
};
|
||||
|
||||
|
||||
CDbgLogger::CDbgLogger()
|
||||
{
|
||||
bShouldLog = false;
|
||||
bShouldLog = true;
|
||||
flStartTime = Plat_FloatTime();
|
||||
file = NULL;
|
||||
iMsg = 0;
|
||||
}
|
||||
|
||||
void CDbgLogger::Disable()
|
||||
{
|
||||
bShouldLog = false;
|
||||
|
||||
while( iMsg > 0 )
|
||||
{
|
||||
delete[] pMsgs[iMsg];
|
||||
iMsg--;
|
||||
}
|
||||
}
|
||||
|
||||
void CDbgLogger::Init(const char *logfile)
|
||||
@@ -86,13 +107,33 @@ void CDbgLogger::Init(const char *logfile)
|
||||
Plat_ctime( &timeCur, szTime, sizeof(szTime) );
|
||||
|
||||
file = fopen(logfile, "w+");
|
||||
fprintf(file, ">>> Engine started at %s\n", szTime);
|
||||
fflush(file);
|
||||
if( file )
|
||||
{
|
||||
#ifdef GIT_COMMIT_HASH
|
||||
fprintf(file, ">>> Engine(arch:%s commit:" GIT_COMMIT_HASH ") started at %s\n", GetProcessorArchName(), szTime);
|
||||
#else
|
||||
fprintf(file, ">>> Engine(arch:%s) started at %s\n", GetProcessorArchName(), szTime);
|
||||
#endif
|
||||
fflush(file);
|
||||
|
||||
for( int i = 0; i < iMsg; i++ )
|
||||
{
|
||||
Write(pMsgs[i]);
|
||||
delete[] pMsgs[i];
|
||||
}
|
||||
iMsg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CDbgLogger::~CDbgLogger()
|
||||
{
|
||||
if( !bShouldLog )
|
||||
while( iMsg > 0 )
|
||||
{
|
||||
delete[] pMsgs[iMsg];
|
||||
iMsg--;
|
||||
}
|
||||
|
||||
if( !file )
|
||||
return;
|
||||
|
||||
time_t timeCur;
|
||||
@@ -113,9 +154,21 @@ void CDbgLogger::Write(const char *data)
|
||||
if( !bShouldLog )
|
||||
return;
|
||||
|
||||
fprintf(file, "[%.4f] ", Plat_FloatTime() - flStartTime);
|
||||
fprintf(file, "%s", data);
|
||||
fflush(file);
|
||||
size_t len = strlen(data);
|
||||
|
||||
if( file )
|
||||
{
|
||||
fprintf(file, "[%.4f] ", Plat_FloatTime() - flStartTime);
|
||||
fprintf(file, "%s", data);
|
||||
fflush(file);
|
||||
}
|
||||
else if( iMsg < MAX_MSGS )
|
||||
{
|
||||
pMsgs[iMsg] = new char[len+8];
|
||||
memcpy(pMsgs[iMsg], data, len);
|
||||
pMsgs[iMsg][len] = 0;
|
||||
iMsg++;
|
||||
}
|
||||
}
|
||||
|
||||
static CDbgLogger g_DbgLogger;
|
||||
|
||||
Reference in New Issue
Block a user