eb0e1c53a071c8f7a15ec4321b88f68ba1964f04
2 * Copyright (c) 1983 Regents of the University of California.
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.
20 #include "libiberty.h"
22 #include "basic_blocks.h"
23 #include "call_graph.h"
36 const char *a_out_name
= A_OUTNAME
;
40 * Default options values:
44 int output_width
= 80;
45 bool bsd_style_output
= FALSE
;
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
;
53 File_Format file_format
= FF_AUTO
;
55 bool first_output
= TRUE
;
58 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
59 All rights reserved.\n";
61 static char *gmon_name
= GMONNAME
; /* profile filename */
66 * Functions that get excluded by default:
68 static char *default_excluded_list
[] = {
69 "_gprof_mcount", "mcount", "_mcount", "__mcleanup",
70 "<locore>", "<hicore>",
74 static struct option long_options
[] =
76 {"line", no_argument
, 0, 'l'},
77 {"no-static", no_argument
, 0, 'a'},
81 {"annotated-source", optional_argument
, 0, 'A'},
82 {"no-annotated-source", optional_argument
, 0, 'J'},
83 {"flat-profile", optional_argument
, 0, 'p'},
84 {"no-flat-profile", optional_argument
, 0, 'P'},
85 {"graph", optional_argument
, 0, 'q'},
86 {"no-graph", optional_argument
, 0, 'Q'},
87 {"exec-counts", optional_argument
, 0, 'C'},
88 {"no-exec-counts", optional_argument
, 0, 'Z'},
89 {"file-info", no_argument
, 0, 'i'},
90 {"sum", no_argument
, 0, 's'},
92 /* various options to affect output: */
94 {"all-lines", no_argument
, 0, 'x'},
95 {"directory-path", required_argument
, 0, 'I'},
96 {"display-unused-functions", no_argument
, 0, 'z'},
97 {"min-count", required_argument
, 0, 'm'},
98 {"print-path", no_argument
, 0, 'L'},
99 {"separate-files", no_argument
, 0, 'y'},
100 {"static-call-graph", no_argument
, 0, 'c'},
101 {"table-length", required_argument
, 0, 't'},
102 {"time", required_argument
, 0, 'n'},
103 {"no-time", required_argument
, 0, 'N'},
104 {"width", required_argument
, 0, 'w'},
106 * These are for backwards-compatibility only. Their functionality
107 * is provided by the output style options already:
109 {"", required_argument
, 0, 'e'},
110 {"", required_argument
, 0, 'E'},
111 {"", required_argument
, 0, 'f'},
112 {"", required_argument
, 0, 'F'},
113 {"", required_argument
, 0, 'k'},
117 {"brief", no_argument
, 0, 'b'},
118 {"debug", optional_argument
, 0, 'd'},
119 {"help", no_argument
, 0, 'h'},
120 {"file-format", required_argument
, 0, 'O'},
121 {"traditional", no_argument
, 0, 'T'},
122 {"version", no_argument
, 0, 'v'},
123 {0, no_argument
, 0, 0}
128 DEFUN(usage
, (stream
, status
), FILE *stream AND
int status
)
131 Usage: %s [-[abchilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
132 [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
133 [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
134 [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
135 [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
136 [--directory-path=dirs] [--display-unused-functions]\n\
137 [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
138 [--no-static] [--print-path] [--separate-files]\n\
139 [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
140 [--version] [--width=n]\n\
141 [image-file] [profile-file...]\n",
148 DEFUN(main
, (argc
, argv
), int argc AND
char **argv
)
152 int ch
, user_specified
= 0;
155 xmalloc_set_program_name(whoami
);
157 while ((ch
= getopt_long(argc
, argv
,
158 "aA::bBcCd::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::",
163 case 'a': ignore_static_funcs
= TRUE
; break;
166 sym_id_add(optarg
, INCL_ANNO
);
168 output_style
|= STYLE_ANNOTATED_SOURCE
;
169 user_specified
|= STYLE_ANNOTATED_SOURCE
;
171 case 'b': print_descriptions
= FALSE
; break;
173 output_style
|= STYLE_CALL_GRAPH
;
174 user_specified
|= STYLE_CALL_GRAPH
;
176 case 'c': ignore_direct_calls
= TRUE
; break;
179 sym_id_add(optarg
, INCL_EXEC
);
181 output_style
|= STYLE_EXEC_COUNTS
;
182 user_specified
|= STYLE_EXEC_COUNTS
;
186 debug_level
|= atoi(optarg
);
187 debug_level
|= ANYDEBUG
;
191 DBG(ANYDEBUG
, printf("[main] debug-level=0x%x\n", debug_level
));
193 printf("%s: debugging not supported; -d ignored\n", whoami
);
196 case 'E': sym_id_add(optarg
, EXCL_TIME
);
197 case 'e': sym_id_add(optarg
, EXCL_GRAPH
); break;
198 case 'F': sym_id_add(optarg
, INCL_TIME
);
199 case 'f': sym_id_add(optarg
, INCL_GRAPH
); break;
200 case 'g': sym_id_add(optarg
, EXCL_FLAT
); break;
201 case 'G': sym_id_add(optarg
, INCL_FLAT
); break;
202 case 'h': usage(stdout
, 0);
204 output_style
|= STYLE_GMON_INFO
;
205 user_specified
|= STYLE_GMON_INFO
;
207 case 'I': search_list_append(&src_search_list
, optarg
); break;
210 sym_id_add(optarg
, EXCL_ANNO
);
211 output_style
|= STYLE_ANNOTATED_SOURCE
;
213 output_style
&= ~STYLE_ANNOTATED_SOURCE
;
215 user_specified
|= STYLE_ANNOTATED_SOURCE
;
217 case 'k': sym_id_add(optarg
, EXCL_ARCS
); break;
218 case 'l': line_granularity
= TRUE
; break;
219 case 'L': print_path
= TRUE
; break;
220 case 'm': bb_min_calls
= atoi(optarg
); break;
221 case 'n': sym_id_add(optarg
, INCL_TIME
); break;
222 case 'N': sym_id_add(optarg
, EXCL_TIME
); break;
225 case 'a': file_format
= FF_AUTO
; break;
226 case 'm': file_format
= FF_MAGIC
; break;
227 case 'b': file_format
= FF_BSD
; break;
228 case 'p': file_format
= FF_PROF
; break;
230 fprintf(stderr
, "%s: unknown file format %s\n",
237 sym_id_add(optarg
, INCL_FLAT
);
239 output_style
|= STYLE_FLAT_PROFILE
;
240 user_specified
|= STYLE_FLAT_PROFILE
;
244 sym_id_add(optarg
, EXCL_FLAT
);
245 output_style
|= STYLE_FLAT_PROFILE
;
247 output_style
&= ~STYLE_FLAT_PROFILE
;
249 user_specified
|= STYLE_FLAT_PROFILE
;
253 if (strchr(optarg
, '/')) {
254 sym_id_add(optarg
, INCL_ARCS
);
256 sym_id_add(optarg
, INCL_GRAPH
);
259 output_style
|= STYLE_CALL_GRAPH
;
260 user_specified
|= STYLE_CALL_GRAPH
;
264 if (strchr(optarg
, '/')) {
265 sym_id_add(optarg
, EXCL_ARCS
);
267 sym_id_add(optarg
, EXCL_GRAPH
);
269 output_style
|= STYLE_CALL_GRAPH
;
271 output_style
&= ~STYLE_CALL_GRAPH
;
273 user_specified
|= STYLE_CALL_GRAPH
;
276 output_style
|= STYLE_SUMMARY_FILE
;
277 user_specified
|= STYLE_SUMMARY_FILE
;
280 bb_table_length
= atoi(optarg
);
281 if (bb_table_length
< 0) {
285 case 'T': bsd_style_output
= TRUE
; break;
286 case 'v': printf ("%s version %s\n", whoami
, VERSION
); done(0);
288 output_width
= atoi(optarg
);
289 if (output_width
< 1) {
293 case 'x': bb_annotate_all_lines
= TRUE
; break;
294 case 'y': create_annotation_files
= TRUE
; break;
295 case 'z': ignore_zeros
= FALSE
; break;
298 sym_id_add(optarg
, EXCL_EXEC
);
299 output_style
|= STYLE_EXEC_COUNTS
;
301 output_style
&= ~STYLE_EXEC_COUNTS
;
303 user_specified
|= STYLE_ANNOTATED_SOURCE
;
305 default: usage(stderr
, 1);
309 /* append value of GPROF_PATH to source search list if set: */
310 str
= getenv("GPROF_PATH");
312 search_list_append(&src_search_list
, str
);
316 a_out_name
= argv
[optind
++];
319 gmon_name
= argv
[optind
++];
323 * Turn off default functions:
325 for (sp
= &default_excluded_list
[0]; *sp
; sp
++) {
326 sym_id_add(*sp
, EXCL_TIME
);
327 sym_id_add(*sp
, EXCL_GRAPH
);
329 sym_id_add(*sp
, EXCL_FLAT
);
334 * For line-by-line profiling, also want to keep those
335 * functions off the flat profile:
337 if (line_granularity
) {
338 for (sp
= &default_excluded_list
[0]; *sp
; sp
++) {
339 sym_id_add(*sp
, EXCL_FLAT
);
344 * Read symbol table from core file:
346 core_init(a_out_name
);
349 * If we should ignore direct function calls, we need to load
350 * to core's text-space:
352 if (ignore_direct_calls
) {
353 core_get_text_space(core_bfd
);
357 * Create symbols from core image:
359 if (line_granularity
) {
360 core_create_line_syms(core_bfd
);
362 core_create_function_syms(core_bfd
);
366 * Translate sym specs into syms:
370 if (file_format
== FF_PROF
) {
371 #ifdef PROF_SUPPORT_IMPLEMENTED
373 * Get information about mon.out file(s):
376 mon_out_read(gmon_name
);
378 gmon_name
= argv
[optind
];
380 } while (optind
++ < argc
);
383 "%s: sorry, file format `prof' is not yet supported\n",
389 * Get information about gmon.out file(s):
392 gmon_out_read(gmon_name
);
394 gmon_name
= argv
[optind
];
396 } while (optind
++ < argc
);
400 * If user did not specify output style, try to guess something
403 if (output_style
== 0) {
404 if (gmon_input
& (INPUT_HISTOGRAM
| INPUT_CALL_GRAPH
)) {
405 output_style
= STYLE_FLAT_PROFILE
| STYLE_CALL_GRAPH
;
407 output_style
= STYLE_EXEC_COUNTS
;
409 output_style
&= ~user_specified
;
413 * Dump a gmon.sum file if requested (before any other processing!):
415 if (output_style
& STYLE_SUMMARY_FILE
) {
416 gmon_out_write(GMONSUM
);
419 if (gmon_input
& INPUT_HISTOGRAM
) {
420 hist_assign_samples();
423 if (gmon_input
& INPUT_CALL_GRAPH
) {
427 /* do some simple sanity checks: */
429 if ((output_style
& STYLE_FLAT_PROFILE
)
430 && !(gmon_input
& INPUT_HISTOGRAM
))
432 fprintf(stderr
, "%s: gmon.out file is missing histogram\n", whoami
);
436 if ((output_style
& STYLE_CALL_GRAPH
) && !(gmon_input
& INPUT_CALL_GRAPH
))
439 "%s: gmon.out file is missing call-graph data\n", whoami
);
443 /* output whatever user whishes to see: */
445 if (cg
&& (output_style
& STYLE_CALL_GRAPH
) && bsd_style_output
) {
446 cg_print(cg
); /* print the dynamic profile */
449 if (output_style
& STYLE_FLAT_PROFILE
) {
450 hist_print(); /* print the flat profile */
453 if (cg
&& (output_style
& STYLE_CALL_GRAPH
)) {
454 if (!bsd_style_output
) {
455 cg_print(cg
); /* print the dynamic profile */
460 if (output_style
& STYLE_EXEC_COUNTS
) {
464 if (output_style
& STYLE_ANNOTATED_SOURCE
) {
465 print_annotated_source();
This page took 0.03851 seconds and 4 git commands to generate.