From 3e19d26a720ea3faf1440cec762c827857732fb7 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 5 Sep 2022 12:54:41 +0300 Subject: [PATCH] add additional logging information --- appframework/sdlmgr.cpp | 2 - launcher/android/main.cpp | 44 ++++++++++++++++++-- launcher/launcher.cpp | 2 + public/tier0/dbg.h | 1 + tier0/cpu.cpp | 17 ++++++++ tier0/dbg.cpp | 67 +++++++++++++++++++++++++++---- togles/linuxwin/glentrypoints.cpp | 21 +++++++--- wscript | 2 + 8 files changed, 139 insertions(+), 17 deletions(-) diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index a2e82346..5c820f6f 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -206,8 +206,6 @@ void *VoidFnPtrLookup_GlMgr(const char *fn, bool &okay, const bool bRequired, vo { retval = _glGetProcAddress(fn); - Msg("_glGetProcAddress(%s) = %x\n", fn, retval); - if( !retval && l_gles ) retval = dlsym( l_gles, fn ); } diff --git a/launcher/android/main.cpp b/launcher/android/main.cpp index a299da1b..7d6e8abe 100644 --- a/launcher/android/main.cpp +++ b/launcher/android/main.cpp @@ -23,6 +23,7 @@ GNU General Public License for more details. #include #include "tier0/dbg.h" #include "tier0/threadtools.h" +#include char *LauncherArgv[512]; char java_args[4096]; @@ -33,13 +34,13 @@ extern void InitCrashHandler(); DLL_EXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over) { - Msg( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) ); + Msg( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s\n", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) ); return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over ); } DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult() { - Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" ); +// Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult\n" ); } DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str) @@ -55,7 +56,6 @@ void SetLauncherArgs() static char binPath[2048]; snprintf(binPath, sizeof binPath, "%s/hl2_linux", getenv("APP_DATA_PATH") ); - Msg(binPath); D(binPath); D("-nouserclip"); @@ -77,12 +77,50 @@ void SetLauncherArgs() #undef D } +float GetTotalMemory() +{ + int64_t mem = 0; + + char meminfo[8196] = { 0 }; + FILE *f = fopen("/proc/meminfo", "r"); + if( !f ) + return 0.f; + + size_t size = fread(meminfo, 1, sizeof(meminfo), f); + if( !size ) + return 0.f; + + char *s = strstr(meminfo, "MemTotal:"); + + if( !s ) return 0.f; + + sscanf(s+9, "%lld", &mem); + fclose(f); + + return mem/1024/1024.f; +} + +void android_property_print(const char *name) +{ + char value[1024]; + + if( __system_property_get( name, value ) != 0 ) + Msg("prop %s=%s\n", name, value); +} + + DLL_EXPORT int LauncherMainAndroid( int argc, char **argv ) { SDL_version ver; SDL_GetVersion( &ver ); Msg("SDL version: %d.%d.%d rev: %s\n", (int)ver.major, (int)ver.minor, (int)ver.patch, SDL_GetRevision()); + Msg("GetTotalMemory() = %.2f GiB\n", GetTotalMemory()); + android_property_print("ro.build.version.sdk"); + android_property_print("ro.product.system.device"); + android_property_print("ro.product.system.manufacturer"); + android_property_print("ro.product.system.model"); + android_property_print("ro.product.system.name"); InitCrashHandler(); SetLauncherArgs(); diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index c03c4cf8..47e69f93 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -767,6 +767,8 @@ bool CSourceAppSystemGroup::PreInit() { if ( !CommandLine()->FindParm( "-nolog" ) ) DebugLogger()->Init("engine.log"); + else + DebugLogger()->Disable(); CreateInterfaceFn factory = GetFactory(); ConnectTier1Libraries( &factory, 1 ); diff --git a/public/tier0/dbg.h b/public/tier0/dbg.h index 80587c04..24e64b01 100644 --- a/public/tier0/dbg.h +++ b/public/tier0/dbg.h @@ -53,6 +53,7 @@ class IDbgLogger public: virtual void Init(const char *logfile) = 0; virtual void Write(const char *data) = 0; + virtual void Disable() = 0; }; PLATFORM_INTERFACE IDbgLogger *DebugLogger(); diff --git a/tier0/cpu.cpp b/tier0/cpu.cpp index 2018c8b0..a602347c 100644 --- a/tier0/cpu.cpp +++ b/tier0/cpu.cpp @@ -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) diff --git a/tier0/dbg.cpp b/tier0/dbg.cpp index 83205eef..8ea5b36f 100644 --- a/tier0/dbg.cpp +++ b/tier0/dbg.cpp @@ -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; diff --git a/togles/linuxwin/glentrypoints.cpp b/togles/linuxwin/glentrypoints.cpp index f341fd1d..ccf920a6 100644 --- a/togles/linuxwin/glentrypoints.cpp +++ b/togles/linuxwin/glentrypoints.cpp @@ -212,7 +212,16 @@ static void GetOpenGLVersion(int *major, int *minor, int *patch) const char *version = (const char *) glGetString(GL_VERSION); if (version) { - sscanf( version, "%d.%d.%d", major, minor, patch ); + const char *s = version; + while( *s ) + { + if( *s >= '0' && *s <= '9' ) + { + sscanf( s, "%d.%d", major, minor ); + break; + } + s++; + } } } } @@ -240,8 +249,8 @@ static int GetOpenGLVersionPatch() static bool CheckBaseOpenGLVersion() { - const int NEED_MAJOR = 2; - const int NEED_MINOR = 0; + const int NEED_MAJOR = 3; + const int NEED_MINOR = 2; const int NEED_PATCH = 0; int major, minor, patch; @@ -251,7 +260,7 @@ static bool CheckBaseOpenGLVersion() const int have = GLVERNUM(major, minor, patch); if (have < need) { - fprintf(stderr, "PROBLEM: You appear to have OpenGL %d.%d.%d, but we need at least %d.%d.%d!\n", + Warning("PROBLEM: You appear to have OpenGL %d.%d.%d, but we need at least %d.%d.%d!\n", major, minor, patch, NEED_MAJOR, NEED_MINOR, NEED_PATCH); return false; } @@ -381,9 +390,11 @@ COpenGLEntryPoints::COpenGLEntryPoints() pszString = ( const char * )glGetString(GL_EXTENSIONS); m_pGLDriverStrings[cGLExtensionsString] = strdup( pszString ? pszString : "" ); - printf( "OpenGL: %s %s (%d.%d.%d)\n", m_pGLDriverStrings[ cGLRendererString ], m_pGLDriverStrings[ cGLVersionString ], + Msg( "GL_RENDERER=\"%s\" GL_VERSION=\"%s\" GL_VENDOR=\"%s\" (%d.%d.%d)\n", m_pGLDriverStrings[ cGLRendererString ], m_pGLDriverStrings[ cGLVersionString ], m_pGLDriverStrings[ cGLVendorString ], m_nOpenGLVersionMajor, m_nOpenGLVersionMinor, m_nOpenGLVersionPatch ); + Msg("GL_EXTENSIONS=\"%s\"\n", m_pGLDriverStrings[cGLExtensionsString]); + // !!! FIXME: Alfred says the original GL_APPLE_fence code only exists to // !!! FIXME: hint Apple's drivers and not because we rely on the // !!! FIXME: functionality. If so, just remove this check (and the diff --git a/wscript b/wscript index f6d5d114..617af682 100644 --- a/wscript +++ b/wscript @@ -282,7 +282,9 @@ def configure(conf): conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test enforce_pic') if conf.env.DEST_OS == 'win32' and conf.env.DEST_CPU == 'amd64': conf.load('masm') + define_platform(conf) + conf.define('GIT_COMMIT_HASH', conf.env.GIT_VERSION) if conf.env.TOGLES: projects['game'] += ['togles']