From 64d0ce8a272a31d02eea69254b31ba9c071903d5 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Mon, 2 Oct 2023 23:19:14 +0200 Subject: [PATCH] Migrate profiler code to ST::string --- Sources/Plasma/Apps/plClient/plClient.cpp | 6 +- .../FeatureLib/pfAnimation/plFollowMod.cpp | 4 +- .../pfAnimation/plLineFollowMod.cpp | 4 +- .../pfAnimation/plViewFaceModifier.cpp | 4 +- .../pfConsole/pfConsoleCommands.cpp | 31 ++--- .../pfGameGUIMgr/pfGUIControlMod.cpp | 4 +- Sources/Plasma/NucleusLib/inc/plProfile.h | 46 ++++--- .../NucleusLib/inc/plProfileManager.cpp | 127 +++++++---------- .../Plasma/NucleusLib/inc/plProfileManager.h | 11 +- .../PubUtilLib/plAnimation/plAGMasterMod.cpp | 4 +- .../PubUtilLib/plAudio/plAudioSystem.cpp | 4 +- .../PubUtilLib/plDrawable/plDrawableSpans.cpp | 46 +++---- .../PubUtilLib/plGLight/plLightInfo.cpp | 4 +- .../PubUtilLib/plGLight/plShadowCaster.cpp | 4 +- .../PubUtilLib/plGLight/plShadowMaster.cpp | 4 +- .../plInputCore/plInputInterfaceMgr.cpp | 4 +- .../plParticleSystem/plParticleEmitter.cpp | 4 +- .../plParticleSystem/plParticleSystem.cpp | 4 +- .../PubUtilLib/plPhysX/plGenericPhysical.cpp | 4 +- .../PubUtilLib/plScene/plPageTreeMgr.cpp | 4 +- .../PubUtilLib/plScene/plPostEffectMod.cpp | 4 +- .../PubUtilLib/plStatGather/plAutoProfile.cpp | 27 ++-- .../PubUtilLib/plStatGather/plAutoProfile.h | 4 +- .../plStatGather/plCalculatedProfiles.cpp | 7 +- .../plStatGather/plCalculatedProfiles.h | 4 +- .../plStatGather/plProfileManagerFull.cpp | 129 ++++++++---------- .../plStatGather/plProfileManagerFull.h | 16 +-- .../PubUtilLib/plSurface/hsGMaterial.cpp | 4 +- 28 files changed, 232 insertions(+), 286 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 2ef6ae8a38..a7a7d347e4 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -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); @@ -1635,7 +1635,7 @@ 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); @@ -1643,7 +1643,7 @@ bool plClient::IUpdate() } 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); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp index f2d5835656..ba6b9c4827 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp @@ -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); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp index 4b4b76ea8d..9d66452ad2 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp @@ -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); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp index 9aec6d9eb0..3f892bd773 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp @@ -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) ) { @@ -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); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index 539400e173..2d9e8cc543 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -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")); } } @@ -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") @@ -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") @@ -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]); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index 1f8e5c16d8..c9ba51efa8 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -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()); diff --git a/Sources/Plasma/NucleusLib/inc/plProfile.h b/Sources/Plasma/NucleusLib/inc/plProfile.h index 6ccba04cdf..3d34e99478 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfile.h +++ b/Sources/Plasma/NucleusLib/inc/plProfile.h @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" +#include + #ifndef PLASMA_EXTERNAL_RELEASE #define PL_PROFILE_ENABLED #endif @@ -79,23 +81,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #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) @@ -151,7 +153,7 @@ class plProfileBase }; protected: - const char* fName; // Name of timer + ST::string fName; // Name of timer uint64_t fValue; @@ -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(); @@ -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; } @@ -202,7 +204,7 @@ class plProfileBase class plProfileVar : public plProfileBase { protected: - const char* fGroup; + ST::string fGroup; plProfileLaps* fLaps; bool fLapsActive; @@ -210,13 +212,13 @@ class plProfileVar : public plProfileBase 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 @@ -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; } diff --git a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp index f69d9b39c8..9c12570f61 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp +++ b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp @@ -42,7 +42,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plProfileManager.h" #include "plProfile.h" #include "hsTimer.h" -#include + +#include +#include plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0) { @@ -70,7 +72,7 @@ void plProfileManager::SetAvgTime(uint32_t avgMS) kAvgMilliseconds = avgMS; } -static plProfileVar gVarEFPS("EFPS", "General", plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); +static plProfileVar gVarEFPS(ST_LITERAL("EFPS"), ST_LITERAL("General"), plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); void plProfileManager::BeginFrame() { @@ -182,89 +184,65 @@ uint64_t plProfileBase::GetValue() return fValue; } -// Stolen from plMemTracker.cpp -static const char *insertCommas(unsigned long long value) +static ST::string insertCommas(unsigned long long value) { - static char str[30]; - memset(str, 0, sizeof(str)); - - snprintf(str, std::size(str), "%llu", value); - if (strlen(str) > 3) - { - memmove(&str[strlen(str)-3], &str[strlen(str)-4], 4); - str[strlen(str) - 4] = ','; - } - if (strlen(str) > 7) - { - memmove(&str[strlen(str)-7], &str[strlen(str)-8], 8); - str[strlen(str) - 8] = ','; + ST::string str; + while (value >= 1000) { + str = ST::format(",{>03}{}", value % 1000, str); + value /= 1000; } - if (strlen(str) > 11) - { - memmove(&str[strlen(str)-11], &str[strlen(str)-12], 12); - str[strlen(str) - 12] = ','; - } - - return str; + return ST::format("{}{}", value, str); } -void plProfileBase::IPrintValue(uint64_t value, char* buf, bool printType) +ST::string plProfileBase::IPrintValue(uint64_t value, bool printType) { - if (hsCheckBits(fDisplayFlags, kDisplayCount)) - { - if (printType) - { - const char* valueStr = insertCommas(value); - strcpy(buf, valueStr); + if (hsCheckBits(fDisplayFlags, kDisplayCount)) { + if (printType) { + return insertCommas(value); + } else { + return ST::string::from_uint(value); } - else - sprintf(buf, "%llu", static_cast(value)); - } - else if (hsCheckBits(fDisplayFlags, kDisplayFPS)) - { - sprintf(buf, "%.2f", 1000.0f / hsTimer::GetMilliSeconds(value)); - } - else if (hsCheckBits(fDisplayFlags, kDisplayTime)) - { - sprintf(buf, "%.2f", hsTimer::GetMilliSeconds(value)); - if (printType) - strcat(buf, " ms"); - } - else if (hsCheckBits(fDisplayFlags, kDisplayMem)) - { - if (printType) - { - if (value > (1024*1000)) - sprintf(buf, "%.2f MB", float(value) / (1024.f * 1024.f)); - else if (value > 1024) - sprintf(buf, "%llu KB", static_cast(value / 1024)); - else - sprintf(buf, "%llu b", static_cast(value)); + } else if (hsCheckBits(fDisplayFlags, kDisplayFPS)) { + return ST::format("{.2f}", 1000.0f / hsTimer::GetMilliSeconds(value)); + } else if (hsCheckBits(fDisplayFlags, kDisplayTime)) { + return ST::format("{.2f}{}", hsTimer::GetMilliSeconds(value), printType ? ST_LITERAL(" ms") : ST::string()); + } else if (hsCheckBits(fDisplayFlags, kDisplayMem)) { + if (printType) { + if (value > (1024*1000)) { + return ST::format("{.2f} MB", value / (1024.f * 1024.f)); + } else if (value > 1024) { + return ST::format("{} KB", value / 1024); + } else { + return ST::format("{} b", value); + } + } else { + return ST::string::from_uint(value); } - else - sprintf(buf, "%llu", static_cast(value)); + } else { + FATAL("Unhandled stat value type"); + return {}; } } -void plProfileBase::PrintValue(char* buf, bool printType) +ST::string plProfileBase::PrintValue(bool printType) { - IPrintValue(fValue, buf, printType); + return IPrintValue(fValue, printType); } -void plProfileBase::PrintAvg(char* buf, bool printType) +ST::string plProfileBase::PrintAvg(bool printType) { - IPrintValue(fLastAvg, buf, printType); + return IPrintValue(fLastAvg, printType); } -void plProfileBase::PrintMax(char* buf, bool printType) +ST::string plProfileBase::PrintMax(bool printType) { - IPrintValue(fMax, buf, printType); + return IPrintValue(fMax, printType); } //////////////////////////////////////////////////////////////////////////////// -plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName) +plProfileLaps::LapInfo* plProfileLaps::IFindLap(const ST::string& lapName) { static int lastSearch = 0; @@ -290,13 +268,10 @@ plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName) return nullptr; } -void plProfileLaps::BeginLap(uint64_t curValue, const char* name) +void plProfileLaps::BeginLap(uint64_t curValue, const ST::string& name) { LapInfo* lap = IFindLap(name); - if (!lap) - { - // Technically we shouldn't hold on to this pointer. However, I think - // it will be ok in all cases, so I'll wait until this blows up + if (!lap) { LapInfo info(name); fLapTimes.push_back(info); lap = &(*(fLapTimes.end()-1)); @@ -306,7 +281,7 @@ void plProfileLaps::BeginLap(uint64_t curValue, const char* name) lap->BeginTiming(curValue); } -void plProfileLaps::EndLap(uint64_t curValue, const char* name) +void plProfileLaps::EndLap(uint64_t curValue, const ST::string& name) { LapInfo* lap = IFindLap(name); @@ -333,9 +308,7 @@ void plProfileLaps::EndFrame() fLapTimes[i].EndFrame(); if (!fLapTimes[i].fUsedThisFrame) { - char buf[200]; - sprintf(buf, "Dropping unused lap %s", fLapTimes[i].GetName()); - hsStatusMessage(buf); + hsStatusMessage(ST::format("Dropping unused lap {}", fLapTimes[i].GetName()).c_str()); fLapTimes.erase(fLapTimes.begin()+i); i--; } @@ -363,11 +336,11 @@ plProfileBase* plProfileLaps::GetLap(int i) /////////////////////////////////////////////////////////////////////////////// -plProfileVar::plProfileVar(const char *name, const char* group, uint8_t flags) : - fGroup(group), +plProfileVar::plProfileVar(ST::string name, ST::string group, uint8_t flags) : + fGroup(std::move(group)), fLaps() { - fName = name; + fName = std::move(name); fDisplayFlags = flags; plProfileManager::Instance().AddTimer(this); fLapsActive = 0; @@ -378,7 +351,7 @@ plProfileVar::~plProfileVar() delete fLaps; } -void plProfileVar::IBeginLap(const char* lapName) +void plProfileVar::IBeginLap(const ST::string& lapName) { if (!fLaps) fLaps = new plProfileLaps; @@ -388,7 +361,7 @@ void plProfileVar::IBeginLap(const char* lapName) BeginTiming(); } -void plProfileVar::IEndLap(const char* lapName) +void plProfileVar::IEndLap(const ST::string& lapName) { EndTiming(); if(fLapsActive) diff --git a/Sources/Plasma/NucleusLib/inc/plProfileManager.h b/Sources/Plasma/NucleusLib/inc/plProfileManager.h index 344fc640f3..476dab7dec 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfileManager.h +++ b/Sources/Plasma/NucleusLib/inc/plProfileManager.h @@ -43,6 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plProfileManager_h_inc #include "HeadSpin.h" + +#include +#include #include #include "plProfile.h" @@ -88,7 +91,7 @@ class plProfileLaps public: bool fUsedThisFrame; - LapInfo(const char* name) : fUsedThisFrame() { fName = name; fDisplayFlags = kDisplayTime; } + LapInfo(ST::string name) : fUsedThisFrame() { fName = std::move(name); fDisplayFlags = kDisplayTime; } bool operator<(const LapInfo& rhs) const { return fLastAvg < rhs.fLastAvg; } void BeginTiming(uint64_t value) { fValue -= value; } @@ -96,11 +99,11 @@ class plProfileLaps }; std::vector fLapTimes; - LapInfo* IFindLap(const char* lapName); + LapInfo* IFindLap(const ST::string& lapName); public: - void BeginLap(uint64_t curValue, const char* name); - void EndLap(uint64_t curValue, const char* name); + void BeginLap(uint64_t curValue, const ST::string& name); + void EndLap(uint64_t curValue, const ST::string& name); void BeginFrame(); void EndFrame(); diff --git a/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp b/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp index 6a9e596bcb..ccbd51e943 100644 --- a/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp @@ -242,7 +242,7 @@ bool plAGMasterMod::IEval(double secs, float del, uint32_t dirty) // APPLYANIMATIONS void plAGMasterMod::ApplyAnimations(double time, float elapsed) { - plProfile_BeginLap(ApplyAnimation, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ApplyAnimation, this->GetKey()->GetUoid().GetObjectName()); // update any fades for (int i = 0; i < fAnimInstances.size(); i++) @@ -252,7 +252,7 @@ void plAGMasterMod::ApplyAnimations(double time, float elapsed) AdvanceAnimsToTime(time); - plProfile_EndLap(ApplyAnimation,this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ApplyAnimation,this->GetKey()->GetUoid().GetObjectName()); } void plAGMasterMod::AdvanceAnimsToTime(double time) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp index 612716f878..d19b8fb64d 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp @@ -817,7 +817,7 @@ bool plAudioSystem::MsgReceive(plMessage* msg) if (plRenderMsg* pRMsg = plRenderMsg::ConvertNoRef( msg )) { //if (fListener) { - plProfile_BeginLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName()); if (hsTimer::GetMilliSeconds() - fLastUpdateTimeMs > UPDATE_TIME_MS) { IUpdateSoftSounds(fCurrListenerPos); @@ -827,7 +827,7 @@ bool plAudioSystem::MsgReceive(plMessage* msg) plProfile_EndTiming(SoundEAXUpdate); } } - plProfile_EndLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName()); } return true; } diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp index 61a34819c5..2fa789cb9f 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp @@ -1222,7 +1222,7 @@ bool plDrawableSpans::MsgReceive( plMessage* msg ) } else if( plRenderMsg::ConvertNoRef( msg ) ) { - plProfile_BeginLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName()); IUpdateMatrixPaletteBoundsHack(); @@ -1233,7 +1233,7 @@ bool plDrawableSpans::MsgReceive( plMessage* msg ) // The pipeline will then clear out those bits as it blends them, and then we simply // re-set them here, since plRenderMsg is sent once before all the rendering is done :) fFakeBlendingSpanVector = fBlendingSpanVector; - plProfile_EndLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName()); return true; } @@ -1433,7 +1433,7 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) { plProfile_Inc(FaceSortCalls); - plProfile_BeginLap(FaceSort, "0"); + plProfile_BeginLap(FaceSort, ST_LITERAL("0")); plIcicle *span = (plIcicle *)fSpans[ index ]; plGBufferTriangle *list, temp; @@ -1462,8 +1462,8 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) tempTriList.resize(numTris * 3); elem = sortList.data(); - plProfile_EndLap(FaceSort, "0"); - plProfile_BeginLap(FaceSort, "1"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); + plProfile_BeginLap(FaceSort, ST_LITERAL("1")); hsVector3 vec(w2cMatrix.fMap[2][0], w2cMatrix.fMap[2][1], w2cMatrix.fMap[2][2]); float trans = w2cMatrix.fMap[2][3]; @@ -1478,15 +1478,15 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) } elem[i - 1].fNext = nullptr; - plProfile_EndLap(FaceSort, "1"); - plProfile_BeginLap(FaceSort, "2"); + plProfile_EndLap(FaceSort, ST_LITERAL("1")); + plProfile_BeginLap(FaceSort, ST_LITERAL("2")); // Do da sort thingy hsRadixSort rad; hsRadixSort::Elem *sortedList = rad.Sort( elem, 0 ); - plProfile_EndLap(FaceSort, "2"); - plProfile_BeginLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("2")); + plProfile_BeginLap(FaceSort, ST_LITERAL("3")); uint16_t* indices = tempTriList.data(); // Stuff into the temp array @@ -1498,8 +1498,8 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) elem = elem->fNext; } - plProfile_EndLap(FaceSort, "3"); - plProfile_BeginLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("3")); + plProfile_BeginLap(FaceSort, ST_LITERAL("4")); /// Now send them on to the buffer group fGroups[ span->fGroupIdx ]->StuffFromTriList( span->fIBufferIdx, span->fIStartIdx, @@ -1515,7 +1515,7 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) /// All done! (force buffer groups to refresh during next render call) fReadyToRender = false; - plProfile_EndLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("4")); } //// SortVisibleSpans //////////////////////////////////////////////////////// @@ -1757,7 +1757,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi plProfile_EndTiming(FaceSort); - plProfile_BeginLap(FaceSort, "0"); + plProfile_BeginLap(FaceSort, ST_LITERAL("0")); startIndex.resize(fSpans.size()); @@ -1777,7 +1777,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi } if( totTris == 0 ) { - plProfile_EndLap(FaceSort, "0"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); return; } @@ -1788,12 +1788,12 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi hsRadixSort::Elem* elem = sortScratch.data(); - plProfile_EndLap(FaceSort, "0"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); size_t iVis = 0; while (iVis < visList.size()) { - plProfile_BeginLap(FaceSort, "1"); + plProfile_BeginLap(FaceSort, ST_LITERAL("1")); // Pack them into the sort structure. We probably want to make the // plGBufferTriangle look like plTriSortData (just add span index) @@ -1824,15 +1824,15 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi } elem[cnt-1].fNext = nullptr; - plProfile_EndLap(FaceSort, "1"); - plProfile_BeginLap(FaceSort, "2"); + plProfile_EndLap(FaceSort, ST_LITERAL("1")); + plProfile_BeginLap(FaceSort, ST_LITERAL("2")); // Actual sort hsRadixSort rad; hsRadixSort::Elem* sortedList = rad.Sort( elem, 0 ); - plProfile_EndLap(FaceSort, "2"); - plProfile_BeginLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("2")); + plProfile_BeginLap(FaceSort, ST_LITERAL("3")); counters.assign(fSpans.size(), 0); @@ -1853,10 +1853,10 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi sortedList = sortedList->fNext; } - plProfile_EndLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("3")); } - plProfile_BeginLap(FaceSort, "4"); + plProfile_BeginLap(FaceSort, ST_LITERAL("4")); constexpr size_t kMaxBufferGroups = 20; constexpr size_t kMaxIndexBuffers = 20; @@ -1882,7 +1882,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi span->fILength / 3, triList.data() + startIndex[idx]); } - plProfile_EndLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("4")); fReadyToRender = false; diff --git a/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp b/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp index e815fcc3d3..08e49601bb 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp @@ -370,7 +370,7 @@ bool plLightInfo::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(LightInfo, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(LightInfo, this->GetKey()->GetUoid().GetObjectName()); if( !fDeviceRef && !GetProperty(kLPShadowOnly) ) { @@ -379,7 +379,7 @@ bool plLightInfo::MsgReceive(plMessage* msg) ICheckMaxStrength(); - plProfile_EndLap(LightInfo, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(LightInfo, this->GetKey()->GetUoid().GetObjectName()); return true; } plGenRefMsg* refMsg = plGenRefMsg::ConvertNoRef(msg); diff --git a/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp b/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp index 64429eba8d..fadeb30ed4 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp @@ -210,9 +210,9 @@ bool plShadowCaster::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName()); IOnRenderMsg(rendMsg); - plProfile_EndLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp index 42d428c28f..b56d58c8f5 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp @@ -177,9 +177,9 @@ bool plShadowMaster::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName()); IBeginRender(); - plProfile_EndLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp index b8af1f3916..a875f853ed 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp @@ -290,7 +290,7 @@ void plInputInterfaceMgr::IUpdateCursor( int32_t newCursor ) bool plInputInterfaceMgr::IEval( double secs, float del, uint32_t dirty ) { - const char *inputEval = "Eval"; + const ST::string inputEval = ST_LITERAL("Eval"); plProfile_BeginLap(Input, inputEval); @@ -420,7 +420,7 @@ bool plInputInterfaceMgr::MsgReceive( plMessage *msg ) plInputEventMsg *ieMsg = plInputEventMsg::ConvertNoRef( msg ); if (ieMsg != nullptr) { - const char *inputIEM = "InputEventMsg"; + const ST::string inputIEM = ST_LITERAL("InputEventMsg"); plProfile_BeginLap(Input, inputIEM); bool handled = false; size_t missedInputStartIdx = 0; diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp index cd6ff83bd3..af59ad77b1 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp @@ -325,7 +325,7 @@ void plParticleEmitter::IUpdateParticles(float delta) if ((fGenerator != nullptr) && (fTimeToLive >= 0)) { - plProfile_BeginLap(ParticleGenerate, fSystem->GetKeyName().c_str()); + plProfile_BeginLap(ParticleGenerate, fSystem->GetKeyName()); if (!fGenerator->AddAutoParticles(this, delta)) { delete fGenerator; @@ -333,7 +333,7 @@ void plParticleEmitter::IUpdateParticles(float delta) } if( (fTimeToLive > 0) && ((fTimeToLive -= delta) <= 0) ) fTimeToLive = -1.f; - plProfile_EndLap(ParticleGenerate, fSystem->GetKeyName().c_str()); + plProfile_EndLap(ParticleGenerate, fSystem->GetKeyName()); } fTargetInfo.fContext = fSystem->fContext; diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp index 4e0fb8841e..31178cba6d 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp @@ -485,9 +485,9 @@ bool plParticleSystem::MsgReceive(plMessage* msg) if ((rend = plRenderMsg::ConvertNoRef(msg))) { - plProfile_BeginLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName()); IHandleRenderMsg(rend->Pipeline()); - plProfile_EndLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName()); return true; } else if ((refMsg = plGenRefMsg::ConvertNoRef(msg))) diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp index a244f8e1c6..f3b1ed0573 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp @@ -500,7 +500,7 @@ void plPXPhysical::SendNewLocation(bool synchTransform, bool isSynchUpdate) if (!curl2w.Compare(fCachedLocal2World, .0001f)) { plProfile_Inc(LocationsSent); - plProfile_BeginLap(PhysicsUpdates, GetKeyName().c_str()); + plProfile_BeginLap(PhysicsUpdates, GetKeyName()); if (fCachedLocal2World.GetTranslate().fZ < kMaxNegativeZPos) { @@ -517,7 +517,7 @@ void plPXPhysical::SendNewLocation(bool synchTransform, bool isSynchUpdate) pCorrMsg->Send(); if (fProxyGen) fProxyGen->SetTransform(fCachedLocal2World, w2l); - plProfile_EndLap(PhysicsUpdates, GetKeyName().c_str()); + plProfile_EndLap(PhysicsUpdates, GetKeyName()); } } } diff --git a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp index 6bc73baf7d..331df41f2b 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp @@ -212,7 +212,7 @@ size_t plPageTreeMgr::IRenderVisList(plPipeline* pipe, std::vectorGetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(DrawableTime, p->GetKey()->GetUoid().GetObjectName()); if( sortedDrawList[i].fDrawable->GetNativeProperty(plDrawable::kPropSortSpans) ) { @@ -230,7 +230,7 @@ size_t plPageTreeMgr::IRenderVisList(plPipeline* pipe, std::vectorGetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(DrawableTime, p->GetKey()->GetUoid().GetObjectName()); } return numDrawn; diff --git a/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp b/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp index c43a317204..6a25afec3d 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp @@ -232,9 +232,9 @@ bool plPostEffectMod::MsgReceive(plMessage* msg) plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg); if( rend && IIsEnabled() ) { - plProfile_BeginLap(PostEffect, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(PostEffect, this->GetKey()->GetUoid().GetObjectName()); ISubmitRequest(); - plProfile_EndLap(PostEffect, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(PostEffect, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index 4d63a5a30e..14fc37923b 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp @@ -73,7 +73,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plGImage/plMipmap.h" #include -#include +#include +#include class plAutoProfileImp : public plAutoProfile { @@ -83,7 +84,7 @@ class plAutoProfileImp : public plAutoProfile int fNextSpawnPoint; ST::string fLastSpawnPointName; // For profiling a single age - std::string fAgeName; + ST::string fAgeName; bool fLinkedToSingleAge; bool fJustLinkToAges; @@ -103,7 +104,7 @@ class plAutoProfileImp : public plAutoProfile : fNextAge(), fNextSpawnPoint(), fLinkedToSingleAge(), fJustLinkToAges(), fLinkTime() { } - void StartProfile(const char* ageName) override; + void StartProfile(ST::string ageName) override; void LinkToAllAges() override; bool MsgReceive(plMessage* msg) override; @@ -117,12 +118,9 @@ plAutoProfile* plAutoProfile::Instance() //////////////////////////////////////////////////////////////////////////////// -void plAutoProfileImp::StartProfile(const char* ageName) +void plAutoProfileImp::StartProfile(ST::string ageName) { - if (ageName) - fAgeName = ageName; - else - fAgeName = ""; + fAgeName = std::move(ageName); IInit(); @@ -241,22 +239,19 @@ void plAutoProfileImp::INextProfile() bool plAutoProfileImp::INextAge() { - const char* ageName = nullptr; + ST::string ageName; - if (fAgeName.length() > 0) - { + if (!fAgeName.empty()) { if (fLinkedToSingleAge) return false; fLinkedToSingleAge = true; - ageName = fAgeName.c_str(); - } - else - { + ageName = fAgeName; + } else { if (fNextAge >= fAges.size()) return false; - ageName = fAges[fNextAge].c_str(); + ageName = fAges[fNextAge]; } fNextAge++; diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h index fa5f6e4a73..583ba4a479 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnKeyedObject/hsKeyedObject.h" +namespace ST { class string; } + class plAutoProfile : public hsKeyedObject { public: @@ -53,7 +55,7 @@ class plAutoProfile : public hsKeyedObject static plAutoProfile* Instance(); // If ageName is nil, do all ages - virtual void StartProfile(const char* ageName = nullptr) = 0; + virtual void StartProfile(ST::string ageName = {}) = 0; // For when we just want to link to each age, for other reasons (profiling load times) virtual void LinkToAllAges()=0; diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp index 4862cac597..fba2bfc78b 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp @@ -53,7 +53,7 @@ plProfile_CreateMemCounter("Allocated", "Memory", MemAllocated); plProfile_CreateMemCounter("Peak Alloc", "Memory", MemPeakAlloc); #endif -static plProfileVar gVarRFPS("RFPS", "General", plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); +static plProfileVar gVarRFPS(ST_LITERAL("RFPS"), ST_LITERAL("General"), plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); plProfile_Extern(DrawTriangles); plProfile_Extern(MatChange); @@ -99,10 +99,9 @@ static bool ICreateStdPlate(plGraphPlate** graph) return false; } -void CreateStandardGraphs(const char* groupName, bool create) +void CreateStandardGraphs(const ST::string& groupName, bool create) { - if (strcmp(groupName, "General") == 0) - { + if (groupName == "General") { if (create) { if (ICreateStdPlate(&fFPSPlate)) diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h index dc843c1fb0..1b058112af 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h @@ -40,6 +40,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ +namespace ST { class string; } + void CalculateProfiles(); -void CreateStandardGraphs(const char* groupName, bool create); +void CreateStandardGraphs(const ST::string& groupName, bool create); void UpdateStandardGraphs(float xPos, float yPos); diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 0a6cc0d280..357563c33c 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -73,11 +73,8 @@ void plProfileManagerFull::GetGroups(GroupSet& groups) groups.insert(fVars[i]->GetGroup()); } -void plProfileManagerFull::ShowGroup(const char* groupName) +void plProfileManagerFull::ShowGroup(const ST::string& groupName) { - if (!groupName) - groupName = "General"; - // If we're already showing this group, stop if (fShowGroups.find(groupName) != fShowGroups.end()) { @@ -87,10 +84,10 @@ void plProfileManagerFull::ShowGroup(const char* groupName) } else { - const char* shareGroupName = nullptr; + ST::string shareGroupName; for (int i = 0; i < fVars.size(); i++) { - if (stricmp(fVars[i]->GetGroup(), groupName) == 0) + if (fVars[i]->GetGroup().compare_i(groupName) == 0) { shareGroupName = fVars[i]->GetGroup(); } @@ -98,7 +95,7 @@ void plProfileManagerFull::ShowGroup(const char* groupName) // We do have a group with this name, so insert one of the variable's // pointers to the name into our list (we can hang on to those pointers) - if (shareGroupName) + if (!shareGroupName.empty()) { ISetActive(shareGroupName, true); CreateStandardGraphs(shareGroupName, true); @@ -119,7 +116,7 @@ void plProfileManagerFull::ShowNextGroup() ST::string nextGroup; if (!curGroup.empty()) { - CreateStandardGraphs(curGroup.c_str(), false); + CreateStandardGraphs(curGroup, false); GroupSet::iterator it = groups.find(curGroup); it++; @@ -127,7 +124,7 @@ void plProfileManagerFull::ShowNextGroup() { nextGroup = *it; } - ISetActive(curGroup.c_str(), false); + ISetActive(curGroup, false); } else { @@ -137,8 +134,8 @@ void plProfileManagerFull::ShowNextGroup() fShowGroups.clear(); if (!nextGroup.empty()) { - ISetActive(nextGroup.c_str(), true); - CreateStandardGraphs(nextGroup.c_str(), true); + ISetActive(nextGroup, true); + CreateStandardGraphs(nextGroup, true); fShowGroups.insert(nextGroup); } } @@ -198,7 +195,6 @@ static void PrintColumn(ProfileGroup& group, const ST::string& groupName, int co for (int i = 0; i < group.size(); i++) { - char buf[1024]; ST::string str; switch (column) @@ -220,16 +216,13 @@ static void PrintColumn(ProfileGroup& group, const ST::string& groupName, int co } break; case kColValue: - group[i]->PrintValue(buf); - str = buf; + str = group[i]->PrintValue(); break; case kColAvg: - group[i]->PrintAvg(buf); - str = buf; + str = group[i]->PrintAvg(); break; case kColMax: - group[i]->PrintMax(buf); - str = buf; + str = group[i]->PrintMax(); break; case kColIndex: str = ST::format("[{3d}]", i + off); @@ -304,16 +297,14 @@ void plProfileManagerFull::Update() int maxX = 0; int y = 10; - GroupSet::iterator it; - for (it = fShowGroups.begin(); it != fShowGroups.end(); it++) - { - ST::string groupName = *it; - + for (const ST::string& groupName : fShowGroups) { std::vector group; - for (int i = 0; i < fVars.size(); i++) - if (groupName.compare(fVars[i]->GetGroup()) == 0) + for (int i = 0; i < fVars.size(); i++) { + if (groupName == fVars[i]->GetGroup()) { group.push_back(fVars[i]); + } + } int x = 10; PrintGroup(group, groupName, x, y); @@ -398,21 +389,19 @@ void plProfileManagerFull::ActivateAllStats() } } -void plProfileManagerFull::IPrintGroup(hsStream* s, const char* groupName, bool printTitle) +void plProfileManagerFull::IPrintGroup(hsStream* s, const ST::string& groupName, bool printTitle) { - char buf[256]; - - for (int i = 0; i < fVars.size(); i++) - { + for (int i = 0; i < fVars.size(); i++) { plProfileVar* var = fVars[i]; - if (strcmp(var->GetGroup(), groupName) == 0) - { - if (printTitle) - sprintf(buf, "%s:%s", var->GetGroup(), var->GetName()); - else - var->PrintAvg(buf, false); + if (var->GetGroup() == groupName) { + ST::string str; + if (printTitle) { + str = ST::format("{}:{}", var->GetGroup(), var->GetName()); + } else { + str = var->PrintAvg(false); + } - s->Write(strlen(buf), buf); + s->WriteString(str); s->WriteByte((uint8_t)','); } } @@ -457,30 +446,22 @@ void plProfileManagerFull::ILogStats() GroupSet groups; GetGroups(groups); - GroupSet::iterator it; - if (!exists) { - static const char kSpawn[] = "Spawn"; - s.Write(strlen(kSpawn), kSpawn); - s.WriteByte((uint8_t)','); + s.WriteString(ST_LITERAL("Spawn,")); - for (it = groups.begin(); it != groups.end(); it++) - { - ST::string groupName = *it; - IPrintGroup(&s, groupName.c_str(), true); + for (const ST::string& groupName : groups) { + IPrintGroup(&s, groupName, true); } s.WriteByte((uint8_t)'\r'); s.WriteByte((uint8_t)'\n'); } - s.Write(fLogSpawnName.size(), fLogSpawnName.c_str()); + s.WriteString(fLogSpawnName); s.WriteByte((uint8_t)','); - for (it = groups.begin(); it != groups.end(); it++) - { - ST::string groupName = *it; - IPrintGroup(&s, groupName.c_str()); + for (const ST::string& groupName : groups) { + IPrintGroup(&s, groupName); } s.WriteByte((uint8_t)'\r'); s.WriteByte((uint8_t)'\n'); @@ -492,7 +473,7 @@ void plProfileManagerFull::ILogStats() } -void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) +void plProfileManagerFull::ShowLaps(const ST::string& groupName, const ST::string& varName) { plProfileVar* var = nullptr; @@ -502,11 +483,9 @@ void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) for (int i = 0; i < fVars.size(); i++) { - int j = 0; - while(fVars[i]->GetName()[j++] == ' ') {} - if (stricmp(&(fVars[i]->GetName()[j-1]), varName) == 0 && - stricmp(fVars[i]->GetGroup(), groupName) == 0) - { + if (fVars[i]->GetName().trim_left(" ").compare_i(varName) == 0 && + fVars[i]->GetGroup().compare_i(groupName) == 0 + ) { var = fVars[i]; break; } @@ -528,7 +507,7 @@ void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) fShowLaps->SetLapsActive(true); } -void plProfileManagerFull::CreateGraph(const char* varName, uint32_t min, uint32_t max) +void plProfileManagerFull::CreateGraph(const ST::string& varName, uint32_t min, uint32_t max) { // If the graph is already created, destroy it for (int i = 0; i < fGraphs.size(); i++) @@ -556,16 +535,16 @@ void plProfileManagerFull::CreateGraph(const char* varName, uint32_t min, uint32 void plProfileManagerFull::ResetDefaultDetailVars() { fDetailVars.clear(); - AddDetailVar("ApplyAnimation",0,50); - AddDetailVar("AnimatingPhysicals",0,50); - AddDetailVar("StoppedAnimPhysicals",0,50); - AddDetailVar("DrawableTime",0,50); - AddDetailVar("Polys",0,150000); - AddDetailVar("Step",0,50); - AddDetailVar("LineOfSight",0,50); - AddDetailVar(" PhysicsUpdates",0,50); - AddDetailVar("Stream Shove Time",0,50); - AddDetailVar("RenderSetup",0,50); + AddDetailVar(ST_LITERAL("ApplyAnimation"), 0, 50); + AddDetailVar(ST_LITERAL("AnimatingPhysicals"), 0, 50); + AddDetailVar(ST_LITERAL("StoppedAnimPhysicals"), 0, 50); + AddDetailVar(ST_LITERAL("DrawableTime"), 0, 50); + AddDetailVar(ST_LITERAL("Polys"), 0, 150000); + AddDetailVar(ST_LITERAL("Step"), 0, 50); + AddDetailVar(ST_LITERAL("LineOfSight"), 0, 50); + AddDetailVar(ST_LITERAL(" PhysicsUpdates"), 0, 50); + AddDetailVar(ST_LITERAL("Stream Shove Time"), 0, 50); + AddDetailVar(ST_LITERAL("RenderSetup"), 0, 50); } void plProfileManagerFull::ShowDetailGraph() @@ -593,13 +572,14 @@ void plProfileManagerFull::HideDetailGraph() } } -void plProfileManagerFull::AddDetailVar(const char* varName, uint32_t min, uint32_t max) +void plProfileManagerFull::AddDetailVar(const ST::string& varName, uint32_t min, uint32_t max) { int i=0; for (i=0; iGetName(), varName) == 0) + if (fDetailVars[i].var->GetName().compare_i(varName) == 0) { return; // don't add it again + } } plProfileVar* var = IFindTimer(varName); @@ -617,12 +597,12 @@ void plProfileManagerFull::AddDetailVar(const char* varName, uint32_t min, uint3 UpdateDetailLabels(); } -void plProfileManagerFull::RemoveDetailVar(const char* varName) +void plProfileManagerFull::RemoveDetailVar(const ST::string& varName) { int i=0; for (i=0; iGetName(), varName) == 0) + if (fDetailVars[i].var->GetName().compare_i(varName) == 0) { fDetailVars.erase(fDetailVars.begin()+i); } @@ -664,12 +644,11 @@ void plProfileManagerFull::ResetMax() fVars[i]->ResetMax(); } -void plProfileManagerFull::ISetActive(const char* groupName, bool active) +void plProfileManagerFull::ISetActive(const ST::string& groupName, bool active) { for (int i = 0; i < fVars.size(); i++) { - if (stricmp(fVars[i]->GetGroup(), groupName) == 0) - { + if (fVars[i]->GetGroup().compare_i(groupName) == 0) { fVars[i]->SetActive(active); } } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h index 1f8bf0dc68..025e01c000 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h @@ -83,12 +83,12 @@ class plProfileManagerFull plProfileVar* fShowLaps; uint32_t fMinLap; // For Display - void IPrintGroup(hsStream* s, const char* groupName, bool printTitle=false); + void IPrintGroup(hsStream* s, const ST::string& groupName, bool printTitle = false); void ILogStats(); plProfileVar* IFindTimer(const ST::string& name); - void ISetActive(const char* groupName, bool active); + void ISetActive(const ST::string& groupName, bool active); plProfileManagerFull(); @@ -99,24 +99,24 @@ class plProfileManagerFull void Update(); void GetGroups(GroupSet& groups); - void ShowGroup(const char* groupName); + void ShowGroup(const ST::string& groupName); void ShowNextGroup(); - struct LapPair { const char* group; const char* varName; }; + struct LapPair { ST::string group; ST::string varName; }; typedef std::vector LapNames; void GetLaps(LapNames& lapNames); - void ShowLaps(const char* groupName, const char* varName); + void ShowLaps(const ST::string& groupName, const ST::string& varName); void SetMinLap(int m) { fMinLap = m; }; void PageDownLaps() { fMinLap += 40; } void PageUpLaps() { fMinLap = (fMinLap < 40) ? 0 : fMinLap - 40;} - void CreateGraph(const char* varName, uint32_t min, uint32_t max); + void CreateGraph(const ST::string& varName, uint32_t min, uint32_t max); void ResetDefaultDetailVars(); void ShowDetailGraph(); void HideDetailGraph(); - void AddDetailVar(const char* varName, uint32_t min, uint32_t max); - void RemoveDetailVar(const char* varName); + void AddDetailVar(const ST::string& varName, uint32_t min, uint32_t max); + void RemoveDetailVar(const ST::string& varName); void UpdateDetailLabels(); void ResetMax(); diff --git a/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp b/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp index b22bfb3866..f27b7cbc48 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp +++ b/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp @@ -262,7 +262,7 @@ void hsGMaterial::Read(hsStream *stream, hsResMgr *group) void hsGMaterial::Eval(double secs, uint32_t frame) { - plProfile_BeginLap(MaterialAnims, GetKeyName().c_str()); + plProfile_BeginLap(MaterialAnims, GetKeyName()); for (size_t i = 0; i < GetNumLayers(); i++) { @@ -275,7 +275,7 @@ void hsGMaterial::Eval(double secs, uint32_t frame) fPiggyBacks[i]->Eval(secs, frame, 0); } - plProfile_EndLap(MaterialAnims, GetKeyName().c_str()); + plProfile_EndLap(MaterialAnims, GetKeyName()); } void hsGMaterial::Reset()