Skip to content

Commit

Permalink
Migrate profiler code to ST::string
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Nov 29, 2023
1 parent 6491a18 commit 64d0ce8
Show file tree
Hide file tree
Showing 28 changed files with 232 additions and 286 deletions.
6 changes: 3 additions & 3 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ bool plClient::IUpdate()
plgDispatch::MsgSend(eval);
plProfile_EndTiming(EvalMsg);

const char *xFormLap1 = "Main";
const ST::string xFormLap1 = ST_LITERAL("Main");
plProfile_BeginLap(TransformMsg, xFormLap1);
plTransformMsg* xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
Expand All @@ -1635,15 +1635,15 @@ bool plClient::IUpdate()
// At this point, we just register for a plDelayedTransformMsg when dirtied.
if (!plCoordinateInterface::GetDelayedTransformsEnabled())
{
const char *xFormLap2 = "Simulation";
const ST::string xFormLap2 = ST_LITERAL("Simulation");
plProfile_BeginLap(TransformMsg, xFormLap2);
xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
plProfile_EndLap(TransformMsg, xFormLap2);
}
else
{
const char *xFormLap3 = "Delayed";
const ST::string xFormLap3 = ST_LITERAL("Delayed");
plProfile_BeginLap(TransformMsg, xFormLap3);
xform = new plDelayedTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ bool plFollowMod::MsgReceive(plMessage* msg)
plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg);
if( rend )
{
plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName());
fLeaderL2W = rend->Pipeline()->GetCameraToWorld();
fLeaderW2L = rend->Pipeline()->GetWorldToCamera();
fLeaderSet = true;
plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plListenerMsg* list = plListenerMsg::ConvertNoRef(msg);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ bool plLineFollowMod::MsgReceive(plMessage* msg)
plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg);
if( rend )
{
plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName());
hsPoint3 oldPos = fSearchPos;
fSearchPos = rend->Pipeline()->GetViewPositionWorld();
ICheckForPop(oldPos, fSearchPos);
plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plListenerMsg* list = plListenerMsg::ConvertNoRef(msg);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg)

if( rend )
{
plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName());

if( HasFlag(kFaceCam) )
{
Expand Down Expand Up @@ -310,7 +310,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg)

IFacePoint(rend->Pipeline(), fFacePoint);

plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plArmatureUpdateMsg* armMsg = plArmatureUpdateMsg::ConvertNoRef(msg);
Expand Down
31 changes: 11 additions & 20 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,12 @@ PF_CONSOLE_CMD( Stats, Show, // Group name, Function name
"Shows or hides a given category of statistics.\n"
"List the valid categories using Stats.ListGroups")
{
const ST::string& group = numParams > 0 ? params[0] : ST::string();

if (numParams > 1) {
const ST::string& stat = params[1];
plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str());
plProfileManagerFull::Instance().ShowLaps(params[0], params[1]);
} else if (numParams > 0) {
plProfileManagerFull::Instance().ShowGroup(params[0]);
} else {
plProfileManagerFull::Instance().ShowGroup(group.c_str());
plProfileManagerFull::Instance().ShowGroup(ST_LITERAL("General"));
}
}

Expand All @@ -506,9 +505,7 @@ PF_CONSOLE_CMD(Stats, ShowLaps,
"string group, string stat",
"")
{
const ST::string& group = params[0];
const ST::string& stat = params[1];
plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str());
plProfileManagerFull::Instance().ShowLaps(params[0], params[1]);
}

PF_CONSOLE_CMD(Stats, ListGroups, "", "Prints the names of all the stat groups to the console")
Expand Down Expand Up @@ -554,8 +551,7 @@ PF_CONSOLE_CMD(Stats, SetAvgTime, "int ms", "Sets the amount of time stats are a

PF_CONSOLE_CMD(Stats, Graph, "string stat, int min, int max", "Graphs the specified stat")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().CreateGraph(stat.c_str(), (int)params[1], (int)params[2]);
plProfileManagerFull::Instance().CreateGraph(params[0], (int)params[1], (int)params[2]);
}

PF_CONSOLE_CMD(Stats, ShowDetail, "", "Shows the detail stat graph")
Expand All @@ -575,36 +571,31 @@ PF_CONSOLE_CMD(Stats, ResetDetailDefaults, "", "Resets the detail graph's defaul

PF_CONSOLE_CMD(Stats, AddDetailVar, "string stat", "Adds the specified var to the detail graph with the default range of 0->100")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), 0, 100);
plProfileManagerFull::Instance().AddDetailVar(params[0], 0, 100);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithOffset, "string stat, int offset", "Adds the specified var to the detail graph with a offset and default range\n"
"of 0->(100-offset)")
{
const ST::string& stat = params[0];
int offset = (int)params[1];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), -offset, 100-offset);
plProfileManagerFull::Instance().AddDetailVar(params[0], -offset, 100-offset);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithRange, "string stat, int min, int max", "Adds the specified var to the detail graph")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[1], (int)params[2]);
plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[1], (int)params[2]);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithOffsetAndRange, "string stat, int offset, int min, int max", "Adds the specified var to the detail graph with an\n"
"offset and a range of min->(max-offset)")
{
const ST::string& stat = params[0];
int offset = (int)params[1];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[2]-offset, (int)params[3]-offset);
plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[2]-offset, (int)params[3]-offset);
}

