summaryrefslogtreecommitdiff
path: root/src/KingSystem/System/BasicProfiler.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-05-09 12:34:36 +0200
committerLéo Lam <leo@leolam.fr>2021-05-09 15:17:11 +0200
commit1fb3ae9368dcb1f540a20cce5a49089643f591f6 (patch)
tree865caf738a354e0582d95f565db59f401c736337 /src/KingSystem/System/BasicProfiler.cpp
parent7c30d3f6e5ceebddbe1a366231e36d680494f564 (diff)
ksys: Add BasicProfiler
Diffstat (limited to 'src/KingSystem/System/BasicProfiler.cpp')
-rw-r--r--src/KingSystem/System/BasicProfiler.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/KingSystem/System/BasicProfiler.cpp b/src/KingSystem/System/BasicProfiler.cpp
new file mode 100644
index 00000000..1ddd728d
--- /dev/null
+++ b/src/KingSystem/System/BasicProfiler.cpp
@@ -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