-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathperf_counters.c
More file actions
67 lines (62 loc) · 1.57 KB
/
perf_counters.c
File metadata and controls
67 lines (62 loc) · 1.57 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
/*
* perf_counters.c - registry + dump for opt-in instrumentation counters.
*
* The register/dump/reset functions are *always* defined so they can be
* exported through the test ABI without conditional linker scripts.
* In !BENCH_PROFILE builds the bodies are no-ops and no PERF_COUNTER
* calls perf_counters_register, so the registry stays empty.
*/
#include <string.h>
#include "perf_counters.h"
#ifdef BENCH_PROFILE
static perf_counter_entry_t *perf_head = (perf_counter_entry_t *)0;
#endif
void perf_counters_register(perf_counter_entry_t *entry)
{
#ifdef BENCH_PROFILE
if (!entry || entry->next)
return; /* already linked */
entry->next = perf_head;
perf_head = entry;
#else
(void)entry;
#endif
}
void perf_counters_reset(void)
{
#ifdef BENCH_PROFILE
perf_counter_entry_t *e;
for (e = perf_head; e; e = e->next)
*e->value = 0;
#endif
}
void perf_counters_dump(FILE *out)
{
#ifdef BENCH_PROFILE
perf_counter_entry_t *e;
if (!out)
out = stderr;
if (!perf_head) {
fprintf(out, "[perf] no counters registered\n");
return;
}
fprintf(out, "[perf] counter dump:\n");
for (e = perf_head; e; e = e->next)
fprintf(out, "[perf] %-40s %llu\n", e->name, *e->value);
#else
(void)out;
#endif
}
unsigned long long *perf_counters_find(const char *name)
{
#ifdef BENCH_PROFILE
perf_counter_entry_t *e;
if (!name) return (unsigned long long *)0;
for (e = perf_head; e; e = e->next)
if (e->name && strcmp(e->name, name) == 0)
return e->value;
#else
(void)name;
#endif
return (unsigned long long *)0;
}