added GetSysTickCount for benchmarking

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40892
This commit is contained in:
David Anderson 2007-06-06 16:40:30 +00:00
parent 13493fd7d5
commit 1b6b0f6c5e
2 changed files with 38 additions and 2 deletions

View File

@ -18,8 +18,15 @@
#include "PluginSys.h"
#include "HandleSys.h"
HandleType_t g_PlIter;
#if defined PLATFORM_WINDOWS
#include <windows.h>
#elif defined PLATFORM_LINUX
#include <limits.h>
#include <unistd.h>
#include <sys/times.h>
#endif
HandleType_t g_PlIter;
class CoreNativeHelpers :
public SMGlobalClass,
@ -257,12 +264,32 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
}
static cell_t GetSysTickCount(IPluginContext *pContext, const cell_t *params)
{
#if defined PLATFORM_WINDOWS
return (cell_t)GetTickCount();
#elif defined PLATFORM_LINUX
tms tm;
clock_t ticks = times(&tm);
long ticks_per_sec = sysconf(_SC_CLK_TCK);
double ftcks = (double)ticks / (double)ticks_per_sec;
fticks *= 1000.0f;
if (fticks > INT_MAX)
{
double r = (int)(fticks / INT_MAX) * (double)INT_MAX;
fticks -= r;
}
return (cell_t)fticks;
#endif
}
REGISTER_NATIVES(coreNatives)
{
{"GetPluginFilename", GetPluginFilename},
{"GetPluginInfo", GetPluginInfo},
{"GetPluginIterator", GetPluginIterator},
{"GetPluginStatus", GetPluginStatus},
{"GetSysTickCount", GetSysTickCount},
{"GetTime", GetTime},
{"IsPluginDebugging", IsPluginDebugging},
{"MorePlugins", MorePlugins},

View File

@ -281,9 +281,18 @@ native GameConfGetOffset(Handle:gc, const String:key[]);
* @param key Key to retrieve from the Keys section.
* @param buffer Destination string buffer.
* @param maxlen Maximum length of output string buffer.
* @return True if key existed, false otherwise.
* @return True if key existed, false otherwise.
*/
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
/**
* Returns the operating system's "tick count," which is a number of
* milliseconds since the operating system loaded. This can be used
* for basic benchmarks.
*
* @return Tick count in milliseconds.
*/
native GetSysTickCount();
#include <helpers>
#include <entity>