jak-project/common/global_profiler/GlobalProfiler.h
water111 73561f10a3
support c++ tools on macos (#2063)
Running reference tests/decompiler should now be possible on macos
(arm). Most of the changes were just cleaning up places where we were
sloppy with ifdefs, but there were two interesting ones:
- `Printer.cpp` was updated to not use a recursive function for printing
lists, to avoid stack overflow
- I replaced xxhash with another version of the same library that
supports arm (the one that comes in zstd). The interface is C instead of
C++ but it's not bad to use. I confirmed that the extractor succeeds on
jak 1 iso so it looks like this gives us the same results as the old
library.
2022-12-22 17:12:05 -05:00

48 lines
997 B
C++

#pragma once
#include <atomic>
#include <string>
#include <vector>
#include "common/common_types.h"
struct ProfNode {
u64 ts;
u64 tid;
char name[32];
enum Kind : u8 { BEGIN, END, INSTANT, UNUSED } kind = UNUSED;
};
class GlobalProfiler {
public:
GlobalProfiler();
void set_max_events(size_t event_count);
void instant_event(const char* name);
void begin_event(const char* name);
void event(const char* name, ProfNode::Kind kind);
void end_event();
void clear();
void set_enable(bool en);
void dump_to_json(const std::string& path);
private:
std::atomic_bool m_enabled = false;
u64 m_t0 = 0;
std::atomic_size_t m_next_idx = 0;
std::vector<ProfNode> m_nodes;
};
struct ScopedEvent {
ScopedEvent(const ScopedEvent&) = delete;
ScopedEvent& operator=(const ScopedEvent&) = delete;
GlobalProfiler* prof = nullptr;
~ScopedEvent() {
if (prof) {
prof->end_event();
}
}
};
GlobalProfiler& prof();
ScopedEvent scoped_prof(const char* name);