Browse Source

Template-ize hsTimer return values.

Darryl Pogue 10 years ago
parent
commit
a3ae4201a2
  1. 4
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  2. 4
      Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp
  3. 63
      Sources/Plasma/NucleusLib/inc/hsTimer.h
  4. 10
      Sources/Plasma/NucleusLib/inc/plProfile.h
  5. 20
      Sources/Plasma/NucleusLib/inc/plProfileManager.cpp
  6. 10
      Sources/Plasma/NucleusLib/inc/plProfileManager.h
  7. 10
      Sources/Plasma/NucleusLib/pnDispatch/plDispatch.cpp
  8. 42
      Sources/Plasma/NucleusLib/pnTimer/hsTimer.cpp
  9. 2
      Sources/Plasma/PubUtilLib/plPipeline/plDTProgressMgr.cpp
  10. 14
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  11. 6
      Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp

4
Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp

@ -1024,8 +1024,8 @@ void pfConsole::Draw( plPipeline *p )
plDebugText& drawText = plDebugText::Instance();
thisTime = (float)hsTimer::PrecTicksToSecs( hsTimer::GetPrecTickCount() );
thisTime = hsTimer::GetSeconds<float>();
if( fMode == kModeHidden && fEffectCounter == 0 )
{

4
Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp

@ -52,7 +52,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, plString& info);
plDispatchLog::plDispatchLog() :
fLog(nil),
fStartTicks(hsTimer::GetFullTickCount())
fStartTicks(hsTimer::GetTicks())
{
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(20, "Dispatch.log", plStatusLog::kAlignToTop | plStatusLog::kFilledBackground | plStatusLog::kRawTimeStamp);
fIncludeTypes.SetSize(plFactory::GetNumClasses());
@ -130,7 +130,7 @@ void plDispatchLog::DumpMsg(plMessage* msg, int numReceivers, int sendTimeMs, in
fLog->AddLine("\n");
}
float sendTime = hsTimer::FullTicksToMs(hsTimer::GetFullTickCount() - fStartTicks);
float sendTime = hsTimer::GetMilliSeconds<float>(hsTimer::GetTicks() - fStartTicks);
char indentStr[50];
indent = hsMinimum(indent, sizeof(indentStr)-1);

63
Sources/Plasma/NucleusLib/inc/hsTimer.h

@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plTimerShare
{
private:
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::time_point<Clock> TimePoint;
typedef Clock::duration Duration;
@ -72,8 +73,39 @@ protected:
bool fClamping;
double GetSeconds() const;
double GetMilliSeconds() const;
template<typename T = double>
T GetSeconds() const
{
typedef std::chrono::duration<T> duration_type;
Duration d = GetRawTicks();
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetSeconds(uint64_t ticks) const
{
typedef std::chrono::duration<T> duration_type;
Duration d(ticks);
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetMilliSeconds() const
{
typedef std::chrono::duration<T, std::milli> duration_type;
Duration d = GetRawTicks();
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetMilliSeconds(uint64_t ticks) const
{
typedef std::chrono::duration<T, std::milli> duration_type;
Duration d(ticks);
return std::chrono::duration_cast<duration_type>(d).count();
}
uint64_t GetTicks() const;
float GetDelSysSeconds() const { return fDelSysSeconds; }
double GetSysSeconds() const { return fSysSeconds; }
@ -112,8 +144,19 @@ protected:
public:
static double GetSeconds() { return fTimer->GetSeconds(); }
static double GetMilliSeconds() { return fTimer->GetMilliSeconds(); }
template<typename T = double>
static T GetSeconds() { return fTimer->GetSeconds<T>(); }
template<typename T = double>
static T GetSeconds(uint64_t ticks) { return fTimer->GetSeconds<T>(ticks); }
template<typename T = double>
static T GetMilliSeconds() { return fTimer->GetMilliSeconds<T>(); }
template<typename T = double>
static T GetMilliSeconds(uint64_t ticks) { return fTimer->GetMilliSeconds<T>(ticks); }
static uint64_t GetTicks() { return fTimer->GetTicks(); }
static float GetDelSysSeconds() { return fTimer->GetDelSysSeconds(); }
static double GetSysSeconds() { return fTimer->GetSysSeconds(); }
@ -133,18 +176,6 @@ public:
static float GetTimeClamp() { return fTimer->GetTimeClamp(); }
static bool IsClamping() { return fTimer->IsClamping(); }
///////////////////////////
// Precision timer routines - these are stateless and implemented as statics.
///////////////////////////
static uint32_t GetPrecTickCount();
static double GetPrecTicksPerSec();
static double PrecTicksToSecs(uint32_t ticks);
// If you need to time something longer than 20 seconds, use this instead of
// the precision timer. It works the same, it just gives you full resolution.
static uint64_t GetFullTickCount();
static float FullTicksToMs(uint64_t ticks);
//
// Pass GetTheTimer() into other process space, and then call SetTheTimer() on it.
static void SetTheTimer(plTimerShare* timer);

10
Sources/Plasma/NucleusLib/inc/plProfile.h

@ -153,7 +153,7 @@ public:
protected:
const char* fName; // Name of timer
uint32_t fValue;
uint64_t fValue;
uint32_t fAvgCount;
uint64_t fAvgTotal;
@ -168,7 +168,7 @@ protected:
void IAddAvg();
void IPrintValue(uint32_t value, char* buf, bool printType);
void IPrintValue(uint64_t value, char* buf, bool printType);
public:
plProfileBase();
@ -179,7 +179,7 @@ public:
void UpdateAvg();
uint32_t GetValue();
uint64_t GetValue();
void PrintValue(char* buf, bool printType=true);
void PrintAvg(char* buf, bool printType=true);
@ -230,7 +230,7 @@ public:
void Inc(int i = 1) { fValue += i;}
void Dec(int i = 1) { fValue -= i;}
void Set(uint32_t value) { fValue = value; }
void Set(uint64_t value) { fValue = value; }
//
// For multiple timings per frame of the same thing ie. Each particle system
@ -249,4 +249,4 @@ public:
void SetLapsActive(bool s) { fLapsActive = s; }
};
#endif // plProfile_h_inc
#endif // plProfile_h_inc

20
Sources/Plasma/NucleusLib/inc/plProfileManager.cpp

@ -150,15 +150,15 @@ uint32_t GetProcSpeedAlt()
}
#define GetProfileTicks() GetPentiumCounter()
#define TicksToMSec(t) (float(t) / float(gCyclesPerMS))
#else
#define GetProfileTicks() hsTimer::GetPrecTickCount()
#define GetProfileTicks() hsTimer::GetTicks()
#define TicksToMSec(t) hsTimer::GetMilliSeconds<float>(t)
#endif // USE_FAST_TIMER
#define TicksToMSec(t) (float(t) / float(gCyclesPerMS))
#define MSecToTicks(t) (float(t) * float(gCyclesPerMS))
plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0)
{
@ -169,8 +169,6 @@ plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0)
fProcessorSpeed = GetProcSpeedAlt();
gCyclesPerMS = fProcessorSpeed / 1000;
#else
gCyclesPerMS = hsTimer::GetPrecTicksPerSec() / 1000;
#endif
}
@ -251,7 +249,7 @@ void plProfileManager::EndFrame()
}
}
uint32_t plProfileManager::GetTime()
uint64_t plProfileManager::GetTime()
{
return GetProfileTicks();
}
@ -300,10 +298,10 @@ void plProfileBase::UpdateAvg()
}
}
uint32_t plProfileBase::GetValue()
uint64_t plProfileBase::GetValue()
{
if (hsCheckBits(fDisplayFlags, kDisplayTime))
return (uint32_t)TicksToMSec(fValue);
return (uint64_t)TicksToMSec(fValue);
else
return fValue;
}
@ -334,7 +332,7 @@ static const char *insertCommas(unsigned int value)
return str;
}
void plProfileBase::IPrintValue(uint32_t value, char* buf, bool printType)
void plProfileBase::IPrintValue(uint64_t value, char* buf, bool printType)
{
if (hsCheckBits(fDisplayFlags, kDisplayCount))
{
@ -416,7 +414,7 @@ plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName)
return nil;
}
void plProfileLaps::BeginLap(uint32_t curValue, const char* name)
void plProfileLaps::BeginLap(uint64_t curValue, const char* name)
{
LapInfo* lap = IFindLap(name);
if (!lap)
@ -432,7 +430,7 @@ void plProfileLaps::BeginLap(uint32_t curValue, const char* name)
lap->BeginTiming(curValue);
}
void plProfileLaps::EndLap(uint32_t curValue, const char* name)
void plProfileLaps::EndLap(uint64_t curValue, const char* name)
{
LapInfo* lap = IFindLap(name);

10
Sources/Plasma/NucleusLib/inc/plProfileManager.h

@ -76,7 +76,7 @@ public:
uint32_t GetProcessorSpeed() { return fProcessorSpeed; }
// Backdoor for hack timers in calculated profiles
static uint32_t GetTime();
static uint64_t GetTime();
};
class plProfileLaps
@ -91,16 +91,16 @@ protected:
LapInfo(const char* name) { fName = name; fDisplayFlags = kDisplayTime; }
bool operator<(const LapInfo& rhs) const { return fLastAvg < rhs.fLastAvg; }
void BeginTiming(uint32_t value) { fValue -= value; }
void EndTiming(uint32_t value) { fValue += value; fTimerSamples++; }
void BeginTiming(uint64_t value) { fValue -= value; }
void EndTiming(uint64_t value) { fValue += value; fTimerSamples++; }
};
std::vector<LapInfo> fLapTimes;
LapInfo* IFindLap(const char* lapName);
public:
void BeginLap(uint32_t curValue, const char* name);
void EndLap(uint32_t curValue, const char* name);
void BeginLap(uint64_t curValue, const char* name);
void EndLap(uint64_t curValue, const char* name);
void BeginFrame();
void EndFrame();

