-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2_scoped.c
More file actions
57 lines (44 loc) · 990 Bytes
/
example2_scoped.c
File metadata and controls
57 lines (44 loc) · 990 Bytes
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
/**
* Example 2: Scoped Timers
*
* Demonstrates automatic scoped timers that clean up automatically
*/
#include "profiler.h"
#include <unistd.h>
void simulate_work(int ms) {
usleep(ms * 1000);
}
void fast_function(void) {
PROFILER_FUNCTION();
simulate_work(5);
}
void slow_function(void) {
PROFILER_FUNCTION();
simulate_work(20);
}
void nested_scopes(void) {
PROFILER_FUNCTION();
{
PROFILER_SCOPE(inner_scope_1);
simulate_work(10);
}
{
PROFILER_SCOPE(inner_scope_2);
simulate_work(15);
}
}
int main(void) {
profiler_init();
printf("=== Example 2: Scoped Timers ===\n\n");
/* Function-level profiling */
fast_function();
slow_function();
/* Nested scopes */
nested_scopes();
/* Block profiling */
PROFILER_BLOCK_START(custom_block)
simulate_work(25);
PROFILER_BLOCK_END(custom_block)
profiler_shutdown();
return 0;
}