Re #145 (trace/log system) Added a heading time indication for each trace line, as the elapsed time since SD is started, with 1 ms resolution.

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2824 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 1ff4f20969d6017832eb9e1212109ec5499b36f6
Former-commit-id: c60f560bfcade0ed835fe41e00fc09eacc4a24f5
This commit is contained in:
pouillot 2010-09-30 18:23:49 +00:00
parent 7aab2d38e5
commit d7ab4a2536
10 changed files with 185 additions and 122 deletions

View file

@ -98,7 +98,7 @@ ReInit(void)
if (!strcmp(GfParmGetStr(ReInfo->_reParam, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_ENABLE, "no"), "no")){
capture->enabled = 0;
capture->outputBase = 0;
GfLogInfo("Movie capture disabled");
GfLogInfo("Movie capture disabled\n");
} else {
capture->enabled = 1;
capture->state = 0;
@ -111,7 +111,7 @@ ReInit(void)
capture->outputBase = strdup(pszDefOutputBase);
GfDirCreate(pszDefOutputBase); // In case not already done.
GfLogInfo("Movie capture enabled (%.0f FPS, PNG frames in %s)\n",
1.0 / capture->deltaFrame, capture->outputBase);
1.0 / capture->deltaFrame, capture->outputBase);
}
ReInfo->_reGameScreen = ReHookInit();

View file

@ -446,14 +446,14 @@ ReUpdateQualifCurRes(tCarElt *car)
sprintf(path, "%s/%s/%s/%s/%d", ReInfo->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, i);
if (!printed) {
if ((car->_bestLapTime != 0.0) && (car->_bestLapTime < GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0))) {
tmp_str = GfTime2Str(car->_bestLapTime, 0);
tmp_str = GfTime2Str(car->_bestLapTime, " ", false, 2);
sprintf(buf, "%d - %s - %s (%s)", i, tmp_str, car->_name, carName);
free(tmp_str);
ReResScreenSetText(buf, i - 1, 1);
printed = 1;
}
}
tmp_str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0);
tmp_str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), " ", false, 2);
sprintf(buf, "%d - %s - %s (%s)", i + printed, tmp_str, GfParmGetStr(results, path, RE_ATTR_NAME, ""),
GfParmGetStr(results, path, RE_ATTR_CAR, ""));
free (tmp_str);
@ -461,7 +461,7 @@ ReUpdateQualifCurRes(tCarElt *car)
}
if (!printed) {
tmp_str = GfTime2Str(car->_bestLapTime, 0);
tmp_str = GfTime2Str(car->_bestLapTime, " ", false, 2);
sprintf(buf, "%d - %s - %s (%s)", i, tmp_str, car->_name, carName);
free(tmp_str);
ReResScreenSetText(buf, i - 1, 1);
@ -500,11 +500,11 @@ ReUpdateQualifCurRes(tCarElt *car)
sprintf(buf, "%d - --:-- - %s (%s)", xx + 1, car->_name, carName);
} else {
if (xx == 0) {
tmp_str = GfTime2Str(car->_bestLapTime, FALSE);
tmp_str = GfTime2Str(car->_bestLapTime, " ", false, 2);
sprintf(buf, "%d - %s - %s (%s)", xx + 1, tmp_str, car->_name, carName);
free(tmp_str);
} else {
tmp_str = GfTime2Str(car->_bestLapTime - ReInfo->s->cars[0]->_bestLapTime, TRUE);
tmp_str = GfTime2Str(car->_bestLapTime - ReInfo->s->cars[0]->_bestLapTime, "+", false, 2);
sprintf(buf, "%d - %s - %s (%s)", xx + 1, tmp_str, car->_name, carName);
free(tmp_str);
}
@ -561,7 +561,7 @@ ReUpdateRaceCurRes()
} else {
if (car->_lapsBehindLeader == 0)
{
tmp_str = GfTime2Str(car->_timeBehindLeader, 0);
tmp_str = GfTime2Str(car->_timeBehindLeader, " ", false, 2);
sprintf(buf, "%d - %s - %s (%s)", xx + 1, tmp_str, car->_name, carName);
free(tmp_str);
}

View file

@ -128,12 +128,12 @@ rmPracticeResults(void *prevHdle, tRmInfo *info, int start)
GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, xLap, y, GFUI_ALIGN_HC_VB, 0);
/* Time */
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0), 0);;
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0), " ", false, 2);;
GfuiLabelCreate(rmScrHdle, str, GFUI_FONT_MEDIUM_C, xTime, y, GFUI_ALIGN_HL_VB, 0);
free(str);
/* Best Lap Time */
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0);;
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), " ", false, 2);;
GfuiLabelCreate(rmScrHdle, str, GFUI_FONT_MEDIUM_C, xBest, y, GFUI_ALIGN_HL_VB, 0);
free(str);
@ -290,7 +290,7 @@ rmRaceResults(void *prevHdle, tRmInfo *info, int start)
xCar, y, GFUI_ALIGN_HL_VB, 0);
//Best lap
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0);
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), " ", false, 2);
GfuiLabelCreate(rmScrHdle, str, GFUI_FONT_MEDIUM_C, xBest, y, GFUI_ALIGN_HR_VB, 0);
free(str);
@ -420,7 +420,7 @@ rmQualifResults(void *prevHdle, tRmInfo *info, int start)
GfuiLabelCreate(rmScrHdle, GfParmGetStr(results, path, RE_ATTR_CAR, NULL), GFUI_FONT_MEDIUM_C,
xCar, y, GFUI_ALIGN_HL_VB, 0);
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0);
str = GfTime2Str(GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), " ", false, 2);
GfuiLabelCreate(rmScrHdle, str, GFUI_FONT_MEDIUM_C,
xTime, y, GFUI_ALIGN_HR_VB, 0);
free(str);

