Commit | Line | Data |
---|---|---|
3d6c6501 | 1 | /* |
16a02269 | 2 | * Copyright (c) 1983, 1998 Regents of the University of California. |
3d6c6501 SEF |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that: (1) source distributions retain this entire copyright | |
7 | * notice and comment, and (2) distributions including binaries display | |
8 | * the following acknowledgement: ``This product includes software | |
9 | * developed by the University of California, Berkeley and its contributors'' | |
10 | * in the documentation or other materials provided with the distribution | |
11 | * and in all advertising materials mentioning features or use of this | |
12 | * software. Neither the name of the University nor the names of its | |
13 | * contributors may be used to endorse or promote products derived | |
14 | * from this software without specific prior written permission. | |
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
18 | */ | |
5489fcc3 KR |
19 | #include "getopt.h" |
20 | #include "libiberty.h" | |
21 | #include "gprof.h" | |
22 | #include "basic_blocks.h" | |
23 | #include "call_graph.h" | |
24 | #include "cg_arcs.h" | |
25 | #include "cg_print.h" | |
43870aec | 26 | #include "corefile.h" |
5489fcc3 KR |
27 | #include "gmon_io.h" |
28 | #include "hertz.h" | |
29 | #include "hist.h" | |
30 | #include "source.h" | |
31 | #include "sym_ids.h" | |
32 | ||
5489fcc3 | 33 | const char *whoami; |
64c50fc5 | 34 | const char *function_mapping_file; |
5489fcc3 KR |
35 | const char *a_out_name = A_OUTNAME; |
36 | long hz = HZ_WRONG; | |
3d6c6501 | 37 | |
5489fcc3 KR |
38 | /* |
39 | * Default options values: | |
40 | */ | |
41 | int debug_level = 0; | |
42 | int output_style = 0; | |
43 | int output_width = 80; | |
44 | bool bsd_style_output = FALSE; | |
e4dee78c | 45 | bool demangle = TRUE; |
5489fcc3 KR |
46 | bool discard_underscores = TRUE; |
47 | bool ignore_direct_calls = FALSE; | |
48 | bool ignore_static_funcs = FALSE; | |
49 | bool ignore_zeros = TRUE; | |
50 | bool line_granularity = FALSE; | |
51 | bool print_descriptions = TRUE; | |
52 | bool print_path = FALSE; | |
32843f94 | 53 | bool ignore_non_functions = FALSE; |
5489fcc3 KR |
54 | File_Format file_format = FF_AUTO; |
55 | ||
56 | bool first_output = TRUE; | |
b4f476e9 | 57 | |
3d6c6501 | 58 | char copyright[] = |
16a02269 TT |
59 | N_("@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
60 | All rights reserved.\n"); | |
3d6c6501 | 61 | |
12516a37 | 62 | static char *gmon_name = GMONNAME; /* profile filename */ |
c06e55d9 | 63 | |
12516a37 | 64 | bfd *abfd; |
77c9b2c3 | 65 | |
5489fcc3 KR |
66 | /* |
67 | * Functions that get excluded by default: | |
68 | */ | |
12516a37 KR |
69 | static char *default_excluded_list[] = |
70 | { | |
c3de2a19 ILT |
71 | "_gprof_mcount", "mcount", "_mcount", "__mcount", "__mcount_internal", |
72 | "__mcleanup", | |
12516a37 KR |
73 | "<locore>", "<hicore>", |
74 | 0 | |
5489fcc3 | 75 | }; |
3d6c6501 | 76 | |
e4dee78c ILT |
77 | /* Codes used for the long options with no short synonyms. 150 isn't |
78 | special; it's just an arbitrary non-ASCII char value. */ | |
79 | ||
80 | #define OPTION_DEMANGLE (150) | |
81 | #define OPTION_NO_DEMANGLE (OPTION_DEMANGLE + 1) | |
82 | ||
5489fcc3 KR |
83 | static struct option long_options[] = |
84 | { | |
12516a37 KR |
85 | {"line", no_argument, 0, 'l'}, |
86 | {"no-static", no_argument, 0, 'a'}, | |
32843f94 | 87 | {"ignore-non-functions", no_argument, 0, 'D'}, |
5489fcc3 KR |
88 | |
89 | /* output styles: */ | |
90 | ||
12516a37 KR |
91 | {"annotated-source", optional_argument, 0, 'A'}, |
92 | {"no-annotated-source", optional_argument, 0, 'J'}, | |
93 | {"flat-profile", optional_argument, 0, 'p'}, | |
94 | {"no-flat-profile", optional_argument, 0, 'P'}, | |
95 | {"graph", optional_argument, 0, 'q'}, | |
96 | {"no-graph", optional_argument, 0, 'Q'}, | |
97 | {"exec-counts", optional_argument, 0, 'C'}, | |
98 | {"no-exec-counts", optional_argument, 0, 'Z'}, | |
64c50fc5 JL |
99 | {"function-ordering", no_argument, 0, 'r'}, |
100 | {"file-ordering", required_argument, 0, 'R'}, | |
12516a37 KR |
101 | {"file-info", no_argument, 0, 'i'}, |
102 | {"sum", no_argument, 0, 's'}, | |
5489fcc3 KR |
103 | |
104 | /* various options to affect output: */ | |
105 | ||
12516a37 | 106 | {"all-lines", no_argument, 0, 'x'}, |
e4dee78c ILT |
107 | {"demangle", no_argument, 0, OPTION_DEMANGLE}, |
108 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLE}, | |
12516a37 KR |
109 | {"directory-path", required_argument, 0, 'I'}, |
110 | {"display-unused-functions", no_argument, 0, 'z'}, | |
111 | {"min-count", required_argument, 0, 'm'}, | |
112 | {"print-path", no_argument, 0, 'L'}, | |
113 | {"separate-files", no_argument, 0, 'y'}, | |
114 | {"static-call-graph", no_argument, 0, 'c'}, | |
115 | {"table-length", required_argument, 0, 't'}, | |
116 | {"time", required_argument, 0, 'n'}, | |
117 | {"no-time", required_argument, 0, 'N'}, | |
118 | {"width", required_argument, 0, 'w'}, | |
3d6c6501 | 119 | /* |
5489fcc3 KR |
120 | * These are for backwards-compatibility only. Their functionality |
121 | * is provided by the output style options already: | |
3d6c6501 | 122 | */ |
12516a37 KR |
123 | {"", required_argument, 0, 'e'}, |
124 | {"", required_argument, 0, 'E'}, | |
125 | {"", required_argument, 0, 'f'}, | |
126 | {"", required_argument, 0, 'F'}, | |
127 | {"", required_argument, 0, 'k'}, | |
5489fcc3 KR |
128 | |
129 | /* miscellaneous: */ | |
130 | ||
12516a37 KR |
131 | {"brief", no_argument, 0, 'b'}, |
132 | {"debug", optional_argument, 0, 'd'}, | |
133 | {"help", no_argument, 0, 'h'}, | |
134 | {"file-format", required_argument, 0, 'O'}, | |
135 | {"traditional", no_argument, 0, 'T'}, | |
136 | {"version", no_argument, 0, 'v'}, | |
137 | {0, no_argument, 0, 0} | |
5489fcc3 KR |
138 | }; |
139 | ||
140 | ||
141 | static void | |
12516a37 | 142 | DEFUN (usage, (stream, status), FILE * stream AND int status) |
5489fcc3 | 143 | { |
16a02269 | 144 | fprintf (stream, _("\ |
32843f94 | 145 | Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\ |
5489fcc3 KR |
146 | [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\ |
147 | [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\ | |
148 | [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\ | |
149 | [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\ | |
64c50fc5 | 150 | [--function-ordering] [--file-ordering]\n\ |
5489fcc3 KR |
151 | [--directory-path=dirs] [--display-unused-functions]\n\ |
152 | [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\ | |
153 | [--no-static] [--print-path] [--separate-files]\n\ | |
154 | [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\ | |
32843f94 | 155 | [--version] [--width=n] [--ignore-non-functions]\n\ |
e4dee78c | 156 | [--demangle] [--no-demangle]\n\ |
16a02269 | 157 | [image-file] [profile-file...]\n"), |
12516a37 | 158 | whoami); |
50622dea | 159 | if (status == 0) |
16a02269 | 160 | fprintf (stream, _("Report bugs to bug-gnu-utils@gnu.org\n")); |
12516a37 | 161 | done (status); |
03c35bcb | 162 | } |
5489fcc3 KR |
163 | |
164 | ||
165 | int | |
12516a37 | 166 | DEFUN (main, (argc, argv), int argc AND char **argv) |
3d6c6501 | 167 | { |
12516a37 KR |
168 | char **sp, *str; |
169 | Sym **cg = 0; | |
170 | int ch, user_specified = 0; | |
3d6c6501 | 171 | |
64eaad40 | 172 | #ifdef HAVE_SETLOCALE |
16a02269 | 173 | setlocale (LC_MESSAGES, ""); |
64eaad40 | 174 | #endif |
16a02269 TT |
175 | bindtextdomain (PACKAGE, LOCALEDIR); |
176 | textdomain (PACKAGE); | |
177 | ||
12516a37 KR |
178 | whoami = argv[0]; |
179 | xmalloc_set_program_name (whoami); | |
5489fcc3 | 180 | |
12516a37 | 181 | while ((ch = getopt_long (argc, argv, |
32843f94 | 182 | "aA::bBcCdD::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::", |
12516a37 KR |
183 | long_options, 0)) |
184 | != EOF) | |
5489fcc3 | 185 | { |
12516a37 KR |
186 | switch (ch) |
187 | { | |
188 | case 'a': | |
189 | ignore_static_funcs = TRUE; | |
190 | break; | |
191 | case 'A': | |
192 | if (optarg) | |
193 | { | |
194 | sym_id_add (optarg, INCL_ANNO); | |
03c35bcb | 195 | } |
12516a37 KR |
196 | output_style |= STYLE_ANNOTATED_SOURCE; |
197 | user_specified |= STYLE_ANNOTATED_SOURCE; | |
198 | break; | |
199 | case 'b': | |
200 | print_descriptions = FALSE; | |
201 | break; | |
202 | case 'B': | |
203 | output_style |= STYLE_CALL_GRAPH; | |
204 | user_specified |= STYLE_CALL_GRAPH; | |
205 | break; | |
206 | case 'c': | |
207 | ignore_direct_calls = TRUE; | |
208 | break; | |
209 | case 'C': | |
210 | if (optarg) | |
211 | { | |
212 | sym_id_add (optarg, INCL_EXEC); | |
03c35bcb | 213 | } |
12516a37 KR |
214 | output_style |= STYLE_EXEC_COUNTS; |
215 | user_specified |= STYLE_EXEC_COUNTS; | |
216 | break; | |
217 | case 'd': | |
218 | if (optarg) | |
219 | { | |
220 | debug_level |= atoi (optarg); | |
221 | debug_level |= ANYDEBUG; | |
222 | } | |
223 | else | |
224 | { | |
225 | debug_level = ~0; | |
03c35bcb | 226 | } |
12516a37 | 227 | DBG (ANYDEBUG, printf ("[main] debug-level=0x%x\n", debug_level)); |
5489fcc3 | 228 | #ifndef DEBUG |
16a02269 | 229 | printf (_("%s: debugging not supported; -d ignored\n"), whoami); |
12516a37 KR |
230 | #endif /* DEBUG */ |
231 | break; | |
32843f94 JL |
232 | case 'D': |
233 | ignore_non_functions = TRUE; | |
234 | break; | |
12516a37 KR |
235 | case 'E': |
236 | sym_id_add (optarg, EXCL_TIME); | |
237 | case 'e': | |
238 | sym_id_add (optarg, EXCL_GRAPH); | |
239 | break; | |
240 | case 'F': | |
241 | sym_id_add (optarg, INCL_TIME); | |
242 | case 'f': | |
243 | sym_id_add (optarg, INCL_GRAPH); | |
244 | break; | |
245 | case 'g': | |
246 | sym_id_add (optarg, EXCL_FLAT); | |
247 | break; | |
248 | case 'G': | |
249 | sym_id_add (optarg, INCL_FLAT); | |
250 | break; | |
251 | case 'h': | |
252 | usage (stdout, 0); | |
253 | case 'i': | |
254 | output_style |= STYLE_GMON_INFO; | |
255 | user_specified |= STYLE_GMON_INFO; | |
256 | break; | |
257 | case 'I': | |
258 | search_list_append (&src_search_list, optarg); | |
259 | break; | |
260 | case 'J': | |
261 | if (optarg) | |
262 | { | |
263 | sym_id_add (optarg, EXCL_ANNO); | |
264 | output_style |= STYLE_ANNOTATED_SOURCE; | |
265 | } | |
266 | else | |
267 | { | |
268 | output_style &= ~STYLE_ANNOTATED_SOURCE; | |
03c35bcb | 269 | } |
12516a37 KR |
270 | user_specified |= STYLE_ANNOTATED_SOURCE; |
271 | break; | |
272 | case 'k': | |
273 | sym_id_add (optarg, EXCL_ARCS); | |
274 | break; | |
275 | case 'l': | |
276 | line_granularity = TRUE; | |
277 | break; | |
278 | case 'L': | |
279 | print_path = TRUE; | |
280 | break; | |
281 | case 'm': | |
8c73afb3 | 282 | bb_min_calls = (unsigned long) strtoul (optarg, (char **) NULL, 10); |
12516a37 KR |
283 | break; |
284 | case 'n': | |
285 | sym_id_add (optarg, INCL_TIME); | |
286 | break; | |
287 | case 'N': | |
288 | sym_id_add (optarg, EXCL_TIME); | |
289 | break; | |
290 | case 'O': | |
291 | switch (optarg[0]) | |
292 | { | |
293 | case 'a': | |
294 | file_format = FF_AUTO; | |
295 | break; | |
296 | case 'm': | |
297 | file_format = FF_MAGIC; | |
298 | break; | |
299 | case 'b': | |
300 | file_format = FF_BSD; | |
301 | break; | |
302 | case 'p': | |
303 | file_format = FF_PROF; | |
304 | break; | |
305 | default: | |
16a02269 | 306 | fprintf (stderr, _("%s: unknown file format %s\n"), |
12516a37 KR |
307 | optarg, whoami); |
308 | done (1); | |
03c35bcb | 309 | } |
12516a37 KR |
310 | break; |
311 | case 'p': | |
312 | if (optarg) | |
313 | { | |
314 | sym_id_add (optarg, INCL_FLAT); | |
03c35bcb | 315 | } |
12516a37 KR |
316 | output_style |= STYLE_FLAT_PROFILE; |
317 | user_specified |= STYLE_FLAT_PROFILE; | |
318 | break; | |
319 | case 'P': | |
320 | if (optarg) | |
321 | { | |
322 | sym_id_add (optarg, EXCL_FLAT); | |
323 | output_style |= STYLE_FLAT_PROFILE; | |
324 | } | |
325 | else | |
326 | { | |
327 | output_style &= ~STYLE_FLAT_PROFILE; | |
03c35bcb | 328 | } |
12516a37 KR |
329 | user_specified |= STYLE_FLAT_PROFILE; |
330 | break; | |
331 | case 'q': | |
332 | if (optarg) | |
333 | { | |
334 | if (strchr (optarg, '/')) | |
335 | { | |
336 | sym_id_add (optarg, INCL_ARCS); | |
337 | } | |
338 | else | |
339 | { | |
340 | sym_id_add (optarg, INCL_GRAPH); | |
03c35bcb KR |
341 | } |
342 | } | |
12516a37 KR |
343 | output_style |= STYLE_CALL_GRAPH; |
344 | user_specified |= STYLE_CALL_GRAPH; | |
345 | break; | |
64c50fc5 JL |
346 | case 'r': |
347 | output_style |= STYLE_FUNCTION_ORDER; | |
348 | user_specified |= STYLE_FUNCTION_ORDER; | |
349 | break; | |
350 | case 'R': | |
351 | output_style |= STYLE_FILE_ORDER; | |
352 | user_specified |= STYLE_FILE_ORDER; | |
353 | function_mapping_file = optarg; | |
354 | break; | |
12516a37 KR |
355 | case 'Q': |
356 | if (optarg) | |
357 | { | |
358 | if (strchr (optarg, '/')) | |
359 | { | |
360 | sym_id_add (optarg, EXCL_ARCS); | |
361 | } | |
362 | else | |
363 | { | |
364 | sym_id_add (optarg, EXCL_GRAPH); | |
03c35bcb | 365 | } |
12516a37 KR |
366 | output_style |= STYLE_CALL_GRAPH; |
367 | } | |
368 | else | |
369 | { | |
370 | output_style &= ~STYLE_CALL_GRAPH; | |
03c35bcb | 371 | } |
12516a37 KR |
372 | user_specified |= STYLE_CALL_GRAPH; |
373 | break; | |
374 | case 's': | |
375 | output_style |= STYLE_SUMMARY_FILE; | |
376 | user_specified |= STYLE_SUMMARY_FILE; | |
377 | break; | |
378 | case 't': | |
379 | bb_table_length = atoi (optarg); | |
380 | if (bb_table_length < 0) | |
381 | { | |
382 | bb_table_length = 0; | |
03c35bcb | 383 | } |
12516a37 KR |
384 | break; |
385 | case 'T': | |
386 | bsd_style_output = TRUE; | |
387 | break; | |
388 | case 'v': | |
50622dea | 389 | /* This output is intended to follow the GNU standards document. */ |
16a02269 TT |
390 | printf (_("GNU gprof %s\n"), VERSION); |
391 | printf (_("Based on BSD gprof, copyright 1983 Regents of the University of California.\n")); | |
392 | printf (_("\ | |
393 | This program is free software. This program has absolutely no warranty.\n")); | |
12516a37 KR |
394 | done (0); |
395 | case 'w': | |
396 | output_width = atoi (optarg); | |
397 | if (output_width < 1) | |
398 | { | |
399 | output_width = 1; | |
03c35bcb | 400 | } |
12516a37 KR |
401 | break; |
402 | case 'x': | |
403 | bb_annotate_all_lines = TRUE; | |
404 | break; | |
405 | case 'y': | |
406 | create_annotation_files = TRUE; | |
407 | break; | |
408 | case 'z': | |
409 | ignore_zeros = FALSE; | |
410 | break; | |
411 | case 'Z': | |
412 | if (optarg) | |
413 | { | |
414 | sym_id_add (optarg, EXCL_EXEC); | |
415 | output_style |= STYLE_EXEC_COUNTS; | |
416 | } | |
417 | else | |
418 | { | |
419 | output_style &= ~STYLE_EXEC_COUNTS; | |
03c35bcb | 420 | } |
12516a37 KR |
421 | user_specified |= STYLE_ANNOTATED_SOURCE; |
422 | break; | |
e4dee78c ILT |
423 | case OPTION_DEMANGLE: |
424 | demangle = TRUE; | |
425 | break; | |
426 | case OPTION_NO_DEMANGLE: | |
427 | demangle = FALSE; | |
428 | break; | |
12516a37 KR |
429 | default: |
430 | usage (stderr, 1); | |
03c35bcb KR |
431 | } |
432 | } | |
12516a37 | 433 | |
64c50fc5 JL |
434 | /* Don't allow both ordering options, they modify the arc data in-place. */ |
435 | if ((user_specified & STYLE_FUNCTION_ORDER) | |
436 | && (user_specified & STYLE_FILE_ORDER)) | |
437 | { | |
16a02269 TT |
438 | fprintf (stderr,_("\ |
439 | %s: Only one of --function-ordering and --file-ordering may be specified.\n"), | |
64c50fc5 JL |
440 | whoami); |
441 | done (1); | |
442 | } | |
443 | ||
7862d7d0 ILT |
444 | /* --sum implies --line, otherwise we'd lose b-b counts in gmon.sum */ |
445 | if (output_style & STYLE_SUMMARY_FILE) | |
446 | { | |
447 | line_granularity = 1; | |
448 | } | |
449 | ||
12516a37 | 450 | /* append value of GPROF_PATH to source search list if set: */ |
31af2d7e | 451 | str = (char *) getenv ("GPROF_PATH"); |
12516a37 KR |
452 | if (str) |
453 | { | |
454 | search_list_append (&src_search_list, str); | |
03c35bcb | 455 | } |
3d6c6501 | 456 | |
12516a37 KR |
457 | if (optind < argc) |
458 | { | |
459 | a_out_name = argv[optind++]; | |
03c35bcb | 460 | } |
12516a37 KR |
461 | if (optind < argc) |
462 | { | |
463 | gmon_name = argv[optind++]; | |
03c35bcb | 464 | } |
12516a37 KR |
465 | |
466 | /* | |
467 | * Turn off default functions: | |
468 | */ | |
469 | for (sp = &default_excluded_list[0]; *sp; sp++) | |
470 | { | |
471 | sym_id_add (*sp, EXCL_TIME); | |
472 | sym_id_add (*sp, EXCL_GRAPH); | |
0f579087 | 473 | #ifdef __alpha__ |
12516a37 | 474 | sym_id_add (*sp, EXCL_FLAT); |
5489fcc3 | 475 | #endif |
03c35bcb | 476 | } |
5489fcc3 | 477 | |
12516a37 KR |
478 | /* |
479 | * For line-by-line profiling, also want to keep those | |
480 | * functions off the flat profile: | |
481 | */ | |
482 | if (line_granularity) | |
483 | { | |
484 | for (sp = &default_excluded_list[0]; *sp; sp++) | |
485 | { | |
486 | sym_id_add (*sp, EXCL_FLAT); | |
03c35bcb KR |
487 | } |
488 | } | |
12516a37 KR |
489 | |
490 | /* | |
491 | * Read symbol table from core file: | |
492 | */ | |
493 | core_init (a_out_name); | |
494 | ||
495 | /* | |
496 | * If we should ignore direct function calls, we need to load | |
497 | * to core's text-space: | |
498 | */ | |
499 | if (ignore_direct_calls) | |
500 | { | |
501 | core_get_text_space (core_bfd); | |
03c35bcb | 502 | } |
3d6c6501 | 503 | |
12516a37 KR |
504 | /* |
505 | * Create symbols from core image: | |
506 | */ | |
507 | if (line_granularity) | |
508 | { | |
509 | core_create_line_syms (core_bfd); | |
510 | } | |
511 | else | |
512 | { | |
513 | core_create_function_syms (core_bfd); | |
03c35bcb | 514 | } |
3d6c6501 | 515 | |
12516a37 KR |
516 | /* |
517 | * Translate sym specs into syms: | |
518 | */ | |
519 | sym_id_parse (); | |
3d6c6501 | 520 | |
12516a37 KR |
521 | if (file_format == FF_PROF) |
522 | { | |
5489fcc3 | 523 | #ifdef PROF_SUPPORT_IMPLEMENTED |
12516a37 KR |
524 | /* |
525 | * Get information about mon.out file(s): | |
526 | */ | |
527 | do | |
528 | { | |
529 | mon_out_read (gmon_name); | |
530 | if (optind < argc) | |
531 | { | |
532 | gmon_name = argv[optind]; | |
03c35bcb | 533 | } |
12516a37 KR |
534 | } |
535 | while (optind++ < argc); | |
5489fcc3 | 536 | #else |
12516a37 | 537 | fprintf (stderr, |
16a02269 | 538 | _("%s: sorry, file format `prof' is not yet supported\n"), |
12516a37 KR |
539 | whoami); |
540 | done (1); | |
811e3c6a | 541 | #endif |
12516a37 KR |
542 | } |
543 | else | |
544 | { | |
545 | /* | |
546 | * Get information about gmon.out file(s): | |
547 | */ | |
548 | do | |
549 | { | |
550 | gmon_out_read (gmon_name); | |
551 | if (optind < argc) | |
552 | { | |
553 | gmon_name = argv[optind]; | |
03c35bcb | 554 | } |
12516a37 KR |
555 | } |
556 | while (optind++ < argc); | |
03c35bcb | 557 | } |
12516a37 KR |
558 | |
559 | /* | |
560 | * If user did not specify output style, try to guess something | |
561 | * reasonable: | |
562 | */ | |
563 | if (output_style == 0) | |
564 | { | |
565 | if (gmon_input & (INPUT_HISTOGRAM | INPUT_CALL_GRAPH)) | |
566 | { | |
567 | output_style = STYLE_FLAT_PROFILE | STYLE_CALL_GRAPH; | |
568 | } | |
569 | else | |
570 | { | |
571 | output_style = STYLE_EXEC_COUNTS; | |
03c35bcb | 572 | } |
12516a37 | 573 | output_style &= ~user_specified; |
03c35bcb | 574 | } |
12516a37 KR |
575 | |
576 | /* | |
577 | * Dump a gmon.sum file if requested (before any other processing!): | |
578 | */ | |
579 | if (output_style & STYLE_SUMMARY_FILE) | |
580 | { | |
581 | gmon_out_write (GMONSUM); | |
03c35bcb | 582 | } |
4b8250bd | 583 | |
12516a37 KR |
584 | if (gmon_input & INPUT_HISTOGRAM) |
585 | { | |
586 | hist_assign_samples (); | |
03c35bcb | 587 | } |
2ea5f325 | 588 | |
12516a37 KR |
589 | if (gmon_input & INPUT_CALL_GRAPH) |
590 | { | |
591 | cg = cg_assemble (); | |
03c35bcb | 592 | } |
12516a37 KR |
593 | |
594 | /* do some simple sanity checks: */ | |
595 | ||
596 | if ((output_style & STYLE_FLAT_PROFILE) | |
597 | && !(gmon_input & INPUT_HISTOGRAM)) | |
598 | { | |
16a02269 | 599 | fprintf (stderr, _("%s: gmon.out file is missing histogram\n"), whoami); |
12516a37 | 600 | done (1); |
03c35bcb | 601 | } |
5489fcc3 | 602 | |
12516a37 KR |
603 | if ((output_style & STYLE_CALL_GRAPH) && !(gmon_input & INPUT_CALL_GRAPH)) |
604 | { | |
605 | fprintf (stderr, | |
16a02269 | 606 | _("%s: gmon.out file is missing call-graph data\n"), whoami); |
12516a37 | 607 | done (1); |
03c35bcb | 608 | } |
5489fcc3 | 609 | |
12516a37 | 610 | /* output whatever user whishes to see: */ |
5489fcc3 | 611 | |
12516a37 KR |
612 | if (cg && (output_style & STYLE_CALL_GRAPH) && bsd_style_output) |
613 | { | |
614 | cg_print (cg); /* print the dynamic profile */ | |
03c35bcb | 615 | } |
5489fcc3 | 616 | |
12516a37 KR |
617 | if (output_style & STYLE_FLAT_PROFILE) |
618 | { | |
619 | hist_print (); /* print the flat profile */ | |
03c35bcb | 620 | } |
12516a37 KR |
621 | |
622 | if (cg && (output_style & STYLE_CALL_GRAPH)) | |
623 | { | |
624 | if (!bsd_style_output) | |
625 | { | |
626 | cg_print (cg); /* print the dynamic profile */ | |
03c35bcb | 627 | } |
12516a37 | 628 | cg_print_index (); |
03c35bcb | 629 | } |
12516a37 KR |
630 | |
631 | if (output_style & STYLE_EXEC_COUNTS) | |
5489fcc3 | 632 | { |
12516a37 | 633 | print_exec_counts (); |
03c35bcb | 634 | } |
5489fcc3 | 635 | |
12516a37 | 636 | if (output_style & STYLE_ANNOTATED_SOURCE) |
5489fcc3 | 637 | { |
12516a37 | 638 | print_annotated_source (); |
03c35bcb | 639 | } |
64c50fc5 JL |
640 | if (output_style & STYLE_FUNCTION_ORDER) |
641 | { | |
642 | cg_print_function_ordering (); | |
643 | } | |
644 | if (output_style & STYLE_FILE_ORDER) | |
645 | { | |
646 | cg_print_file_ordering (); | |
647 | } | |
12516a37 | 648 | return 0; |
3d6c6501 SEF |
649 | } |
650 | ||
5489fcc3 KR |
651 | void |
652 | done (status) | |
653 | int status; | |
3d6c6501 | 654 | { |
12516a37 | 655 | exit (status); |
3d6c6501 | 656 | } |