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 * Log results of the sessiond boot process.
105 * Uses all time_sessiond_* values (see measures.h)
107 void bench_print_boot_process(void)
110 double global_boot_time
= 0.0;
112 fprintf(fp
, "--- Session daemon boot process ---\n");
114 res
= get_bench_time(time_sessiond_boot_start
, time_sessiond_boot_end
);
116 fprintf(fp
, "Boot time inside main() from start to first pthread_join (blocking state)\n");
117 fprintf(fp
, "Time: %.20f sec.\n", res
);
119 global_boot_time
+= res
;
121 res
= get_bench_time(time_sessiond_th_kern_start
, time_sessiond_th_kern_poll
);
123 fprintf(fp
, "Boot time of the kernel thread from start to poll() (ready state)\n");
124 fprintf(fp
, "Time: %.20f sec.\n", res
);
126 global_boot_time
+= res
;
128 res
= get_bench_time(time_sessiond_th_apps_start
, time_sessiond_th_apps_poll
);
130 fprintf(fp
, "Boot time of the application thread from start to poll() (ready state)\n");
131 fprintf(fp
, "Time: %.20f sec.\n", res
);
133 global_boot_time
+= res
;
135 res
= get_bench_time(time_sessiond_th_cli_start
, time_sessiond_th_cli_poll
);
137 fprintf(fp
, "Boot time of the client thread from start to poll() (ready state)\n");
138 fprintf(fp
, "Time: %.20f sec.\n", res
);
140 global_boot_time
+= res
;
142 fprintf(fp
, "Global Boot Time of ltt-sessiond: %0.20f sec.\n", global_boot_time
);