PF_CONSOLE_CMD(Stats, RemoveDetailVar, "string stat", "Removes the specified var from the detail graph")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().RemoveDetailVar(stat.c_str());
plProfileManagerFull::Instance().RemoveDetailVar(params[0]);
}


Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ bool pfGUIControlMod::MsgReceive( plMessage *msg )
if (rend || device) {
plPipeline* pipe = rend ? rend->Pipeline() : device->Pipeline();

plProfile_BeginLap(GUITime, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(GUITime, this->GetKey()->GetUoid().GetObjectName());
ISetUpDynTextMap(pipe);
plProfile_EndLap(GUITime, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(GUITime, this->GetKey()->GetUoid().GetObjectName());

if (rend)
plgDispatch::Dispatch()->UnRegisterForExactType(plRenderMsg::Index(), GetKey());
Expand Down
46 changes: 24 additions & 22 deletions Sources/Plasma/NucleusLib/inc/plProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "HeadSpin.h"

#include <string_theory/string>

#ifndef PLASMA_EXTERNAL_RELEASE
#define PL_PROFILE_ENABLED
#endif
Expand Down Expand Up @@ -79,23 +81,23 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#ifdef PL_PROFILE_ENABLED

#define plProfile_CreateTimerNoReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime | plProfileVar::kDisplayNoReset)
#define plProfile_CreateTimer(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime)
#define plProfile_CreateAsynchTimer(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime | plProfileVar::kDisplayResetEveryBegin | plProfileVar::kDisplayNoReset)
#define plProfile_CreateTimerNoReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime | plProfileVar::kDisplayNoReset)
#define plProfile_CreateTimer(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime)
#define plProfile_CreateAsynchTimer(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime | plProfileVar::kDisplayResetEveryBegin | plProfileVar::kDisplayNoReset)
#define plProfile_BeginTiming(varName) gProfileVar##varName.BeginTiming()
#define plProfile_EndTiming(varName) gProfileVar##varName.EndTiming()
#define plProfile_BeginLap(varName, lapName) gProfileVar##varName.BeginLap(lapName)
#define plProfile_EndLap(varName, lapName) gProfileVar##varName.EndLap(lapName)

#define plProfile_CreateCounter(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayCount)
#define plProfile_CreateCounterNoReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayCount | plProfileVar::kDisplayNoReset)
#define plProfile_CreateCounter(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayCount)
#define plProfile_CreateCounterNoReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayCount | plProfileVar::kDisplayNoReset)
#define plProfile_Inc(varName) gProfileVar##varName.Inc()
#define plProfile_IncCount(varName, count) gProfileVar##varName.Inc(count)
#define plProfile_Dec(varName) gProfileVar##varName.Dec()
#define plProfile_Set(varName, value) gProfileVar##varName.Set(value)

#define plProfile_CreateMemCounter(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayMem | plProfileVar::kDisplayNoReset)
#define plProfile_CreateMemCounterReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayMem)
#define plProfile_CreateMemCounter(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayMem | plProfileVar::kDisplayNoReset)
#define plProfile_CreateMemCounterReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayMem)
#define plProfile_NewMem(varName, memAmount) gProfileVar##varName.NewMem(memAmount)
#define plProfile_DelMem(varName, memAmount) gProfileVar##varName.DelMem(memAmount)

Expand Down Expand Up @@ -151,7 +153,7 @@ class plProfileBase
};

protected:
const char* fName; // Name of timer
ST::string fName; // Name of timer

uint64_t fValue;

Expand All @@ -168,7 +170,7 @@ class plProfileBase

void IAddAvg();

void IPrintValue(uint64_t value, char* buf, bool printType);
ST::string IPrintValue(uint64_t value, bool printType);

public:
plProfileBase();
Expand All @@ -181,13 +183,13 @@ class plProfileBase

uint64_t GetValue();

void PrintValue(char* buf, bool printType=true);
void PrintAvg(char* buf, bool printType=true);
void PrintMax(char* buf, bool printType=true);
ST::string PrintValue(bool printType = true);
ST::string PrintAvg(bool printType = true);
ST::string PrintMax(bool printType = true);

uint32_t GetTimerSamples() const { return fTimerSamples; }

const char* GetName() { return fName; }
ST::string GetName() { return fName; }

void SetActive(bool s) { fActive = s; }

Expand All @@ -202,21 +204,21 @@ class plProfileBase
class plProfileVar : public plProfileBase
{
protected:
const char* fGroup;
ST::string fGroup;
plProfileLaps* fLaps;
bool fLapsActive;

plProfileVar() {}

void IBeginTiming();
void IEndTiming();
void IBeginLap(const char* lapName);
void IEndLap(const char* lapName);

void IBeginLap(const ST::string& lapName);
void IEndLap(const ST::string& lapName);

public:
// Name is the timer name. Each timer group gets its own plStatusLog
plProfileVar(const char *name, const char* group, uint8_t flags);
plProfileVar(ST::string name, ST::string group, uint8_t flags);
~plProfileVar();

// For timing
Expand All @@ -238,10 +240,10 @@ class plProfileVar : public plProfileBase
// Will output to log like
// Timername : lapCnt: (lapName) : 3.22 msec
//
void BeginLap(const char* lapName) { if(fActive && fRunning) IBeginLap(lapName); }
void EndLap(const char* lapName) { if(fActive && fRunning) IEndLap(lapName); }
const char* GetGroup() { return fGroup; }
void BeginLap(const ST::string& lapName) { if (fActive && fRunning) IBeginLap(lapName); }
void EndLap(const ST::string& lapName) { if (fActive && fRunning) IEndLap(lapName); }

ST::string GetGroup() { return fGroup; }

plProfileLaps* GetLaps() { return fLaps; }

Expand Down
Loading

0 comments on commit 64d0ce8

Please sign in to comment.