b8f8516ef9447d64fbd6b6086884201272944f3e
[lttng-tools.git] / benchmark / benchmark.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <sys/time.h>
22 #include <unistd.h>
23
24 #include "benchmark.h"
25
26 FILE *fp;
27 static double g_freq;
28
29 static double calibrate_cpu_freq(void)
30 {
31 int i, nb_calib = 10;
32 double freq;
33
34 printf("CPU frequency calibration, this should take 10 seconds\n");
35
36 /* CPU Frequency calibration */
37 for (i = 0; i < nb_calib; i++) {
38 freq += (double) get_cpu_freq();
39 }
40
41 return (freq / (double)nb_calib);
42 }
43
44 static void close_logs(void)
45 {
46 fclose(fp);
47 }
48
49 static void open_logs(void)
50 {
51 fp = fopen(RESULTS_FILE_NAME, "a");
52 if (fp == NULL) {
53 perror("fopen benchmark");
54 }
55 }
56
57 static double get_bench_time(cycles_t before, cycles_t after)
58 {
59 double ret;
60
61 ret = (((double)(after - before) / (g_freq / 1000.0)) / 1000000000.0);
62
63 return ret;
64 }
65
66 void bench_init(void)
67 {
68 open_logs();
69 if (g_freq == 0) {
70 g_freq = calibrate_cpu_freq();
71 //fprintf(fp, "CPU frequency %f Ghz\n\n", g_freq);
72 }
73 }
74
75 void bench_close(void)
76 {
77 close_logs();
78 printf("Benchmark results in %s\n", RESULTS_FILE_NAME);
79 }
80
81 double bench_get_create_session(void)
82 {
83 if ((time_create_session_start == 0) &&
84 (time_create_session_end == 0)) {
85 fprintf(fp, "NO DATA\n");
86 return 0;
87 }
88
89 return get_bench_time(time_create_session_start, time_create_session_end);
90 }
91
92 double bench_get_destroy_session(void)
93 {
94 if ((time_destroy_session_start == 0) &&
95 (time_destroy_session_end == 0)) {
96 fprintf(fp, "NO DATA\n");
97 return 0;
98 }
99
100 return get_bench_time(time_destroy_session_start, time_destroy_session_end);
101 }
102
103 /*
104 * Complete UST notification process time break down in different actions.
105 */
106 void bench_print_ust_notification(void)
107 {
108 double res, total = 0;
109
110 fprintf(fp, "--- UST notification time ---\n");
111
112 if (time_ust_notify_mmap_start == 0 || time_ust_notify_mmap_stop == 0) {
113 goto no_data;
114 }
115
116 res = get_bench_time(time_ust_notify_mmap_start,
117 time_ust_notify_mmap_stop);
118 fprintf(fp, "mmap() call time\n");
119 fprintf(fp, "Time: %.20f sec.\n", res);
120
121 total += res;
122
123 if (time_ust_notify_perms_start == 0 || time_ust_notify_perms_stop == 0) {
124 goto no_data;
125 }
126
127 res = get_bench_time(time_ust_notify_perms_start,
128 time_ust_notify_perms_stop);
129 fprintf(fp, "Setting permissions (chown/chmod)\n");
130 fprintf(fp, "Time: %.20f sec.\n", res);
131
132 total += res;
133
134 if (time_ust_notify_shm_start == 0 || time_ust_notify_shm_stop == 0) {
135 goto no_data;
136 }
137
138 res = get_bench_time(time_ust_notify_shm_start,
139 time_ust_notify_shm_stop);
140 fprintf(fp, "shm_open/ftruncate/fchmod\n");
141 fprintf(fp, "Time: %.20f sec.\n", res);
142
143 total += res;
144
145 if (time_ust_notify_apps_start == 0 || time_ust_notify_apps_stop == 0) {
146 goto no_data;
147 }
148
149 res = get_bench_time(time_ust_notify_apps_start,
150 time_ust_notify_apps_stop);
151 fprintf(fp, "futex wake\n");
152 fprintf(fp, "Time: %.20f sec.\n", res);
153
154 total += res;
155
156 fprintf(fp, "Global UST nonification time\n");
157 fprintf(fp, "Time: %.20f sec.\n", total);
158 return;
159
160 no_data:
161 fprintf(fp, "NO DATA\n");
162 return;
163 }
164
165 /*
166 * Time taken by an UST apps to unregister.
167 */
168 void bench_print_ust_unregister(void)
169 {
170 double res;
171
172 fprintf(fp, "--- UST unregister time ---\n");
173
174 if (time_ust_unregister_start == 0 || time_ust_unregister_stop == 0) {
175 goto no_data;
176 }
177
178 res = get_bench_time(time_ust_unregister_start, time_ust_unregister_stop);
179 fprintf(fp, "UST unregister time\n");
180 fprintf(fp, "Time: %.20f sec.\n", res);
181 return;
182
183 no_data:
184 fprintf(fp, "NO DATA\n");
185 return;
186 }
187
188 /*
189 * This time value is only coherent is an UST application registered.
190 */
191 void bench_print_ust_register(void)
192 {
193 double res, total = 0;
194
195 fprintf(fp, "--- UST registration time ---\n");
196
197 if (time_ust_register_start == 0 || time_ust_register_stop == 0) {
198 goto no_data;
199 }
200
201 res = get_bench_time(time_ust_register_start, time_ust_register_stop);
202 fprintf(fp, "UST registration received and send to dispatch time\n");
203 fprintf(fp, "Time: %.20f sec.\n", res);
204
205 total += res;
206
207 if (time_ust_dispatch_register_start == 0 ||
208 time_ust_dispatch_register_stop == 0) {
209 goto no_data;
210 }
211
212 res = get_bench_time(time_ust_dispatch_register_start,
213 time_ust_dispatch_register_stop);
214 fprintf(fp, "Dispatch UST registration request time\n");
215 fprintf(fp, "Time: %.20f sec.\n", res);
216
217 total += res;
218
219 fprintf(fp, "--> Manage registration breakdown\n");
220
221 res = get_bench_time(time_ust_register_read_start,
222 time_ust_register_read_stop);
223 fprintf(fp, "read() from pipe time\n");
224 fprintf(fp, "Time: %.20f sec.\n", res);
225
226 total += res;
227
228 res = get_bench_time(time_ust_register_add_start,
229 time_ust_register_add_stop);
230 fprintf(fp, "register_traceable_app time\n");
231 fprintf(fp, "Time: %.20f sec.\n", res);
232
233 total += res;
234
235 res = get_bench_time(time_ust_register_done_start,
236 time_ust_register_done_stop);
237 fprintf(fp, "send register done command time\n");
238 fprintf(fp, "Time: %.20f sec.\n", res);
239
240 total += res;
241
242 fprintf(fp, "Global time of an UST application registration\n");
243 fprintf(fp, "Time: %.20f sec.\n", total);
244 return;
245
246 no_data:
247 fprintf(fp, "NO DATA\n");
248 return;
249 }
250
251
252 /*
253 * Log results of the sessiond boot process.
254 *
255 * Uses all time_sessiond_* values (see measures.h)
256 */
257 void bench_print_boot_process(void)
258 {
259 double res;
260 double global_boot_time = 0.0;
261
262 fprintf(fp, "--- Session daemon boot process ---\n");
263
264 res = get_bench_time(time_sessiond_boot_start, time_sessiond_boot_end);
265
266 fprintf(fp, "Inside main() from start to first pthread_join"
267 "(blocking state)\n");
268 fprintf(fp, "Time: %.20f sec.\n", res);
269
270 global_boot_time += res;
271
272 res = get_bench_time(time_sessiond_th_kern_start,
273 time_sessiond_th_kern_poll);
274
275 fprintf(fp, "Kernel thread from start to poll() (ready state)\n");
276 fprintf(fp, "Time: %.20f sec.\n", res);
277
278 global_boot_time += res;
279
280 res = get_bench_time(time_sessiond_th_apps_start,
281 time_sessiond_th_apps_poll);
282
283 fprintf(fp, "Application thread from start to poll() (ready state)\n");
284 fprintf(fp, "Time: %.20f sec.\n", res);
285
286 global_boot_time += res;
287
288 res = get_bench_time(time_sessiond_th_cli_start,
289 time_sessiond_th_cli_poll);
290
291 fprintf(fp, "Client thread from start to poll() (ready state)\n");
292 fprintf(fp, "Time: %.20f sec.\n", res);
293
294 global_boot_time += res;
295
296 res = get_bench_time(time_sessiond_th_dispatch_start,
297 time_sessiond_th_dispatch_block);
298
299 fprintf(fp, "Dispatch registration thread from start to poll()"
300 "(ready state)\n");
301 fprintf(fp, "Time: %.20f sec.\n", res);
302
303 global_boot_time += res;
304
305 fprintf(fp, "Global Boot Time\n");
306 fprintf(fp, "Time: %0.20f sec.\n", global_boot_time);
307 }
This page took 0.034868 seconds and 3 git commands to generate.