-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimple.c
145 lines (116 loc) · 4.24 KB
/
simple.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <uprof.h>
#include <stdio.h>
#define UPROF_DEBUG 1
#ifdef UPROF_DEBUG
#define DBG_PRINTF(fmt, args...) \
do \
{ \
printf ("[%s] " fmt, __FILE__, ##args); \
} \
while (0)
#else
#define DBG_PRINTF(fmt, args...) do { } while (0)
#endif
UPROF_STATIC_TIMER (full_timer,
NULL, /* no parent */
"Full timer",
"A timer for the test delays in loop0",
0 /* no application private data */
);
UPROF_STATIC_COUNTER (loop0_counter,
"Loop0 counter",
"A Counter for the first loop",
0 /* no application private data */
);
UPROF_STATIC_TIMER (loop0_timer,
"Full timer", /* parent */
"Loop0 timer",
"A timer for the test delays in loop0",
0 /* no application private data */
);
UPROF_STATIC_TIMER (loop0_sub_timer,
"Loop0 timer", /* parent */
"Loop0 sub timer",
"An example sub timer for loop0",
0 /* no application private data */
);
UPROF_STATIC_COUNTER (loop1_counter,
"Loop1 counter",
"A Counter for the first loop",
0 /* no application private data */
);
UPROF_STATIC_TIMER (loop1_timer,
"Full timer", /* parent */
"Loop1 timer",
"A timer for the test delays in loop1",
0 /* no application private data */
);
UPROF_STATIC_TIMER (loop1_sub_timer,
"Loop1 timer", /* parent */
"Loop1 sub timer",
"An example sub timer for loop1",
0 /* no application private data */
);
int
main (int argc, char **argv)
{
UProfContext *context;
UProfReport *report;
int i;
uprof_init (&argc, &argv);
context = uprof_context_new ("Simple context");
DBG_PRINTF ("start full timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
UPROF_TIMER_START (context, full_timer);
for (i = 0; i < 2; i ++)
{
struct timespec delay;
UPROF_COUNTER_INC (context, loop0_counter);
DBG_PRINTF ("start simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
UPROF_TIMER_START (context, loop0_timer);
DBG_PRINTF (" <delay: 1/2 sec>\n");
delay.tv_sec = 0;
delay.tv_nsec = 1000000000/2;
nanosleep (&delay, NULL);
UPROF_TIMER_START (context, loop0_sub_timer);
DBG_PRINTF (" <timing sub delay: 1/4 sec>\n");
delay.tv_sec = 0;
delay.tv_nsec = 1000000000/4;
nanosleep (&delay, NULL);
UPROF_TIMER_STOP (context, loop0_sub_timer);
UPROF_TIMER_STOP (context, loop0_timer);
DBG_PRINTF ("stop simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
}
for (i = 0; i < 4; i ++)
{
struct timespec delay;
UPROF_COUNTER_INC (context, loop1_counter);
DBG_PRINTF ("start simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
UPROF_TIMER_START (context, loop1_timer);
DBG_PRINTF (" <delay: 1/4 sec>\n");
delay.tv_sec = 0;
delay.tv_nsec = 1000000000/4;
nanosleep (&delay, NULL);
UPROF_TIMER_START (context, loop1_sub_timer);
DBG_PRINTF (" <timing sub delay: 1/2 sec>\n");
delay.tv_sec = 0;
delay.tv_nsec = 1000000000/2;
nanosleep (&delay, NULL);
UPROF_TIMER_STOP (context, loop1_sub_timer);
UPROF_TIMER_STOP (context, loop1_timer);
DBG_PRINTF ("stop simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
}
DBG_PRINTF ("stop full timer (rdtsc = %" G_GUINT64_FORMAT ")\n",
uprof_get_system_counter ());
UPROF_TIMER_STOP (context, full_timer);
report = uprof_report_new ("Simple report");
uprof_report_add_context (report, context);
uprof_report_print (report);
uprof_report_unref (report);
uprof_context_unref (context);
return 0;
}