Commit | Line | Data |
---|---|---|
b25a8868 DG |
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 | ||
3c6bae61 DG |
26 | FILE *fp; |
27 | static double g_freq; | |
b25a8868 | 28 | |
3c6bae61 | 29 | static double calibrate_cpu_freq(void) |
b25a8868 | 30 | { |
b25a8868 | 31 | int i, nb_calib = 10; |
3c6bae61 DG |
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 | return (freq / (double)nb_calib); | |
41 | } | |
42 | ||
43 | static void close_logs(void) | |
44 | { | |
45 | fclose(fp); | |
46 | } | |
b25a8868 | 47 | |
3c6bae61 DG |
48 | static void open_logs(void) |
49 | { | |
50 | fp = fopen(RESULTS_FILE_NAME, "a"); | |
b25a8868 DG |
51 | if (fp == NULL) { |
52 | perror("fopen benchmark"); | |
b25a8868 | 53 | } |
3c6bae61 | 54 | } |
b25a8868 | 55 | |
3c6bae61 DG |
56 | static double get_bench_time(cycles_t before, cycles_t after) |
57 | { | |
58 | double ret; | |
59 | ||
60 | ret = (((double)(after - before) / (g_freq / 1000.0)) / 1000000000.0); | |
61 | ||
62 | return ret; | |
63 | } | |
64 | ||
65 | void bench_init(void) | |
66 | { | |
67 | open_logs(); | |
68 | if (g_freq == 0) { | |
69 | g_freq = calibrate_cpu_freq(); | |
70 | //fprintf(fp, "CPU frequency %f Ghz\n\n", g_freq); | |
71 | } | |
72 | } | |
73 | ||
74 | void bench_close(void) | |
75 | { | |
76 | close_logs(); | |
77 | printf("Benchmark results in %s\n", RESULTS_FILE_NAME); | |
78 | } | |
79 | ||
80 | double bench_get_create_session(void) | |
81 | { | |
82 | if ((time_create_session_start == 0) && | |
83 | (time_create_session_end == 0)) { | |
84 | fprintf(fp, "NO DATA\n"); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | return get_bench_time(time_create_session_start, time_create_session_end); | |
89 | } | |
90 | ||
91 | double bench_get_destroy_session(void) | |
92 | { | |
93 | if ((time_destroy_session_start == 0) && | |
94 | (time_destroy_session_end == 0)) { | |
95 | fprintf(fp, "NO DATA\n"); | |
96 | return 0; | |
b25a8868 | 97 | } |
b25a8868 | 98 | |
3c6bae61 DG |
99 | return get_bench_time(time_destroy_session_start, time_destroy_session_end); |
100 | } | |
b25a8868 | 101 | |
62d53818 DG |
102 | /* |
103 | * Complete UST notification process time break down in different actions. | |
104 | */ | |
105 | void bench_print_ust_notification(void) | |
106 | { | |
107 | double res, total = 0; | |
108 | ||
109 | fprintf(fp, "--- UST notification time ---\n"); | |
110 | ||
111 | if (time_ust_notify_mmap_start == 0 || time_ust_notify_mmap_stop == 0) { | |
112 | goto no_data; | |
113 | } | |
114 | ||
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); | |
119 | ||
120 | total += res; | |
121 | ||
122 | if (time_ust_notify_perms_start == 0 || time_ust_notify_perms_stop == 0) { | |
123 | goto no_data; | |
124 | } | |
125 | ||
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); | |
130 | ||
131 | total += res; | |
132 | ||
133 | if (time_ust_notify_shm_start == 0 || time_ust_notify_shm_stop == 0) { | |
134 | goto no_data; | |
135 | } | |
136 | ||
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); | |
141 | ||
142 | total += res; | |
143 | ||
144 | fprintf(fp, "Global UST nonification time\n"); | |
145 | fprintf(fp, "Time: %.20f sec.\n", total); | |
146 | return; | |
147 | ||
148 | no_data: | |
149 | fprintf(fp, "NO DATA\n"); | |
150 | return; | |
151 | } | |
152 | ||
01e65450 DG |
153 | /* |
154 | * Time taken by an UST apps to unregister. | |
155 | */ | |
156 | void bench_print_ust_unregister(void) | |
157 | { | |
158 | double res; | |
159 | ||
160 | fprintf(fp, "--- UST unregister time ---\n"); | |
161 | ||
162 | if (time_ust_unregister_start == 0 || time_ust_unregister_stop == 0) { | |
163 | goto no_data; | |
164 | } | |
165 | ||
166 | res = get_bench_time(time_ust_unregister_start, time_ust_unregister_stop); | |
167 | fprintf(fp, "UST unregister time\n"); | |
168 | fprintf(fp, "Time: %.20f sec.\n", res); | |
169 | return; | |
170 | ||
171 | no_data: | |
172 | fprintf(fp, "NO DATA\n"); | |
173 | return; | |
174 | } | |
175 | ||
62d53818 DG |
176 | /* |
177 | * This time value is only coherent is an UST application registered. | |
178 | */ | |
179 | void bench_print_ust_register(void) | |
180 | { | |
181 | double res, total = 0; | |
182 | ||
183 | fprintf(fp, "--- UST registration time ---\n"); | |
184 | ||
185 | if (time_ust_register_start == 0 || time_ust_register_stop == 0) { | |
186 | goto no_data; | |
187 | } | |
188 | ||
189 | res = get_bench_time(time_ust_register_start, time_ust_register_stop); | |
190 | fprintf(fp, "UST registration received and send to dispatch time\n"); | |
191 | fprintf(fp, "Time: %.20f sec.\n", res); | |
192 | ||
193 | total += res; | |
194 | ||
195 | if (time_ust_dispatch_register_start == 0 || | |
196 | time_ust_dispatch_register_stop == 0) { | |
197 | goto no_data; | |
198 | } | |
199 | ||
200 | res = get_bench_time(time_ust_dispatch_register_start, | |
201 | time_ust_dispatch_register_stop); | |
202 | fprintf(fp, "Dispatch UST registration request time\n"); | |
203 | fprintf(fp, "Time: %.20f sec.\n", res); | |
204 | ||
205 | total += res; | |
206 | ||
85c434ee DG |
207 | fprintf(fp, "--> Manage registration breakdown\n"); |
208 | ||
209 | res = get_bench_time(time_ust_register_read_start, | |
210 | time_ust_register_read_stop); | |
211 | fprintf(fp, "read() from pipe time\n"); | |
212 | fprintf(fp, "Time: %.20f sec.\n", res); | |
62d53818 | 213 | |
85c434ee DG |
214 | total += res; |
215 | ||
216 | res = get_bench_time(time_ust_register_add_start, | |
217 | time_ust_register_add_stop); | |
218 | fprintf(fp, "register_traceable_app time\n"); | |
219 | fprintf(fp, "Time: %.20f sec.\n", res); | |
220 | ||
221 | total += res; | |
222 | ||
223 | res = get_bench_time(time_ust_register_done_start, | |
224 | time_ust_register_done_stop); | |
225 | fprintf(fp, "send register done command time\n"); | |
62d53818 DG |
226 | fprintf(fp, "Time: %.20f sec.\n", res); |
227 | ||
228 | total += res; | |
229 | ||
230 | fprintf(fp, "Global time of an UST application registration\n"); | |
231 | fprintf(fp, "Time: %.20f sec.\n", total); | |
232 | return; | |
233 | ||
234 | no_data: | |
235 | fprintf(fp, "NO DATA\n"); | |
236 | return; | |
237 | } | |
238 | ||
239 | ||
3c6bae61 DG |
240 | /* |
241 | * Log results of the sessiond boot process. | |
242 | * | |
243 | * Uses all time_sessiond_* values (see measures.h) | |
244 | */ | |
245 | void bench_print_boot_process(void) | |
246 | { | |
247 | double res; | |
248 | double global_boot_time = 0.0; | |
249 | ||
250 | fprintf(fp, "--- Session daemon boot process ---\n"); | |
b25a8868 | 251 | |
3c6bae61 | 252 | res = get_bench_time(time_sessiond_boot_start, time_sessiond_boot_end); |
b25a8868 | 253 | |
85c434ee DG |
254 | fprintf(fp, "Inside main() from start to first pthread_join" |
255 | "(blocking state)\n"); | |
256 | fprintf(fp, "Time: %.20f sec.\n", res); | |
257 | ||
258 | global_boot_time += res; | |
259 | ||
260 | res = get_bench_time(time_sessiond_th_kern_start, | |
261 | time_sessiond_th_kern_poll); | |
262 | ||
263 | fprintf(fp, "Kernel thread from start to poll() (ready state)\n"); | |
b25a8868 DG |
264 | fprintf(fp, "Time: %.20f sec.\n", res); |
265 | ||
266 | global_boot_time += res; | |
267 | ||
85c434ee DG |
268 | res = get_bench_time(time_sessiond_th_apps_start, |
269 | time_sessiond_th_apps_poll); | |
b25a8868 | 270 | |
85c434ee | 271 | fprintf(fp, "Application thread from start to poll() (ready state)\n"); |
b25a8868 DG |
272 | fprintf(fp, "Time: %.20f sec.\n", res); |
273 | ||
274 | global_boot_time += res; | |
275 | ||
85c434ee DG |
276 | res = get_bench_time(time_sessiond_th_cli_start, |
277 | time_sessiond_th_cli_poll); | |
b25a8868 | 278 | |
85c434ee | 279 | fprintf(fp, "Client thread from start to poll() (ready state)\n"); |
b25a8868 DG |
280 | fprintf(fp, "Time: %.20f sec.\n", res); |
281 | ||
282 | global_boot_time += res; | |
283 | ||
85c434ee DG |
284 | res = get_bench_time(time_sessiond_th_dispatch_start, |
285 | time_sessiond_th_dispatch_block); | |
b25a8868 | 286 | |
85c434ee DG |
287 | fprintf(fp, "Dispatch registration thread from start to poll()" |
288 | "(ready state)\n"); | |
b25a8868 DG |
289 | fprintf(fp, "Time: %.20f sec.\n", res); |
290 | ||
291 | global_boot_time += res; | |
292 | ||
85c434ee DG |
293 | fprintf(fp, "Global Boot Time\n"); |
294 | fprintf(fp, "Time: %0.20f sec.\n", global_boot_time); | |
b25a8868 | 295 | } |