2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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
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.
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.
24 #include "benchmark.h"
29 static double calibrate_cpu_freq(void)
34 printf("CPU frequency calibration, this should take 10 seconds\n");
36 /* CPU Frequency calibration */
37 for (i
= 0; i
< nb_calib
; i
++) {
38 freq
+= (double) get_cpu_freq();
40 return (freq
/ (double)nb_calib
);
43 static void close_logs(void)
48 static void open_logs(void)
50 fp
= fopen(RESULTS_FILE_NAME
, "a");
52 perror("fopen benchmark");
56 static double get_bench_time(cycles_t before
, cycles_t after
)
60 ret
= (((double)(after
- before
) / (g_freq
/ 1000.0)) / 1000000000.0);
69 g_freq
= calibrate_cpu_freq();
70 //fprintf(fp, "CPU frequency %f Ghz\n\n", g_freq);
74 void bench_close(void)
77 printf("Benchmark results in %s\n", RESULTS_FILE_NAME
);
80 double bench_get_create_session(void)
82 if ((time_create_session_start
== 0) &&
83 (time_create_session_end
== 0)) {
84 fprintf(fp
, "NO DATA\n");
88 return get_bench_time(time_create_session_start
, time_create_session_end
);
91 double bench_get_destroy_session(void)
93 if ((time_destroy_session_start
== 0) &&
94 (time_destroy_session_end
== 0)) {
95 fprintf(fp
, "NO DATA\n");
99 return get_bench_time(time_destroy_session_start
, time_destroy_session_end
);
103 * Complete UST notification process time break down in different actions.
105 void bench_print_ust_notification(void)
107 double res
, total
= 0;
109 fprintf(fp
, "--- UST notification time ---\n");
111 if (time_ust_notify_mmap_start
== 0 || time_ust_notify_mmap_stop
== 0) {
115 res
= get_bench_time(time_ust_notify_mmap_start
,
116 time_ust_notify_mmap_stop
);
117 fprintf(fp
, "mmap() call time\n");
118 fprintf(fp
, "Time: %.20f sec.\n", res
);
122 if (time_ust_notify_perms_start
== 0 || time_ust_notify_perms_stop
== 0) {
126 res
= get_bench_time(time_ust_notify_perms_start
,
127 time_ust_notify_perms_stop
);
128 fprintf(fp
, "Setting permissions (chown/chmod)\n");
129 fprintf(fp
, "Time: %.20f sec.\n", res
);
133 if (time_ust_notify_shm_start
== 0 || time_ust_notify_shm_stop
== 0) {
137 res
= get_bench_time(time_ust_notify_shm_start
,
138 time_ust_notify_shm_stop
);
139 fprintf(fp
, "shm_open/ftruncate/fchmod\n");
140 fprintf(fp
, "Time: %.20f sec.\n", res
);
144 fprintf(fp
, "Global UST nonification time\n");
145 fprintf(fp
, "Time: %.20f sec.\n", total
);
149 fprintf(fp
, "NO DATA\n");
154 * This time value is only coherent is an UST application registered.
156 void bench_print_ust_register(void)
158 double res
, total
= 0;
160 fprintf(fp
, "--- UST registration time ---\n");
162 if (time_ust_register_start
== 0 || time_ust_register_stop
== 0) {
166 res
= get_bench_time(time_ust_register_start
, time_ust_register_stop
);
167 fprintf(fp
, "UST registration received and send to dispatch time\n");
168 fprintf(fp
, "Time: %.20f sec.\n", res
);
172 if (time_ust_dispatch_register_start
== 0 ||
173 time_ust_dispatch_register_stop
== 0) {
177 res
= get_bench_time(time_ust_dispatch_register_start
,
178 time_ust_dispatch_register_stop
);
179 fprintf(fp
, "Dispatch UST registration request time\n");
180 fprintf(fp
, "Time: %.20f sec.\n", res
);
184 fprintf(fp
, "--> Manage registration breakdown\n");
186 res
= get_bench_time(time_ust_register_read_start
,
187 time_ust_register_read_stop
);
188 fprintf(fp
, "read() from pipe time\n");
189 fprintf(fp
, "Time: %.20f sec.\n", res
);
193 res
= get_bench_time(time_ust_register_add_start
,
194 time_ust_register_add_stop
);
195 fprintf(fp
, "register_traceable_app time\n");
196 fprintf(fp
, "Time: %.20f sec.\n", res
);
200 res
= get_bench_time(time_ust_register_done_start
,
201 time_ust_register_done_stop
);
202 fprintf(fp
, "send register done command time\n");
203 fprintf(fp
, "Time: %.20f sec.\n", res
);
207 fprintf(fp
, "Global time of an UST application registration\n");
208 fprintf(fp
, "Time: %.20f sec.\n", total
);
212 fprintf(fp
, "NO DATA\n");
218 * Log results of the sessiond boot process.
220 * Uses all time_sessiond_* values (see measures.h)
222 void bench_print_boot_process(void)
225 double global_boot_time
= 0.0;
227 fprintf(fp
, "--- Session daemon boot process ---\n");
229 res
= get_bench_time(time_sessiond_boot_start
, time_sessiond_boot_end
);
231 fprintf(fp
, "Inside main() from start to first pthread_join"
232 "(blocking state)\n");
233 fprintf(fp
, "Time: %.20f sec.\n", res
);
235 global_boot_time
+= res
;
237 res
= get_bench_time(time_sessiond_th_kern_start
,
238 time_sessiond_th_kern_poll
);
240 fprintf(fp
, "Kernel thread from start to poll() (ready state)\n");
241 fprintf(fp
, "Time: %.20f sec.\n", res
);
243 global_boot_time
+= res
;
245 res
= get_bench_time(time_sessiond_th_apps_start
,
246 time_sessiond_th_apps_poll
);
248 fprintf(fp
, "Application thread from start to poll() (ready state)\n");
249 fprintf(fp
, "Time: %.20f sec.\n", res
);
251 global_boot_time
+= res
;
253 res
= get_bench_time(time_sessiond_th_cli_start
,
254 time_sessiond_th_cli_poll
);
256 fprintf(fp
, "Client thread from start to poll() (ready state)\n");
257 fprintf(fp
, "Time: %.20f sec.\n", res
);
259 global_boot_time
+= res
;
261 res
= get_bench_time(time_sessiond_th_dispatch_start
,
262 time_sessiond_th_dispatch_block
);
264 fprintf(fp
, "Dispatch registration thread from start to poll()"
266 fprintf(fp
, "Time: %.20f sec.\n", res
);
268 global_boot_time
+= res
;
270 fprintf(fp
, "Global Boot Time\n");
271 fprintf(fp
, "Time: %0.20f sec.\n", global_boot_time
);