ksys: Add BasicProfiler

This commit is contained in:
Léo Lam 2021-05-09 12:34:36 +02:00
parent 7c30d3f6e5
commit 1fb3ae9368
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 82 additions and 3 deletions

View File

@ -88720,9 +88720,9 @@
0x00000071010ba1b0,sub_71010BA1B0,56,_ZN4ksys12CameraEditor18SingletonDisposer_D1Ev
0x00000071010ba1e8,sub_71010BA1E8,92,_ZN4ksys12CameraEditor18SingletonDisposer_D0Ev
0x00000071010ba244,CameraEditor::createInstance,120,_ZN4ksys12CameraEditor14createInstanceEPN4sead4HeapE
0x00000071010ba2bc,Profiler::Push,136,
0x00000071010ba344,Profiler::Pop,596,
0x00000071010ba598,sub_71010BA598,176,
0x00000071010ba2bc,Profiler::Push,136,_ZN4ksys13BasicProfiler4pushEPKc
0x00000071010ba344,Profiler::Pop,596,_ZN4ksys13BasicProfiler3popEPKc
0x00000071010ba598,sub_71010BA598,176,_GLOBAL__sub_I_BasicProfiler.cpp?
0x00000071010ba648,sub_71010BA648,212,
0x00000071010ba71c,sub_71010BA71C,100,
0x00000071010ba780,sub_71010BA780,108,

Can't render this file because it is too large.

View File

@ -0,0 +1,55 @@
#include "KingSystem/System/BasicProfiler.h"
#include <container/seadObjList.h>
#include <devenv/seadEnvUtil.h>
#include <prim/seadSafeString.h>
#include <prim/seadStorageFor.h>
#include <thread/seadAtomic.h>
#include <time/seadTickTime.h>
#include "KingSystem/Utils/Debug.h"
namespace ksys {
struct ProfilerRecord {
ProfilerRecord() { enter_time.construct(); }
sead::StorageFor<sead::TickTime, true> enter_time{};
const char* description{};
};
struct ProfilerInitInfo {
ProfilerInitInfo() { time.setNow(); }
sead::TickTime time;
};
ProfilerInitInfo sProfilerInitInfo;
sead::Atomic<bool> sProfilerUnusedBool = true;
sead::FixedObjList<ProfilerRecord, 10> sProfilerRecords;
void BasicProfiler::push(const char* description) {
auto* record = sProfilerRecords.emplaceBack();
record->enter_time->setNow();
record->description = description;
}
void BasicProfiler::pop(const char* description) {
if (sProfilerRecords.isEmpty())
return;
auto* record = sProfilerRecords.back();
if (!record)
return;
if (sead::SafeString(description) != record->description)
return;
if (sProfilerRecords.size() == 1 && sead::EnvUtil::getRomType() != "Show_2017_1st" &&
sead::EnvUtil::getRomType() != "RID_Demo") {
util::PrintDebug(sead::FormatFixedSafeString<64>(
"%s:%.3f秒", record->description,
record->enter_time->diffToNow().toMilliSeconds() / 1000.0f));
}
sProfilerRecords.erase(record);
}
} // namespace ksys

View File

@ -0,0 +1,22 @@
#pragma once
namespace ksys {
class BasicProfiler {
public:
class Scope {
public:
explicit Scope(const char* description) : mDescription(description) { push(description); }
~Scope() { pop(mDescription); }
Scope(const Scope&) = delete;
auto operator=(const Scope&) = delete;
private:
const char* mDescription;
};
static void push(const char* description);
static void pop(const char* description);
};
} // namespace ksys

View File

@ -1,6 +1,8 @@
target_sources(uking PRIVATE
Account.cpp
Account.h
BasicProfiler.cpp
BasicProfiler.h
CameraEditor.cpp
CameraEditor.h
DebugMessage.h