View file

@ -459,66 +459,50 @@ tdble gfMean(tdble v, tMeanVal *pvt, int n, int w)
}
static char bufstr[1024];
char * GfGetTimeStr(void)
{
struct tm *stm;
time_t t;
t = time(NULL);
stm = localtime(&t);
sprintf(bufstr, "%4d%02d%02d%02d%02d%02d",
stm->tm_year+1900,
stm->tm_mon+1,
stm->tm_mday,
stm->tm_hour,
stm->tm_min,
stm->tm_sec);
return bufstr;
}
/** Convert a time in seconds (float) to an ascii string.
@ingroup screen
@param sec Time to convert
@param sgn Flag to indicate if the sign (+) is to be displayed for positive values of time.
@param plus String to display as the positive sign (+) for positive values of time.
@param zeros Flag to indicate if heading zeros are to be displayed or not.
@param prec Numer of figures to display after the decimal point (< 2 forced to 1).
@return Time string.
@warning The returned string has to be freed by the caller.
*/
char* GfTime2Str(tdble sec, int sgn)
char* GfTime2Str(double sec, const char* plus, bool zeros, int prec)
{
char buf[256];
const char* sign = (sec < 0.0 ? "-" : (sgn ? "+" : " ") );
if (sec < 0.0) {
char* buf = (char*)malloc(256*sizeof(char));
const char* sign = (sec < 0.0) ? "-" : (plus ? plus : "");
if (sec < 0.0)
sec = -sec;
sign = "-";
} else {
if (sgn) {
sign = "+";
} else {
sign = " ";
}
}
int h = (int)(sec / 3600.0);
// Hours.
const int h = (int)(sec / 3600.0);
sec -= 3600 * h;
int m = (int)(sec / 60.0);
sec -= 60 * m;
int s = (int)(sec);
sec -= s;
int c = (int)floor((sec) * 100.0);
if (h) {
(void)sprintf(buf, "%s%2.2d:%2.2d:%2.2d.%2.2d", sign,h,m,s,c);
// Minutes.
const int m = (int)(sec / 60.0);
sec -= 60 * m;
// Seconds.
const int s = (int)sec;
sec -= s;
// Fractions of the second (limited resolution).
int mult = 10;
int digits = prec;
while (digits-- > 1)
mult *= 10;
const int f = (int)floor(sec * mult);
if (h || zeros) {
(void)sprintf(buf, "%s%2.2d:%2.2d:%2.2d.%0.*d", sign, h, m, s, prec, f);
} else if (m) {
(void)sprintf(buf, " %s%2.2d:%2.2d.%2.2d", sign,m,s,c);
(void)sprintf(buf, " %s%2.2d:%2.2d.%0.*d", sign, m, s, prec, f);
} else {
(void)sprintf(buf, " %s%2.2d.%2.2d", sign,s,c);
(void)sprintf(buf, " %s%2.2d.%0.*d", sign, s, prec, f);
}
return strdup(buf);
return buf;
}
// Determine if a dir or file path is absolute or not.

View file

@ -260,7 +260,7 @@ TGF_API void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserData, bool fr
* Directory and file path management *
**************************************/
TGF_API bool GfPathIsAbsolute(const char *path);
TGF_API bool GfPathIsAbsolute(const char *pszPath);
TGF_API char* GfPathNormalizeDir(char* pszPath, size_t nMaxPathLen);
/**********************************
@ -367,6 +367,8 @@ TGF_API tdble GfParmGetVariable(void *handle, char const *path, char const *key)
/********************************************************************************
* Log/Trace Interface *
* - Write formated string messages at run-time to the log stream, *
* with automatic prepending of current time and trace level *
* (Ex: 12:27.35.267 Debug My formated message) *
* - Messages are given an integer "level" = "criticity", *
* (0=Fatal, 1=Error, 2=Warning, 3=Info, 4=Trace, 5=Debug, ...) *
* - Messages are actually logged into the stream only if their level *
@ -416,8 +418,7 @@ static inline void GfLogMessage(int nLevel, const char *pszFmt, ...) {};
* Time Interface *
*******************/
TGF_API double GfTimeClock(void);
TGF_API char *GfGetTimeStr(void);
TGF_API char *GfTime2Str(tdble sec, int sgn);
TGF_API char *GfTime2Str(double sec, const char* plus="", bool zeros=true, int prec=3);
/* Mean values */
#define GF_MEAN_MAX_VAL 5

View file

@ -86,17 +86,19 @@ void GfLogSetStream(FILE* fStream)
// Trace date and time.
time_t t = time(NULL);
struct tm *stm = localtime(&t);
fprintf(gfLogStream, "Info\t%4d/%02d/%02d %02d:%02d:%02d\n",
stm->tm_year+1900, stm->tm_mon+1, stm->tm_mday,
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Info %4d/%02d/%02d %02d:%02d:%02d\n",
pszClock, stm->tm_year+1900, stm->tm_mon+1, stm->tm_mday,
stm->tm_hour, stm->tm_min, stm->tm_sec);
// Trace current trace level threshold.
fprintf(gfLogStream, "Info\tCurrent trace level threshold : ");
fprintf(gfLogStream, "%s Info\tCurrent trace level threshold : ", pszClock);
if (gfLogLevelThreshold >= gfLogFatal && gfLogLevelThreshold <= gfLogDebug)
fprintf(gfLogStream, "%s\n", gfLogLevelNames[gfLogLevelThreshold]);
else
fprintf(gfLogStream, "%d\n", gfLogLevelThreshold);
fprintf(gfLogStream, "Level%d\n", gfLogLevelThreshold);
fflush(gfLogStream);
free(pszClock);
}
}
@ -107,7 +109,9 @@ void GfLogSetLevelThreshold(int nLevel)
// Trace new trace level threshold.
if (gfLogStream)
{
fprintf(gfLogStream, "Info\tNew trace level threshold : ");
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Info New trace level threshold : ", pszClock);
free(pszClock);
if (gfLogLevelThreshold >= gfLogFatal && gfLogLevelThreshold <= gfLogDebug)
fprintf(gfLogStream, "%s\n", gfLogLevelNames[gfLogLevelThreshold]);
else
@ -124,7 +128,11 @@ void GfLogFatal(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogFatal)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Fatal\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Fatal ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -146,7 +154,11 @@ TGF_API void GfLogError(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogError)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Error\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Error ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -161,7 +173,11 @@ TGF_API void GfLogWarning(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogWarning)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Warning\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Warning ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -176,7 +192,11 @@ TGF_API void GfLogInfo(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogInfo)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Info\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Info ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -191,7 +211,11 @@ TGF_API void GfLogTrace(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogTrace)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Trace\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Trace ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -206,7 +230,11 @@ TGF_API void GfLogDebug(const char *pszFmt, ...)
if (gfLogLevelThreshold >= gfLogDebug)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Debug\t");
{
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
fprintf(gfLogStream, "%s Debug ", pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);
vfprintf(gfLogStream, pszFmt, vaArgs);
@ -220,15 +248,14 @@ TGF_API void GfLogMessage(int nLevel, const char *pszFmt, ...)
{
if (gfLogLevelThreshold >= nLevel)
{
if (nLevel >= gfLogFatal && nLevel <= gfLogDebug)
if (gfLogNeedLineHeader)
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "%s\t", gfLogLevelNames[nLevel]);
}
else
{
if (gfLogNeedLineHeader)
fprintf(gfLogStream, "Level%d\t", nLevel);
char* pszClock = GfTime2Str(GfTimeClock(), 0, true, 3);
if (nLevel >= gfLogFatal && nLevel <= gfLogDebug)
fprintf(gfLogStream, "%s %.7s ", gfLogLevelNames[nLevel], pszClock);
else
fprintf(gfLogStream, "%s Level%d ", nLevel, pszClock);
free(pszClock);
}
va_list vaArgs;
va_start(vaArgs, pszFmt);

View file

@ -568,6 +568,23 @@ linuxDirGetListFiltered(const char *dir, const char *prefix, const char *suffix)
return flist;
}
// Initial "time" (actually the number of seconds since the system has been up).
static double InitTime = -1.0;
/*
* Function
* linuxTimeClock
*
* Description
* Return the number of seconds since the game is running (resolution 1 micro-second).
*
* Parameters
* None
*
* Return
* The number of seconds since the game is running
*
*/
static double
linuxTimeClock(void)
{
@ -575,7 +592,10 @@ linuxTimeClock(void)
gettimeofday(&tv, 0);
return (double)(tv.tv_sec + tv.tv_usec * 1e-6);
if (InitTime < 0)
InitTime = (double)(tv.tv_sec + tv.tv_usec * 1e-6);
return (double)(tv.tv_sec + tv.tv_usec * 1e-6) - InitTime;
}

View file

@ -151,10 +151,10 @@ main(int argc, char *argv[])
init_args(argc, argv);
GfFileSetup(); /* Update user settings files from an old version */
LinuxSpecInit(); /* init specific linux functions */
GfFileSetup(); /* Update user settings files from installed ones */
GfScrInit(argc, argv); /* init screen */
if (MenuEntry()) /* launch the game */

View file

@ -149,11 +149,12 @@ main(int argc, char *argv[])
{
GfInit();
init_args(argc, argv);
init_args(argc, argv);
GfFileSetup(); /* Update user settings files from an old version */
WindowsSpecInit(); /* init specific windows functions */
GfFileSetup(); /* Update user settings files from installed ones */
GfScrInit(argc, argv); /* init screen */
if (MenuEntry()) /* launch the game */

View file

@ -62,12 +62,12 @@ windowsModLoad(unsigned int /* gfid */, const char *soPath, tModList **modlist)
/* Try and avoid loading the same module twice (WARNING: Only checks soPath equality !) */
if ((curMod = GfModIsInList(soPath, *modlist)) != 0)
{
GfOut("Module %s already loaded\n", soPath);
GfLogTrace("Module %s already loaded\n", soPath);
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
return 0;
}
GfOut("Loading module %s\n", soPath);
GfLogTrace("Loading module %s\n", soPath);
char fname[256];
const char* lastSlash = strrchr(soPath, '/');
@ -90,17 +90,17 @@ windowsModLoad(unsigned int /* gfid */, const char *soPath, tModList **modlist)
else
{
FreeLibrary(SOHandle(handle));
GfError("windowsModLoad: Module init function failed %s\n", soPath);
GfLogError("windowsModLoad: Module init function failed %s\n", soPath);
return -1;
}
}
else
{
GfError("windowsModLoad: ... can't open dll %s\n", soPath);
GfLogError("windowsModLoad: ... can't open dll %s\n", soPath);
return -1;
}
GfOut("Module %s loaded\n",soPath);
GfLogInfo("Module %s loaded\n",soPath);
return 0;
}
@ -135,12 +135,12 @@ windowsModInfo(unsigned int /* gfid */, const char *soPath, tModList **modlist)
/* Try and avoid loading the same module twice (WARNING: Only checks soPath equality !) */
if ((curMod = GfModIsInList(soPath, *modlist)) != 0)
{
GfOut("Module %s already loaded\n", soPath);
GfLogTrace("Module %s already loaded\n", soPath);
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
return infoSts;
}
GfOut("Querying module %s\n", soPath);
GfLogTrace("Querying module %s\n", soPath);
/* Load the DLL */
handle = LoadLibrary( soPath );
@ -160,7 +160,7 @@ windowsModInfo(unsigned int /* gfid */, const char *soPath, tModList **modlist)
}
else
{
GfOut("windowsModInfo: Module init function failed %s\n", soPath);
GfLogError("windowsModInfo: Module init function failed %s\n", soPath);
infoSts = -1;
}
@ -169,8 +169,8 @@ windowsModInfo(unsigned int /* gfid */, const char *soPath, tModList **modlist)
}
else
{
GfError("windowsModInfo: ... %d\n", GetLastError());
infoSts = -1;
GfLogError("windowsModInfo: ... %d\n", GetLastError());
infoSts = -1;
}
return infoSts;
@ -224,7 +224,7 @@ windowsModLoadDir(unsigned int gfid, const char *dir, tModList **modlist)
if (!GfModIsInList(soPath, *modlist))
{
/* Load the DLL */
GfOut("Loading module %s\n", soPath);
GfLogTrace("Loading module %s\n", soPath);
handle = LoadLibrary( soPath );
if (handle)
{
@ -246,7 +246,7 @@ windowsModLoadDir(unsigned int gfid, const char *dir, tModList **modlist)
}
else
{
GfError("windowsModLoadDir: ... %s\n", GetLastError());
GfLogError("windowsModLoadDir: ... %s\n", GetLastError());
modnb = -1;
break;
}
@ -299,7 +299,7 @@ windowsModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList
char Dir_name[ 1024 ];
sprintf( Dir_name, "%s\\*.*", dir );
GfOut("Listing module directory %s for info. only\n", dir);
GfLogTrace("Listing module directory %s for info. only\n", dir);
long Dirent = _findfirst( Dir_name, &FData );
if ( Dirent != -1 )
{
@ -318,7 +318,7 @@ windowsModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList
if (!GfModIsInList(soPath, *modlist))
{
/* Load the DLL */
GfOut("Querying module %s\n", soPath);
GfLogTrace("Querying module %s\n", soPath);
handle = (tSOHandle)LoadLibrary( soPath );
if (handle)
{
@ -337,7 +337,7 @@ windowsModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList
}
else
{
GfOut("windowsModInfo: Module init function failed %s\n", soPath);
GfLogError("windowsModInfo: Module init function failed %s\n", soPath);
modnb = -1;
break;
}
@ -347,7 +347,7 @@ windowsModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList
}
else
{
GfTrace("windowsModInfoDir: ... can't open dll %s\n", soPath);
GfLogError("windowsModInfoDir: ... can't open dll %s\n", soPath);
}
}
}
@ -400,7 +400,7 @@ windowsModUnloadList(tModList **modlist)
FreeLibrary(SOHandle(curMod->handle));
}
GfOut("Unloaded module %s\n", curMod->sopath);
GfLogTrace("Unloaded module %s\n", curMod->sopath);
GfModInfoFreeNC(curMod->modInfo, curMod->modInfoSize);
free(curMod->sopath);
@ -436,7 +436,7 @@ windowsDirGetList(const char *dir)
_finddata_t FData;
char Dir_name[ 1024 ];
sprintf( Dir_name, "%s\\*.*", dir );
GfOut("Listing directory %s\n",dir);
GfLogDebug("Listing directory %s\n",dir);
long Dirent = _findfirst( Dir_name, &FData );
if ( Dirent != -1 ) {
do {
@ -547,19 +547,48 @@ windowsDirGetListFiltered(const char *dir, const char *prefix, const char *suffi
return flist;
}
// Performance counters update frequency (never changes while Windows is up and running).
static LARGE_INTEGER PerformanceFrequency;
// Initial "time" (actually the number of seconds since the system has been up).
static double InitTime = -1.0;
/*
* Function
* windowsTimeClock
*
* Description
* Return the number of seconds since the game is running (resolution 1 micro-second).
*
* Parameters
* None
*
* Return
* The number of seconds since the game is running
*
*/
static double
windowsTimeClock(void)
{
LARGE_INTEGER Frequency;
if ( !QueryPerformanceFrequency( &Frequency ) )
return( 0 );
LARGE_INTEGER counter;
if ( !QueryPerformanceCounter( &counter ) )
{
GfLogError("Failed to QueryPerformanceCounter : %s\n", GetLastError());
return 0.0;
}
LARGE_INTEGER Counter;
if ( !QueryPerformanceCounter( &Counter ) )
return( 0 );
// Initialize initial time if not already done.
if (InitTime < 0)
{
// Initialize PerformanceFrequency (never changes while Windows is up and running).
if (!QueryPerformanceFrequency( &PerformanceFrequency ) )
GfLogError("Failed to QueryPerformanceFrequency : %s\n", GetLastError());
InitTime = (double)counter.QuadPart / (double)PerformanceFrequency.QuadPart;
}
double D = (double)Counter.QuadPart / (double)Frequency.QuadPart;
return( D );
return ((double)counter.QuadPart / (double)PerformanceFrequency.QuadPart) - InitTime;
}
/*
@ -594,8 +623,8 @@ windowsGetOSInfo(int* pnMajor, int* pnMinor, int* pnBits)
if (!GetVersionEx((OSVERSIONINFO*)&osvi))
{
GfOut("Error: Could not get Windows OS version info");
return false;
GfLogError("Error: Could not get Windows OS version info");
return false;
}
// Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
@ -723,7 +752,7 @@ windowsGetOSInfo(int* pnMajor, int* pnMinor, int* pnBits)
}
}
GfOut("Detected %s (%d.%d)\n", pszVerSionString, *pnMajor, *pnMinor);
GfLogInfo("Detected %s (%d.%d)\n", pszVerSionString, *pnMajor, *pnMinor);
return true;
}
@ -760,11 +789,11 @@ windowsGetNumberOfCPUs()
if (nCPUs < 1)
{
GfOut("Could not get the number of CPUs here ; assuming only 1\n");
GfLogWarning("Could not get the number of CPUs here ; assuming only 1\n");
nCPUs = 1;
}
else
GfOut("Detected %u CPUs\n", nCPUs);
GfLogInfo("Detected %u CPUs\n", nCPUs);
}
return nCPUs;
@ -817,7 +846,7 @@ windowsSetThreadAffinity(int nCPUId)
nBitIndex--;
if (nCPUIndex != nCPUId)
{
GfError("Target CPU %d not found (erroneous id specified ?)\n", nCPUId);
GfLogError("Target CPU %d not found (erroneous id specified ?)\n", nCPUId);
return false;
}
@ -827,18 +856,18 @@ windowsSetThreadAffinity(int nCPUId)
// Get the handle for the current thread.
HANDLE hCurrThread = GetCurrentThread();
GfOut("Current thread handle is 0x%X\n", hCurrThread);
GfLogTrace("Current thread handle is 0x%X\n", hCurrThread);
// Set the affinity mask for the current thread ("stick" it to the target core).
if (SetThreadAffinityMask(hCurrThread, (DWORD_PTR)nThreadAffinityMask) == 0)
{
GfError("Failed to set current thread (handle=0x%X) affinity mask to 0x%X)\n",
hCurrThread, nThreadAffinityMask);
GfLogError("Failed to set current thread (handle=0x%X) affinity mask to 0x%X)\n",
hCurrThread, nThreadAffinityMask);
return false;
}
else
GfOut("Affinity mask set to 0x%X for current thread (handle=0x%X)\n",
nThreadAffinityMask, hCurrThread);
GfLogTrace("Affinity mask set to 0x%X for current thread (handle=0x%X)\n",
nThreadAffinityMask, hCurrThread);
return true;
}
@ -862,6 +891,7 @@ windowsSetThreadAffinity(int nCPUId)
void
WindowsSpecInit(void)
{
// Initialize OSSpec interface.
memset(&GfOs, 0, sizeof(GfOs));
GfOs.modLoad = windowsModLoad;