91 template <
unsigned Capacity>
93 static_assert(Capacity && !(Capacity & (Capacity - 1)),
"Capacity must be a power of two");
107 template <
unsigned Capacity>
122 [[gnu::always_inline, gnu::no_instrument_function]]
static inline uint32_t
now() {
123 volatile uint16_t*
const counter1 =
reinterpret_cast<volatile uint16_t*
>(0xbf801110);
124 volatile uint16_t*
const counter2 =
reinterpret_cast<volatile uint16_t*
>(0xbf801120);
125 uint32_t
lines, cycles;
129 }
while (
lines != *counter1);
130 return (
lines << 16) | cycles;
136 static uint32_t
elapsed(uint32_t
start, uint32_t end) {
return pcsx_profElapsed(
start, end, s_cyclesPer16Lines); }
144 [[gnu::always_inline]]
explicit Scope(
const Zone& zone) : m_zone(&zone) {
145 if (s_header) begin();
161 uint8_t m_stackDepth;
162 uint32_t m_generation;
182 template <
typename F>
186 uint32_t generation = s_generation;
187 uint8_t depth = s_depth;
189 if (stackDepth > 255) stackDepth = 255;
191 for (
unsigned i = 0;
i <
count;
i++) {
196 uint32_t end =
now();
199 if (s_generation != generation)
break;
200 record(&zone,
start, end, vsync, depth, stackDepth);
202 cycles = cycles > s_nowCost ? cycles - s_nowCost : 0;
219 template <
typename F>
223 uint32_t
written = header->written;
224 uint32_t mask = header->capacity - 1;
226 auto entries =
reinterpret_cast<const pcsx_ProfEntry*
>(header->entries);
229 function(*
reinterpret_cast<const Zone*
>(entry.zone), entry.start,
elapsed(entry.start, entry.end),
230 entry.vsync, entry.depth, entry.stackDepth);
244 static void record(
const Zone* zone, uint32_t
start, uint32_t end, uint16_t vsync, uint8_t depth,
247 static uint32_t s_cyclesPer16Lines;
248 static uint32_t s_nowCost;
249 static uint8_t s_depth;
252 static uint32_t s_generation;
260#define PSYQO_PROFILE_CONCAT_(a, b) a##b
261#define PSYQO_PROFILE_CONCAT(a, b) PSYQO_PROFILE_CONCAT_(a, b)
267#define PSYQO_PROFILE_SCOPE(name) \
268 static constexpr psyqo::Profiler::Zone PSYQO_PROFILE_CONCAT(psyqoProfileZone_, __LINE__) = {name, __FILE__, \
270 psyqo::Profiler::Scope PSYQO_PROFILE_CONCAT(psyqoProfileScope_, __LINE__) { \
271 PSYQO_PROFILE_CONCAT(psyqoProfileZone_, __LINE__) \
int written
Definition cdda.c:321
uint32_t start
Definition cdlgetlocp.c:252
Times its own lifetime. Use PSYQO_PROFILE_SCOPE rather than declaring one directly.
Definition profiler.hh:142
~Scope()
Definition profiler.hh:147
Scope(const Scope &)=delete
Scope(const Zone &zone)
Definition profiler.hh:144
Scope & operator=(const Scope &)=delete
Scoped profiler: timed scopes recorded into a ring buffer.
Definition profiler.hh:76
static bool dumpPCDRV(const char *path)
Writes every entry still in the buffer to a host file through PCDRV, one line each,...
Definition profiler.cpp:199
static void forEach(F &&function)
Calls function(zone, start, cycles, vsync, depth, stackDepth) for every entry still in the buffer,...
Definition profiler.hh:220
static void uninstall()
Stops recording. Root counter 2 is left running.
Definition profiler.cpp:150
static bool installed()
Definition profiler.hh:117
static uint32_t now()
Reads a timestamp, as stored in the buffer.
Definition profiler.hh:122
static void install(Buffer< Capacity > &buffer)
Claims root counter 2 and starts recording into the buffer.
Definition profiler.hh:108
static uint32_t elapsed(uint32_t start, uint32_t end)
System clock cycles from timestamp start to timestamp end.
Definition profiler.hh:136
static BenchResult bench(const Zone &zone, unsigned count, F &&function)
Runs function count times, timing each run.
Definition profiler.hh:183
static constexpr unsigned depth()
Definition shadow-stack.hh:108
uint32_t psyqoFrameCounter
Definition gpu.hh:50
int i
Definition gte-regio.c:299
void * result
Definition memcpy.c:52
uint32_t psyqoFrameCounter
Definition profiler.hh:34
Definition profiler.hh:165
uint32_t total
Definition profiler.hh:169
uint32_t min
Definition profiler.hh:167
uint32_t mean() const
Definition profiler.hh:170
uint32_t count
Definition profiler.hh:166
uint32_t max
Definition profiler.hh:168
Storage for the ring buffer, with room for Capacity scopes.
Definition profiler.hh:92
pcsx_ProfHeader header
Definition profiler.hh:94
pcsx_ProfEntry entries[Capacity]
Definition profiler.hh:95
Static descriptor of one profiled scope. Its address is its identity.
Definition profiler.hh:82
uint32_t line
Definition profiler.hh:85
const char * file
Definition profiler.hh:84
const char * name
Definition profiler.hh:83
static void * buffer
Definition syscalls.h:274
static const void size_t count
Definition syscalls.h:196
int lines
Definition timers.c:412
uint32_t elapsed
Definition timers.c:592