KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
perf_monitor.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 arch/dreamcast/include/dc/perf_monitor.h
4 * Copyright (C) 2024 Paul Cercueil
5
6*/
7
8/** \file dc/perf_monitor.h
9 \brief Low-level performance monitor
10 \ingroup perf_monitor
11
12 This file contains an API that can be used to monitor specific
13 performance events in one or several functional blocks.
14
15 \author Paul Cercueil
16*/
17
18#ifndef __KOS_PERF_MONITOR_H
19#define __KOS_PERF_MONITOR_H
20
21#include <sys/cdefs.h>
22__BEGIN_DECLS
23
24#include <dc/perfctr.h>
25#include <stdint.h>
26#include <stdio.h>
27
28/** \defgroup perf_monitor Performance monitor
29 \brief Code performance monitor
30 \ingroup debugging
31
32 The performance monitor API is built on top of the performance counter API,
33 and as such cannot be used at the same time.
34 With this API, programs can set probe points in different functional blocks
35 and later obtain statistics about the execution of said functional blocks.
36
37 @{
38*/
39
40/** /cond */
42 const char *fn;
43 unsigned int line;
44 uint64_t calls;
48};
49
50void __stop_perf_monitor(struct perf_monitor **monitor);
51
53
54#define __perf_monitor(f, l) \
55 static struct perf_monitor __perf_monitor_##l \
56 __attribute__((section(".monitors"))) = { f, l, }; \
57 struct perf_monitor *___perf_monitor_##l \
58 __attribute__((cleanup(__stop_perf_monitor))) = \
59 __start_perf_monitor(&__perf_monitor_##l)
60
61#define _perf_monitor(f, l) __perf_monitor(f, l)
62/** /endcond */
63
64/** \brief Register a performance monitor in the current functional block
65
66 The performance monitor will run from the moment this macro is used, till
67 the end of the functional block.
68*/
69#define perf_monitor() _perf_monitor(__func__, __LINE__)
70
71/** \brief Initialize the performance monitor system
72
73 Set up the performance monitor system. Note that using the performance
74 monitor system will conflict with any external usage of the performance
75 counter API.
76
77 \param event1 The first event mode (pef_cntr_event_t).
78 \param event2 The second event mode (pef_cntr_event_t).
79*/
81
82/** \brief De-initialize the performance monitor system
83
84 After this function is called, the performance counter API can be
85 used again.
86*/
88
89/** \brief Print statistics about the probe points to the given file descriptor
90 \param f A valid file descriptor to which the messages will
91 be printed. Use "stdout" for the standard output.
92*/
93void perf_monitor_print(FILE *f);
94
95__END_DECLS
96#endif /* __KOS_PERF_MONITOR_H */
perf_cntr_event_t
Performance Counter Event Modes.
Definition perfctr.h:90
const char * fn
Definition perf_monitor.h:42
uint64_t time_ns
Definition perf_monitor.h:45
uint64_t event0
Definition perf_monitor.h:46
void perf_monitor_print(FILE *f)
Print statistics about the probe points to the given file descriptor.
uint64_t calls
Definition perf_monitor.h:44
uint64_t time_start
Definition perf_monitor.h:45
unsigned int line
Definition perf_monitor.h:43
void perf_monitor_exit(void)
De-initialize the performance monitor system.
uint64_t event1_start
Definition perf_monitor.h:47
struct perf_monitor * __start_perf_monitor(struct perf_monitor *monitor)
void __stop_perf_monitor(struct perf_monitor **monitor)
void perf_monitor_init(perf_cntr_event_t event1, perf_cntr_event_t event2)
Initialize the performance monitor system.
uint64_t event1
Definition perf_monitor.h:47
uint64_t event0_start
Definition perf_monitor.h:46
Low-level performance counter API.
Basic sys/stdio.h file from newlib.
/cond
Definition perf_monitor.h:41