diff --git a/core/AMBuilder b/core/AMBuilder index fb5e768df..e312017f9 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -40,7 +40,6 @@ for i in SM.sdkInfo: 'concmd_cleaner.cpp', 'HalfLife2.cpp', 'NextMap.cpp', - 'smn_profiler.cpp', 'ConCmdManager.cpp', 'HandleSys.cpp', 'ConVarManager.cpp', diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index c51de0478..8e4198df2 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -44,7 +44,8 @@ files = [ 'smn_datapacks.cpp', 'smn_gameconfigs.cpp', 'GameConfigs.cpp', - 'sm_crc32.cpp' + 'sm_crc32.cpp', + 'smn_profiler.cpp' ] if AMBuild.target['platform'] == 'windows': files.append('thread/WinThreads.cpp') diff --git a/core/smn_profiler.cpp b/core/logic/smn_profiler.cpp similarity index 78% rename from core/smn_profiler.cpp rename to core/logic/smn_profiler.cpp index e3418857d..0d7681582 100644 --- a/core/smn_profiler.cpp +++ b/core/logic/smn_profiler.cpp @@ -29,12 +29,13 @@ * Version: $Id$ */ -#include "sm_globals.h" -#include "HandleSys.h" - -//Note: Do not add this to Linux yet, i haven't done the HPET timing research (if even available) -//nonetheless we need accurate counting -#if !defined PLATFORM_LINUX && !defined PLATFORM_APPLE +#include "common_logic.h" +#include +#if !defined PLATFORM_WINDOWS +#include +#include +#include +#endif struct Profiler { @@ -47,6 +48,9 @@ struct Profiler LARGE_INTEGER start; LARGE_INTEGER end; double freq; +#else + struct timeval start; + struct timeval end; #endif bool started; bool stopped; @@ -61,11 +65,11 @@ class ProfilerHelpers : public: void OnSourceModAllInitialized() { - g_ProfilerType = g_HandleSys.CreateType("Profiler", this, 0, NULL, NULL, g_pCoreIdent, NULL); + g_ProfilerType = handlesys->CreateType("Profiler", this, 0, NULL, NULL, g_pCoreIdent, NULL); } void OnSourceModShutdown() { - g_HandleSys.RemoveType(g_ProfilerType, g_pCoreIdent); + handlesys->RemoveType(g_ProfilerType, g_pCoreIdent); } void OnHandleDestroy(HandleType_t type, void *object) { @@ -84,7 +88,7 @@ static cell_t CreateProfiler(IPluginContext *pContext, const cell_t *params) p->freq = 1.0 / (double)(qpf.QuadPart); #endif - Handle_t hndl = g_HandleSys.CreateHandle(g_ProfilerType, p, pContext->GetIdentity(), g_pCoreIdent, NULL); + Handle_t hndl = handlesys->CreateHandle(g_ProfilerType, p, pContext->GetIdentity(), g_pCoreIdent, NULL); if (hndl == BAD_HANDLE) { delete p; @@ -100,7 +104,7 @@ static cell_t StartProfiling(IPluginContext *pContext, const cell_t *params) HandleError err; Profiler *prof; - if ((err = g_HandleSys.ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) + if ((err = handlesys->ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); @@ -108,6 +112,8 @@ static cell_t StartProfiling(IPluginContext *pContext, const cell_t *params) #if defined PLATFORM_WINDOWS QueryPerformanceCounter(&prof->start); +#else + gettimeofday(&prof->start, NULL); #endif prof->started = true; @@ -123,7 +129,7 @@ static cell_t StopProfiling(IPluginContext *pContext, const cell_t *params) HandleError err; Profiler *prof; - if ((err = g_HandleSys.ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) + if ((err = handlesys->ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); @@ -136,6 +142,8 @@ static cell_t StopProfiling(IPluginContext *pContext, const cell_t *params) #if defined PLATFORM_WINDOWS QueryPerformanceCounter(&prof->end); +#else + gettimeofday(&prof->end, NULL); #endif prof->started = false; @@ -151,7 +159,7 @@ static cell_t GetProfilerTime(IPluginContext *pContext, const cell_t *params) HandleError err; Profiler *prof; - if ((err = g_HandleSys.ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) + if ((err = handlesys->ReadHandle(hndl, g_ProfilerType, &sec, (void **)&prof)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err); @@ -168,6 +176,10 @@ static cell_t GetProfilerTime(IPluginContext *pContext, const cell_t *params) LONGLONG diff = prof->end.QuadPart - prof->start.QuadPart; double seconds = diff * prof->freq; fTime = (float)seconds; +#else + int64_t start_us = int64_t(prof->start.tv_sec) * 1000000 + prof->start.tv_usec; + int64_t stop_us = int64_t(prof->end.tv_sec) * 1000000 + prof->end.tv_usec; + fTime = double((stop_us - start_us) / 1000) / 1000.0; #endif return sp_ftoc(fTime); @@ -181,5 +193,4 @@ REGISTER_NATIVES(profilerNatives) {"StopProfiling", StopProfiling}, {NULL, NULL}, }; -#endif