Move profile natives to logic, add linux support (bug 4927, r=ds).
This commit is contained in:
parent
024d094459
commit
5b45e29533
@ -40,7 +40,6 @@ for i in SM.sdkInfo:
|
|||||||
'concmd_cleaner.cpp',
|
'concmd_cleaner.cpp',
|
||||||
'HalfLife2.cpp',
|
'HalfLife2.cpp',
|
||||||
'NextMap.cpp',
|
'NextMap.cpp',
|
||||||
'smn_profiler.cpp',
|
|
||||||
'ConCmdManager.cpp',
|
'ConCmdManager.cpp',
|
||||||
'HandleSys.cpp',
|
'HandleSys.cpp',
|
||||||
'ConVarManager.cpp',
|
'ConVarManager.cpp',
|
||||||
|
@ -44,7 +44,8 @@ files = [
|
|||||||
'smn_datapacks.cpp',
|
'smn_datapacks.cpp',
|
||||||
'smn_gameconfigs.cpp',
|
'smn_gameconfigs.cpp',
|
||||||
'GameConfigs.cpp',
|
'GameConfigs.cpp',
|
||||||
'sm_crc32.cpp'
|
'sm_crc32.cpp',
|
||||||
|
'smn_profiler.cpp'
|
||||||
]
|
]
|
||||||
if AMBuild.target['platform'] == 'windows':
|
if AMBuild.target['platform'] == 'windows':
|
||||||
files.append('thread/WinThreads.cpp')
|
files.append('thread/WinThreads.cpp')
|
||||||
|
@ -29,12 +29,13 @@
|
|||||||
* Version: $Id$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sm_globals.h"
|
#include "common_logic.h"
|
||||||
#include "HandleSys.h"
|
#include <IHandleSys.h>
|
||||||
|
#if !defined PLATFORM_WINDOWS
|
||||||
//Note: Do not add this to Linux yet, i haven't done the HPET timing research (if even available)
|
#include <stddef.h>
|
||||||
//nonetheless we need accurate counting
|
#include <stdint.h>
|
||||||
#if !defined PLATFORM_LINUX && !defined PLATFORM_APPLE
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct Profiler
|
struct Profiler
|
||||||
{
|
{
|
||||||
@ -47,6 +48,9 @@ struct Profiler
|
|||||||
LARGE_INTEGER start;
|
LARGE_INTEGER start;
|
||||||
LARGE_INTEGER end;
|
LARGE_INTEGER end;
|
||||||
double freq;
|
double freq;
|
||||||
|
#else
|
||||||
|
struct timeval start;
|
||||||
|
struct timeval end;
|
||||||
#endif
|
#endif
|
||||||
bool started;
|
bool started;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
@ -61,11 +65,11 @@ class ProfilerHelpers :
|
|||||||
public:
|
public:
|
||||||
void OnSourceModAllInitialized()
|
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()
|
void OnSourceModShutdown()
|
||||||
{
|
{
|
||||||
g_HandleSys.RemoveType(g_ProfilerType, g_pCoreIdent);
|
handlesys->RemoveType(g_ProfilerType, g_pCoreIdent);
|
||||||
}
|
}
|
||||||
void OnHandleDestroy(HandleType_t type, void *object)
|
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);
|
p->freq = 1.0 / (double)(qpf.QuadPart);
|
||||||
#endif
|
#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)
|
if (hndl == BAD_HANDLE)
|
||||||
{
|
{
|
||||||
delete p;
|
delete p;
|
||||||
@ -100,7 +104,7 @@ static cell_t StartProfiling(IPluginContext *pContext, const cell_t *params)
|
|||||||
HandleError err;
|
HandleError err;
|
||||||
Profiler *prof;
|
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)
|
!= HandleError_None)
|
||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);
|
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
|
#if defined PLATFORM_WINDOWS
|
||||||
QueryPerformanceCounter(&prof->start);
|
QueryPerformanceCounter(&prof->start);
|
||||||
|
#else
|
||||||
|
gettimeofday(&prof->start, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
prof->started = true;
|
prof->started = true;
|
||||||
@ -123,7 +129,7 @@ static cell_t StopProfiling(IPluginContext *pContext, const cell_t *params)
|
|||||||
HandleError err;
|
HandleError err;
|
||||||
Profiler *prof;
|
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)
|
!= HandleError_None)
|
||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);
|
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
|
#if defined PLATFORM_WINDOWS
|
||||||
QueryPerformanceCounter(&prof->end);
|
QueryPerformanceCounter(&prof->end);
|
||||||
|
#else
|
||||||
|
gettimeofday(&prof->end, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
prof->started = false;
|
prof->started = false;
|
||||||
@ -151,7 +159,7 @@ static cell_t GetProfilerTime(IPluginContext *pContext, const cell_t *params)
|
|||||||
HandleError err;
|
HandleError err;
|
||||||
Profiler *prof;
|
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)
|
!= HandleError_None)
|
||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);
|
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;
|
LONGLONG diff = prof->end.QuadPart - prof->start.QuadPart;
|
||||||
double seconds = diff * prof->freq;
|
double seconds = diff * prof->freq;
|
||||||
fTime = (float)seconds;
|
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
|
#endif
|
||||||
|
|
||||||
return sp_ftoc(fTime);
|
return sp_ftoc(fTime);
|
||||||
@ -181,5 +193,4 @@ REGISTER_NATIVES(profilerNatives)
|
|||||||
{"StopProfiling", StopProfiling},
|
{"StopProfiling", StopProfiling},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user