Skip to content

Commit d8610b6

Browse files
author
Roderick Kennedy
committed
Unix time measurement for profiling
1 parent d67cfc5 commit d8610b6

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

Core/Timer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ using namespace platform::core;
1616
#else
1717
#define LARGE_INTEGER long
1818
#endif
19-
#if defined(__ORBIS__) | defined(__COMMODORE__)
20-
#include <perf.h>
21-
static uint64_t performanceCounter()
19+
#if defined(__ORBIS__) || defined(__COMMODORE__) || defined(UNIX)
20+
#include <time.h>
21+
#if defined(__ORBIS__)
22+
#include <perf.h>
23+
#endif
24+
static uint64_t performanceCounter()
2225
{
2326
uint64_t result = 0;
2427
timespec ts;
2528
clock_gettime(CLOCK_MONOTONIC, &ts);
2629
result = (uint64_t)ts.tv_sec * 1000000000LL + (uint64_t)ts.tv_nsec;
2730
return result;
2831
}
29-
uint64_t performanceFrequency()
32+
static uint64_t performanceFrequency()
3033
{
3134
uint64_t result = 1;
3235
result = 1000000000LL;
@@ -84,8 +87,8 @@ void Timer::StartTime()
8487
LARGE_INTEGER &tStart=*(reinterpret_cast<LARGE_INTEGER*>(&iStart));
8588
QueryPerformanceCounter(&tStart);
8689
#endif
87-
#if defined(__ORBIS__) | defined(__COMMODORE__)
88-
iStart=(double)performanceCounter();
90+
#if defined(__ORBIS__) || defined(__COMMODORE__) || defined(UNIX)
91+
iStart=performanceCounter();
8992
#endif
9093
}
9194

@@ -101,8 +104,8 @@ float Timer::FinishTime()
101104
Time=((float)(tStop.QuadPart-tStart.QuadPart-Oht))/(float)dPerfFreq;
102105
TimeSum+=Time;
103106
#endif
104-
#if defined(__ORBIS__) | defined(__COMMODORE__)
105-
iStop=(double)performanceCounter();
107+
#if defined(__ORBIS__) || defined(__COMMODORE__) || defined(UNIX)
108+
iStop=performanceCounter();
106109
Time=(float)(1000.0*(double)(iStop-iStart)/(double)performanceFrequency());
107110
iStart=iStop;
108111
TimeSum+=Time;
@@ -122,7 +125,7 @@ float Timer::AbsoluteTimeMS()
122125
else
123126
t=((float)(tStop.QuadPart-tStart.QuadPart))/(float)dPerfFreq;
124127
#endif
125-
#ifdef __ORBIS__
128+
#if defined(__ORBIS__) || defined(__COMMODORE__) || defined(UNIX)
126129
return (float)(1000.0*(double)performanceCounter()/(double)performanceFrequency());
127130
#endif
128131
return t;

Core/Timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace platform
2020
{
2121
private:
2222
static __int64 OverheadTicks; // overhead in calling timer
23-
#if defined(__ORBIS__) | defined(__COMMODORE__)
23+
#if defined(__ORBIS__) || defined(__COMMODORE__) || defined(UNIX)
2424
uint64_t iStart,iStop;
2525
#endif
26-
#ifdef _MSC_VER
26+
#ifdef _MSC_VER
2727
Int64 iStart,iStop;
2828
int PerfFreqAdjust; // in case Freq is too big
2929
float dPerfFreq; // ticks per second

0 commit comments

Comments
 (0)