Commit | Line | Data |
---|---|---|
5489fcc3 KR |
1 | /* |
2 | * Basic-block level related code: reading/writing of basic-block info | |
3 | * to/from gmon.out; computing and formatting of basic-block related | |
4 | * statistics. | |
5 | */ | |
6 | #include <stdio.h> | |
7 | #include <unistd.h> | |
8 | #include "basic_blocks.h" | |
9 | #include "core.h" | |
10 | #include "gmon_io.h" | |
11 | #include "gmon_out.h" | |
12 | #include "gprof.h" | |
13 | #include "libiberty.h" | |
14 | #include "source.h" | |
15 | #include "sym_ids.h" | |
16 | ||
17 | ||
18 | /* | |
19 | * Default option values: | |
20 | */ | |
21 | bool bb_annotate_all_lines = FALSE; | |
22 | int bb_min_calls = 1; | |
23 | int bb_table_length = 10; | |
24 | ||
25 | /* | |
26 | * Variables used to compute annotated source listing stats: | |
27 | */ | |
28 | static long num_executable_lines; | |
29 | static long num_lines_executed; | |
30 | ||
31 | ||
32 | /* | |
7862d7d0 | 33 | * Helper for sorting. Compares two symbols and returns result |
5489fcc3 | 34 | * such that sorting will be increasing according to filename, line |
7862d7d0 | 35 | * number, and address (in that order). |
5489fcc3 | 36 | */ |
7862d7d0 | 37 | |
5489fcc3 | 38 | static int |
12516a37 | 39 | DEFUN (cmp_bb, (lp, rp), const void *lp AND const void *rp) |
5489fcc3 | 40 | { |
12516a37 KR |
41 | int r; |
42 | const Sym *left = *(const Sym **) lp; | |
43 | const Sym *right = *(const Sym **) rp; | |
44 | ||
45 | if (left->file && right->file) | |
46 | { | |
47 | r = strcmp (left->file->name, right->file->name); | |
48 | if (r) | |
49 | { | |
50 | return r; | |
03c35bcb | 51 | } |
12516a37 KR |
52 | |
53 | if (left->line_num != right->line_num) | |
54 | { | |
55 | return left->line_num - right->line_num; | |
03c35bcb KR |
56 | } |
57 | } | |
12516a37 KR |
58 | |
59 | if (left->addr < right->addr) | |
60 | { | |
61 | return -1; | |
62 | } | |
63 | else if (left->addr > right->addr) | |
64 | { | |
65 | return 1; | |
66 | } | |
67 | else | |
68 | { | |
69 | return 0; | |
03c35bcb KR |
70 | } |
71 | } | |
5489fcc3 KR |
72 | |
73 | ||
74 | /* | |
75 | * Helper for sorting. Order basic blocks in decreasing number of | |
76 | * calls, ties are broken in increasing order of line numbers. | |
77 | */ | |
78 | static int | |
12516a37 | 79 | DEFUN (cmp_ncalls, (lp, rp), const void *lp AND const void *rp) |
5489fcc3 | 80 | { |
12516a37 KR |
81 | const Sym *left = *(const Sym **) lp; |
82 | const Sym *right = *(const Sym **) rp; | |
5489fcc3 | 83 | |
12516a37 KR |
84 | if (!left) |
85 | { | |
86 | return 1; | |
87 | } | |
88 | else if (!right) | |
89 | { | |
90 | return -1; | |
03c35bcb | 91 | } |
5489fcc3 | 92 | |
12516a37 KR |
93 | if (right->ncalls != left->ncalls) |
94 | { | |
95 | return right->ncalls - left->ncalls; | |
03c35bcb | 96 | } |
5489fcc3 | 97 | |
12516a37 | 98 | return left->line_num - right->line_num; |
03c35bcb | 99 | } |
5489fcc3 KR |
100 | |
101 | ||
102 | /* | |
103 | * Skip over variable length string. | |
104 | */ | |
105 | static void | |
12516a37 | 106 | DEFUN (fskip_string, (fp), FILE * fp) |
5489fcc3 | 107 | { |
12516a37 | 108 | int ch; |
5489fcc3 | 109 | |
12516a37 KR |
110 | while ((ch = fgetc (fp)) != EOF) |
111 | { | |
112 | if (ch == '\0') | |
113 | { | |
114 | break; | |
03c35bcb KR |
115 | } |
116 | } | |
117 | } | |
5489fcc3 KR |
118 | |
119 | ||
120 | /* | |
121 | * Read a basic-block record from file IFP. FILENAME is the name | |
122 | * of file IFP and is provided for formatting error-messages only. | |
123 | */ | |
124 | void | |
12516a37 | 125 | DEFUN (bb_read_rec, (ifp, filename), FILE * ifp AND const char *filename) |
5489fcc3 | 126 | { |
12516a37 KR |
127 | int nblocks, b; |
128 | bfd_vma addr; | |
129 | long ncalls; | |
130 | Sym *sym; | |
131 | ||
132 | if (fread (&nblocks, sizeof (nblocks), 1, ifp) != 1) | |
133 | { | |
134 | fprintf (stderr, "%s: %s: unexpected end of file\n", whoami, filename); | |
135 | done (1); | |
03c35bcb | 136 | } |
12516a37 KR |
137 | |
138 | nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks); | |
139 | if (gmon_file_version == 0) | |
140 | { | |
141 | fskip_string (ifp); | |
03c35bcb | 142 | } |
12516a37 KR |
143 | |
144 | for (b = 0; b < nblocks; ++b) | |
145 | { | |
146 | if (gmon_file_version == 0) | |
147 | { | |
148 | int line_num; | |
149 | /* | |
150 | * Version 0 had lots of extra stuff that we don't | |
151 | * care about anymore. | |
152 | */ | |
153 | if ((fread (&ncalls, sizeof (ncalls), 1, ifp) != 1) | |
154 | || (fread (&addr, sizeof (addr), 1, ifp) != 1) | |
155 | || (fskip_string (ifp), FALSE) | |
156 | || (fskip_string (ifp), FALSE) | |
157 | || (fread (&line_num, sizeof (line_num), 1, ifp) != 1)) | |
5489fcc3 | 158 | { |
12516a37 KR |
159 | perror (filename); |
160 | done (1); | |
03c35bcb | 161 | } |
12516a37 KR |
162 | } |
163 | else | |
164 | { | |
165 | if (fread (&addr, sizeof (addr), 1, ifp) != 1 | |
166 | || fread (&ncalls, sizeof (ncalls), 1, ifp) != 1) | |
5489fcc3 | 167 | { |
12516a37 KR |
168 | perror (filename); |
169 | done (1); | |
03c35bcb KR |
170 | } |
171 | } | |
12516a37 KR |
172 | |
173 | /* | |
174 | * Basic-block execution counts are meaningful only if we're | |
175 | * profiling at the line-by-line level: | |
176 | */ | |
177 | if (line_granularity) | |
178 | { | |
5489fcc3 | 179 | |
12516a37 | 180 | /* convert from target to host endianness: */ |
5489fcc3 | 181 | |
12516a37 | 182 | addr = get_vma (core_bfd, (bfd_byte *) & addr); |
7862d7d0 | 183 | ncalls = bfd_get_32 (core_bfd, (bfd_byte *) &ncalls); |
5489fcc3 | 184 | |
12516a37 | 185 | sym = sym_lookup (&symtab, addr); |
5489fcc3 | 186 | |
7862d7d0 ILT |
187 | if (sym) |
188 | { | |
189 | int i; | |
190 | ||
191 | DBG (BBDEBUG, | |
192 | printf ("[bb_read_rec] 0x%lx->0x%lx (%s:%d) cnt=%ld\n", | |
193 | addr, sym->addr, sym->name, sym->line_num, ncalls)); | |
194 | ||
195 | for (i = 0; i < NBBS; i++) | |
196 | { | |
197 | if (! sym->bb_addr[i] || sym->bb_addr[i] == addr) | |
198 | { | |
199 | sym->bb_addr[i] = addr; | |
200 | sym->bb_calls[i] += ncalls; | |
201 | break; | |
202 | } | |
203 | } | |
204 | } | |
12516a37 KR |
205 | } |
206 | else | |
207 | { | |
208 | static bool user_warned = FALSE; | |
5489fcc3 | 209 | |
12516a37 KR |
210 | if (!user_warned) |
211 | { | |
212 | user_warned = TRUE; | |
213 | fprintf (stderr, | |
214 | "%s: warning: ignoring basic-block exec counts (use -l or --line)\n", | |
215 | whoami); | |
03c35bcb KR |
216 | } |
217 | } | |
218 | } | |
12516a37 | 219 | return; |
03c35bcb | 220 | } |
5489fcc3 KR |
221 | |
222 | ||
223 | /* | |
224 | * Write all basic-blocks with non-zero counts to file OFP. FILENAME | |
225 | * is the name of OFP and is provided for producing error-messages | |
226 | * only. | |
227 | */ | |
228 | void | |
12516a37 | 229 | DEFUN (bb_write_blocks, (ofp, filename), FILE * ofp AND const char *filename) |
5489fcc3 | 230 | { |
12516a37 KR |
231 | const unsigned char tag = GMON_TAG_BB_COUNT; |
232 | int nblocks = 0; | |
233 | bfd_vma addr; | |
234 | long ncalls; | |
235 | Sym *sym; | |
7862d7d0 | 236 | int i; |
12516a37 KR |
237 | |
238 | /* count how many non-zero blocks with have: */ | |
239 | ||
240 | for (sym = symtab.base; sym < symtab.limit; ++sym) | |
5489fcc3 | 241 | { |
7862d7d0 ILT |
242 | for (i = 0; i < NBBS && sym->bb_addr[i]; i++) |
243 | ; | |
244 | nblocks += i; | |
03c35bcb | 245 | } |
12516a37 KR |
246 | |
247 | /* write header: */ | |
248 | bfd_put_32 (core_bfd, nblocks, (bfd_byte *) & nblocks); | |
249 | if (fwrite (&tag, sizeof (tag), 1, ofp) != 1 | |
250 | || fwrite (&nblocks, sizeof (nblocks), 1, ofp) != 1) | |
251 | { | |
252 | perror (filename); | |
253 | done (1); | |
03c35bcb | 254 | } |
5489fcc3 | 255 | |
12516a37 KR |
256 | /* write counts: */ |
257 | for (sym = symtab.base; sym < symtab.limit; ++sym) | |
258 | { | |
7862d7d0 | 259 | for (i = 0; i < NBBS && sym->bb_addr[i]; i++) |
12516a37 | 260 | { |
7862d7d0 ILT |
261 | put_vma (core_bfd, sym->bb_addr[i], (bfd_byte *) & addr); |
262 | bfd_put_32 (core_bfd, sym->bb_calls[i], (bfd_byte *) & ncalls); | |
5489fcc3 | 263 | |
7862d7d0 ILT |
264 | if (fwrite (&addr, sizeof (addr), 1, ofp) != 1 |
265 | || fwrite (&ncalls, sizeof (ncalls), 1, ofp) != 1) | |
266 | { | |
267 | perror (filename); | |
268 | done (1); | |
269 | } | |
03c35bcb KR |
270 | } |
271 | } | |
272 | } | |
5489fcc3 KR |
273 | |
274 | ||
275 | /* | |
276 | * Output basic-block statistics in a format that is easily parseable. | |
277 | * Current the format is: | |
278 | * | |
12516a37 | 279 | * <filename>:<line-number>: (<function-name>:<bb-addr): <ncalls> |
5489fcc3 KR |
280 | */ |
281 | void | |
12516a37 | 282 | DEFUN_VOID (print_exec_counts) |
5489fcc3 | 283 | { |
12516a37 | 284 | Sym **sorted_bbs, *sym; |
7862d7d0 | 285 | int i, j, len; |
12516a37 KR |
286 | |
287 | if (first_output) | |
288 | { | |
289 | first_output = FALSE; | |
290 | } | |
291 | else | |
292 | { | |
293 | printf ("\f\n"); | |
03c35bcb | 294 | } |
12516a37 KR |
295 | |
296 | /* sort basic-blocks according to function name and line number: */ | |
297 | ||
298 | sorted_bbs = (Sym **) xmalloc (symtab.len * sizeof (sorted_bbs[0])); | |
299 | len = 0; | |
300 | for (sym = symtab.base; sym < symtab.limit; ++sym) | |
301 | { | |
302 | /* | |
7862d7d0 ILT |
303 | * Accept symbol if it's in the INCL_EXEC table |
304 | * or there is no INCL_EXEC table | |
305 | * and it does not appear in the EXCL_EXEC table. | |
12516a37 | 306 | */ |
7862d7d0 ILT |
307 | if (sym_lookup (&syms[INCL_EXEC], sym->addr) |
308 | || (syms[INCL_EXEC].len == 0 | |
309 | && !sym_lookup (&syms[EXCL_EXEC], sym->addr))) | |
5489fcc3 | 310 | { |
12516a37 | 311 | sorted_bbs[len++] = sym; |
03c35bcb KR |
312 | } |
313 | } | |
12516a37 | 314 | qsort (sorted_bbs, len, sizeof (sorted_bbs[0]), cmp_bb); |
5489fcc3 | 315 | |
12516a37 | 316 | /* output basic-blocks: */ |
5489fcc3 | 317 | |
12516a37 KR |
318 | for (i = 0; i < len; ++i) |
319 | { | |
7862d7d0 ILT |
320 | if (sym->ncalls > 0 || ! ignore_zeros) |
321 | { | |
322 | printf ("%s:%d: (%s:0x%lx) %d executions\n", | |
323 | sym->file ? sym->file->name : "<unknown>", sym->line_num, | |
324 | sym->name, sym->addr, sym->ncalls); | |
325 | } | |
326 | for (j = 0; j < NBBS && sym->bb_addr[j]; j ++) | |
327 | { | |
328 | if (sym->bb_calls[j] > 0 || ! ignore_zeros) | |
329 | { | |
330 | printf ("%s:%d: (%s:0x%lx) %d executions\n", | |
331 | sym->file ? sym->file->name : "<unknown>", sym->line_num, | |
332 | sym->name, sym->bb_addr[j], sym->bb_calls[j]); | |
333 | } | |
334 | } | |
03c35bcb | 335 | } |
12516a37 | 336 | free (sorted_bbs); |
03c35bcb | 337 | } |
5489fcc3 | 338 | |
5489fcc3 KR |
339 | /* |
340 | * Helper for bb_annotated_source: format annotation containing | |
7862d7d0 ILT |
341 | * number of line executions. Depends on being called on each |
342 | * line of a file in sequential order. | |
343 | * | |
344 | * Global variable bb_annotate_all_lines enables execution count | |
345 | * compression (counts are supressed if identical to the last one) | |
346 | * and prints counts on all executed lines. Otherwise, print | |
347 | * all basic-block execution counts exactly once on the line | |
348 | * that starts the basic-block. | |
5489fcc3 | 349 | */ |
7862d7d0 | 350 | |
5489fcc3 | 351 | static void |
12516a37 KR |
352 | DEFUN (annotate_with_count, (buf, width, line_num, arg), |
353 | char *buf AND int width AND int line_num AND void *arg) | |
5489fcc3 | 354 | { |
12516a37 KR |
355 | Source_File *sf = arg; |
356 | Sym *b; | |
7862d7d0 ILT |
357 | int i; |
358 | static int last_count; | |
359 | int last_print=-1; | |
12516a37 | 360 | |
7862d7d0 | 361 | b = NULL; |
12516a37 KR |
362 | if (line_num <= sf->num_lines) |
363 | { | |
364 | b = sf->line[line_num - 1]; | |
03c35bcb | 365 | } |
12516a37 KR |
366 | if (!b) |
367 | { | |
7862d7d0 ILT |
368 | for (i = 0; i < width; i++) |
369 | buf[i] = ' '; | |
370 | buf[width] = '\0'; | |
12516a37 KR |
371 | } |
372 | else | |
373 | { | |
7862d7d0 ILT |
374 | char tmpbuf[NBBS * 30]; |
375 | char *p; | |
376 | int ncalls; | |
377 | int len; | |
378 | ||
12516a37 | 379 | ++num_executable_lines; |
7862d7d0 ILT |
380 | |
381 | p = tmpbuf; | |
382 | *p = '\0'; | |
383 | ||
384 | ncalls = -1; | |
385 | ||
386 | /* If this is a function entry point, label the line no matter what. | |
387 | * Otherwise, we're in the middle of a function, so check to see | |
388 | * if the first basic-block address is larger than the starting | |
389 | * address of the line. If so, then this line begins with a | |
390 | * a portion of the previous basic-block, so print that prior | |
391 | * execution count (if bb_annotate_all_lines is set). | |
392 | */ | |
393 | ||
394 | if (b->is_func) | |
395 | { | |
396 | sprintf (p, "%d", b->ncalls); | |
397 | p += strlen (p); | |
398 | last_count = b->ncalls; | |
399 | last_print = last_count; | |
400 | ncalls = b->ncalls; | |
401 | } | |
402 | else if (bb_annotate_all_lines | |
403 | && b->bb_addr[0] && b->bb_addr[0] > b->addr) | |
404 | { | |
405 | sprintf (p, "%d", last_count); | |
406 | p += strlen (p); | |
407 | last_print = last_count; | |
408 | ncalls = last_count; | |
409 | } | |
410 | ||
411 | /* Loop through all of this line's basic-blocks. For each one, | |
412 | * update last_count, then compress sequential identical counts | |
413 | * (if bb_annotate_all_lines) and print the execution count. | |
414 | */ | |
415 | ||
416 | for (i = 0; i < NBBS && b->bb_addr[i]; i++) | |
417 | { | |
418 | last_count = b->bb_calls[i]; | |
419 | if (ncalls < 0) | |
420 | ncalls = 0; | |
421 | ncalls += last_count; | |
422 | ||
423 | if (bb_annotate_all_lines && last_count == last_print) | |
424 | { | |
425 | continue; | |
426 | } | |
427 | ||
428 | if (p > tmpbuf) | |
429 | *p++ = ','; | |
430 | sprintf (p, "%d", last_count); | |
431 | p += strlen (p); | |
432 | ||
433 | last_print = last_count; | |
434 | } | |
435 | ||
436 | /* We're done. If nothing has been printed on this line, | |
437 | * print the last execution count (bb_annotate_all_lines), | |
438 | * which could be from either a previous line (if there were | |
439 | * no BBs on this line), or from this line (if all our BB | |
440 | * counts were compressed out because they were identical). | |
441 | */ | |
442 | ||
443 | if (bb_annotate_all_lines && p == tmpbuf) | |
444 | { | |
445 | sprintf (p, "%d", last_count); | |
446 | p += strlen (p); | |
447 | ncalls = last_count; | |
448 | } | |
449 | ||
450 | if (ncalls < 0) | |
451 | { | |
452 | int c; | |
453 | ||
454 | for (c = 0; c < width; c++) | |
455 | buf[c] = ' '; | |
456 | buf[width] = '\0'; | |
457 | return; | |
458 | } | |
459 | ||
12516a37 | 460 | ++num_lines_executed; |
12516a37 | 461 | |
7862d7d0 ILT |
462 | if (ncalls < bb_min_calls) |
463 | { | |
464 | strcpy (tmpbuf, "#####"); | |
465 | p = tmpbuf + 5; | |
466 | } | |
467 | ||
468 | strcpy (p, " -> "); | |
469 | p += 4; | |
470 | ||
471 | len = p - tmpbuf; | |
472 | if (len >= width) | |
473 | { | |
474 | strncpy (buf, tmpbuf, width); | |
475 | buf[width] = '\0'; | |
476 | } | |
477 | else | |
478 | { | |
479 | int c; | |
480 | ||
481 | strcpy (buf + width - len, tmpbuf); | |
482 | for (c = 0; c < width - len; ++c) | |
483 | buf[c] = ' '; | |
484 | } | |
03c35bcb | 485 | } |
03c35bcb | 486 | } |
5489fcc3 | 487 | |
5489fcc3 KR |
488 | /* |
489 | * Annotate the files named in SOURCE_FILES with basic-block statistics | |
490 | * (execution counts). After each source files, a few statistics | |
491 | * regarding that source file are printed. | |
492 | */ | |
493 | void | |
12516a37 | 494 | DEFUN_VOID (print_annotated_source) |
5489fcc3 | 495 | { |
12516a37 KR |
496 | Sym *sym, *line_stats, *new_line; |
497 | Source_File *sf; | |
498 | int i, table_len; | |
499 | FILE *ofp; | |
500 | ||
501 | /* | |
502 | * Find maximum line number for each source file that user is | |
503 | * interested in: | |
504 | */ | |
505 | for (sym = symtab.base; sym < symtab.limit; ++sym) | |
506 | { | |
507 | /* | |
508 | * Accept symbol if it's file is known, its line number is | |
509 | * bigger than anything we have seen for that file so far and | |
510 | * if it's in the INCL_ANNO table or there is no INCL_ANNO | |
511 | * table and it does not appear in the EXCL_ANNO table. | |
512 | */ | |
513 | if (sym->file && sym->line_num > sym->file->num_lines | |
514 | && (sym_lookup (&syms[INCL_ANNO], sym->addr) | |
515 | || (syms[INCL_ANNO].len == 0 | |
516 | && !sym_lookup (&syms[EXCL_ANNO], sym->addr)))) | |
517 | { | |
518 | sym->file->num_lines = sym->line_num; | |
03c35bcb KR |
519 | } |
520 | } | |
12516a37 KR |
521 | |
522 | /* allocate line descriptors: */ | |
523 | ||
524 | for (sf = first_src_file; sf; sf = sf->next) | |
525 | { | |
526 | if (sf->num_lines > 0) | |
527 | { | |
528 | sf->line = (void *) xmalloc (sf->num_lines * sizeof (sf->line[0])); | |
529 | memset (sf->line, 0, sf->num_lines * sizeof (sf->line[0])); | |
03c35bcb KR |
530 | } |
531 | } | |
12516a37 KR |
532 | |
533 | /* count executions per line: */ | |
534 | ||
535 | for (sym = symtab.base; sym < symtab.limit; ++sym) | |
536 | { | |
7862d7d0 | 537 | if (sym->file && sym->file->num_lines |
12516a37 KR |
538 | && (sym_lookup (&syms[INCL_ANNO], sym->addr) |
539 | || (syms[INCL_ANNO].len == 0 | |
540 | && !sym_lookup (&syms[EXCL_ANNO], sym->addr)))) | |
541 | { | |
542 | sym->file->ncalls += sym->ncalls; | |
543 | line_stats = sym->file->line[sym->line_num - 1]; | |
544 | if (!line_stats) | |
545 | { | |
546 | /* common case has at most one basic-block per source line: */ | |
547 | sym->file->line[sym->line_num - 1] = sym; | |
548 | } | |
549 | else if (!line_stats->addr) | |
550 | { | |
551 | /* sym is the 3rd .. nth basic block for this line: */ | |
552 | line_stats->ncalls += sym->ncalls; | |
553 | } | |
554 | else | |
555 | { | |
556 | /* sym is the second basic block for this line */ | |
557 | new_line = (Sym *) xmalloc (sizeof (*new_line)); | |
558 | *new_line = *line_stats; | |
559 | new_line->addr = 0; | |
560 | new_line->ncalls += sym->ncalls; | |
561 | sym->file->line[sym->line_num - 1] = new_line; | |
03c35bcb KR |
562 | } |
563 | } | |
564 | } | |
12516a37 KR |
565 | |
566 | /* plod over source files, annotating them: */ | |
567 | ||
568 | for (sf = first_src_file; sf; sf = sf->next) | |
569 | { | |
570 | if (!sf->num_lines || (ignore_zeros && sf->ncalls == 0)) | |
5489fcc3 | 571 | { |
12516a37 | 572 | continue; |
03c35bcb | 573 | } |
12516a37 KR |
574 | |
575 | num_executable_lines = num_lines_executed = 0; | |
576 | ofp = annotate_source (sf, 16, annotate_with_count, sf); | |
577 | if (!ofp) | |
5489fcc3 | 578 | { |
12516a37 | 579 | continue; |
03c35bcb | 580 | } |
12516a37 KR |
581 | |
582 | if (bb_table_length > 0) | |
583 | { | |
584 | fprintf (ofp, "\n\nTop %d Lines:\n\n Line Count\n\n", | |
585 | bb_table_length); | |
586 | ||
587 | /* abuse line arrays---it's not needed anymore: */ | |
588 | qsort (sf->line, sf->num_lines, sizeof (sf->line[0]), cmp_ncalls); | |
589 | table_len = bb_table_length; | |
590 | if (table_len > sf->num_lines) | |
591 | { | |
592 | table_len = sf->num_lines; | |
03c35bcb | 593 | } |
12516a37 KR |
594 | for (i = 0; i < table_len; ++i) |
595 | { | |
596 | sym = sf->line[i]; | |
597 | if (!sym || sym->ncalls <= 0) | |
598 | { | |
599 | break; | |
03c35bcb | 600 | } |
12516a37 | 601 | fprintf (ofp, "%9d %10d\n", sym->line_num, sym->ncalls); |
03c35bcb KR |
602 | } |
603 | } | |
12516a37 KR |
604 | |
605 | free (sf->line); | |
606 | sf->line = 0; | |
607 | ||
608 | fprintf (ofp, "\nExecution Summary:\n\n"); | |
609 | fprintf (ofp, "%9ld Executable lines in this file\n", | |
610 | num_executable_lines); | |
611 | fprintf (ofp, "%9ld Lines executed\n", num_lines_executed); | |
612 | fprintf (ofp, "%9.2f Percent of the file executed\n", | |
613 | num_executable_lines | |
614 | ? 100.0 * num_lines_executed / (double) num_executable_lines | |
615 | : 100.0); | |
616 | fprintf (ofp, "\n%9d Total number of line executions\n", sf->ncalls); | |
617 | fprintf (ofp, "%9.2f Average executions per line\n", | |
618 | num_executable_lines | |
619 | ? sf->ncalls / (double) num_executable_lines | |
620 | : 0.0); | |
621 | if (ofp != stdout) | |
622 | { | |
623 | fclose (ofp); | |
03c35bcb KR |
624 | } |
625 | } | |
626 | } |