blob: 1ddd728d7975edc1f4da8f51b1377ba217be4e65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|