10
Sources/Plasma/NucleusLib/pnDispatch/plDispatch.cpp

@ -311,7 +311,7 @@ void plDispatch::IMsgDispatch()
static uint64_t startTicks = 0;
if (plDispatchLogBase::IsLogging())
startTicks = hsTimer::GetFullTickCount();
startTicks = hsTimer::GetTicks();
int i, numReceivers=0;
for( i = 0; fMsgCurrent && i < fMsgCurrent->GetNumReceivers(); i++ )
@ -343,7 +343,7 @@ void plDispatch::IMsgDispatch()
}
#ifndef PLASMA_EXTERNAL_RELEASE
uint32_t rcvTicks = hsTimer::GetPrecTickCount();
uint64_t rcvTicks = hsTimer::GetTicks();
// Object could be deleted by this message, so we need to log this stuff now
plString keyname = "(unknown)";
@ -373,9 +373,9 @@ void plDispatch::IMsgDispatch()
#ifndef PLASMA_EXTERNAL_RELEASE
if (plDispatchLogBase::IsLoggingLong())
{
rcvTicks = hsTimer::GetPrecTickCount() - rcvTicks;
rcvTicks = hsTimer::GetTicks() - rcvTicks;
float rcvTime = (float)(hsTimer::PrecTicksToSecs(rcvTicks) * 1000.f);
float rcvTime = hsTimer::GetMilliSeconds<float>(rcvTicks);
// If the receiver takes more than 5 ms to process its message, log it
if (rcvTime > 5.f)
plDispatchLogBase::GetInstance()->LogLongReceive(keyname.c_str(), className, clonePlayerID, msg, rcvTime);
@ -392,7 +392,7 @@ void plDispatch::IMsgDispatch()
// for message logging
// if (plDispatchLogBase::IsLogging())
// {
// float sendTime = hsTimer::FullTicksToMs(hsTimer::GetFullTickCount() - startTicks);
// float sendTime = hsTimer::GetMilliSeconds<float>(hsTimer::GetTicks() - startTicks);
//
// plDispatchLogBase::GetInstance()->DumpMsg(msg, numReceivers, (int)sendTime, responseLevel*2 /* indent */);
// if (origTail==fMsgCurrent)

42
Sources/Plasma/NucleusLib/pnTimer/hsTimer.cpp

@ -44,9 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plTweak.h"
typedef std::chrono::duration<double> dSeconds;
typedef std::chrono::duration<double, std::milli> dMilliseconds;
//
// plTimerShare - the actual worker. All process spaces should share a single
// plTimerShare to keep time synchronized across spaces.
@ -71,14 +68,12 @@ plTimerShare::~plTimerShare()
{
}
double plTimerShare::GetSeconds() const
uint64_t plTimerShare::GetTicks() const
{
return dSeconds(GetRawTicks()).count();
}
plTimerShare::Duration d = plTimerShare::Clock::now().time_since_epoch();
typedef std::chrono::duration<uint64_t, plTimerShare::Clock::period> ticks;
double plTimerShare::GetMilliSeconds() const
{
return dMilliseconds(GetRawTicks()).count();
return std::chrono::duration_cast<ticks>(d).count();
}
double plTimerShare::IncSysSeconds()
@ -194,8 +189,7 @@ plTimerShare::Duration plTimerShare::GetRawTicks() const
//
// hsTimer - thin static interface to plTimerShare. Also keeps a couple of
// constants.
// hsTimer - thin static interface to plTimerShare.
//
static plTimerShare staticTimer;
plTimerShare* hsTimer::fTimer = &staticTimer; // until overridden.
@ -204,29 +198,3 @@ void hsTimer::SetTheTimer(plTimerShare* timer)
{
fTimer = timer;
}
double hsTimer::GetPrecTicksPerSec()
{
return double(plTimerShare::Clock::period::num) /
double(plTimerShare::Clock::period::den);
}
uint32_t hsTimer::GetPrecTickCount()
{
return uint32_t(plTimerShare::Clock::now().time_since_epoch().count());
}
double hsTimer::PrecTicksToSecs(uint32_t ticks)
{
return dSeconds(plTimerShare::Duration(ticks)).count();
}
uint64_t hsTimer::GetFullTickCount()
{
return uint64_t(plTimerShare::Clock::now().time_since_epoch().count());
}
float hsTimer::FullTicksToMs(uint64_t ticks)
{
return float(dMilliseconds(plTimerShare::Duration(ticks)).count());
}

2
Sources/Plasma/PubUtilLib/plPipeline/plDTProgressMgr.cpp

@ -153,7 +153,7 @@ void plDTProgressMgr::Draw( plPipeline *p )
if (fActivePlate)
{
float currentMs = hsTimer::FullTicksToMs(hsTimer::GetFullTickCount());
float currentMs = hsTimer::GetMilliSeconds<float>();
if ((currentMs - fLastDraw) > 30)
{
fCurrentImage++;

14
Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp

@ -355,7 +355,7 @@ bool plResManager::IReadObject(plKeyImp* pKey, hsStream *stream)
uint64_t startTotalTime = totalTime;
uint64_t startTime = 0;
if (fLogReadTimes)
startTime = hsTimer::GetFullTickCount();
startTime = hsTimer::GetTicks();
hsKeyedObject* ko = nil;
@ -449,7 +449,7 @@ bool plResManager::IReadObject(plKeyImp* pKey, hsStream *stream)
if (fLogReadTimes)
{
uint64_t ourTime = hsTimer::GetFullTickCount() - startTime;
uint64_t ourTime = hsTimer::GetTicks() - startTime;
uint64_t childTime = totalTime - startTotalTime;
ourTime -= childTime;
@ -457,9 +457,9 @@ bool plResManager::IReadObject(plKeyImp* pKey, hsStream *stream)
pKey->GetUoid().GetObjectName().c_str(),
plFactory::GetNameOfClass(pKey->GetUoid().GetClassType()),
pKey->GetDataLen(),
hsTimer::FullTicksToMs(ourTime));
hsTimer::GetMilliSeconds<float>(ourTime));
totalTime += (hsTimer::GetFullTickCount() - startTime) - childTime;
totalTime += (hsTimer::GetTicks() - startTime) - childTime;
}
return (ko != nil);
@ -1132,7 +1132,7 @@ void plResManager::PageInRoom(const plLocation& page, uint16_t objClassToRef, pl
{
uint64_t readRoomTime = 0;
if (fLogReadTimes)
readRoomTime = hsTimer::GetFullTickCount();
readRoomTime = hsTimer::GetTicks();
plSynchEnabler ps(false); // disable dirty tracking while paging in
@ -1218,11 +1218,11 @@ void plResManager::PageInRoom(const plLocation& page, uint16_t objClassToRef, pl
if (fLogReadTimes)
{
readRoomTime = hsTimer::GetFullTickCount() - readRoomTime;
readRoomTime = hsTimer::GetTicks() - readRoomTime;
plStatusLog::AddLineS("readtimings.log", plStatusLog::kWhite, "----- Reading page %s>%s took %.1f ms",
pageNode->GetPageInfo().GetAge().c_str(), pageNode->GetPageInfo().GetPage().c_str(),
hsTimer::FullTicksToMs(readRoomTime));
hsTimer::GetMilliSeconds<float>(readRoomTime));
}
}

6
Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp

@ -337,7 +337,7 @@ bool plAutoProfileImp::MsgReceive(plMessage* msg)
{
if (!ageLoaded->fLoaded)
{
fLinkTime = hsTimer::GetFullTickCount();
fLinkTime = hsTimer::GetTicks();
hsStatusMessage("Age unloaded");
}
return true;
@ -348,8 +348,8 @@ bool plAutoProfileImp::MsgReceive(plMessage* msg)
{
if (fNextAge > 0)
{
fLinkTime = hsTimer::GetFullTickCount() - fLinkTime;
float ms = hsTimer::FullTicksToMs(fLinkTime);
fLinkTime = hsTimer::GetTicks() - fLinkTime;
float ms = hsTimer::GetMilliSeconds<float>(fLinkTime);
hsStatusMessageF("Age %s finished load, took %.1f ms",
fAges[fNextAge-1].c_str(),

Loading…
Cancel
Save