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"
34 const char *function_mapping_file
;
35 const char *a_out_name
= A_OUTNAME
;
39 * Default options values:
43 int output_width
= 80;
44 bool bsd_style_output
= FALSE
;
45 bool discard_underscores
= TRUE
;
46 bool ignore_direct_calls
= FALSE
;
47 bool ignore_static_funcs
= FALSE
;
48 bool ignore_zeros
= TRUE
;
49 bool line_granularity
= FALSE
;
50 bool print_descriptions
= TRUE
;
51 bool print_path
= FALSE
;
52 bool ignore_non_functions
= 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
[] =
70 "_gprof_mcount", "mcount", "_mcount", "__mcount", "__mcount_internal",
72 "<locore>", "<hicore>",
76 static struct option long_options
[] =
78 {"line", no_argument
, 0, 'l'},
79 {"no-static", no_argument
, 0, 'a'},
80 {"ignore-non-functions", no_argument
, 0, 'D'},
84 {"annotated-source", optional_argument
, 0, 'A'},
85 {"no-annotated-source", optional_argument
, 0, 'J'},
86 {"flat-profile", optional_argument
, 0, 'p'},
87 {"no-flat-profile", optional_argument
, 0, 'P'},
88 {"graph", optional_argument
, 0, 'q'},
89 {"no-graph", optional_argument
, 0, 'Q'},
90 {"exec-counts", optional_argument
, 0, 'C'},
91 {"no-exec-counts", optional_argument
, 0, 'Z'},
92 {"function-ordering", no_argument
, 0, 'r'},
93 {"file-ordering", required_argument
, 0, 'R'},
94 {"file-info", no_argument
, 0, 'i'},
95 {"sum", no_argument
, 0, 's'},
97 /* various options to affect output: */
99 {"all-lines", no_argument
, 0, 'x'},
100 {"directory-path", required_argument
, 0, 'I'},
101 {"display-unused-functions", no_argument
, 0, 'z'},
102 {"min-count", required_argument
, 0, 'm'},
103 {"print-path", no_argument
, 0, 'L'},
104 {"separate-files", no_argument
, 0, 'y'},
105 {"static-call-graph", no_argument
, 0, 'c'},
106 {"table-length", required_argument
, 0, 't'},
107 {"time", required_argument
, 0, 'n'},
108 {"no-time", required_argument
, 0, 'N'},
109 {"width", required_argument
, 0, 'w'},
111 * These are for backwards-compatibility only. Their functionality
112 * is provided by the output style options already:
114 {"", required_argument
, 0, 'e'},
115 {"", required_argument
, 0, 'E'},
116 {"", required_argument
, 0, 'f'},
117 {"", required_argument
, 0, 'F'},
118 {"", required_argument
, 0, 'k'},
122 {"brief", no_argument
, 0, 'b'},
123 {"debug", optional_argument
, 0, 'd'},
124 {"help", no_argument
, 0, 'h'},
125 {"file-format", required_argument
, 0, 'O'},
126 {"traditional", no_argument
, 0, 'T'},
127 {"version", no_argument
, 0, 'v'},
128 {0, no_argument
, 0, 0}
133 DEFUN (usage
, (stream
, status
), FILE * stream AND
int status
)
136 Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
137 [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
138 [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
139 [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
140 [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
141 [--function-ordering] [--file-ordering]\n\
142 [--directory-path=dirs] [--display-unused-functions]\n\
143 [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
144 [--no-static] [--print-path] [--separate-files]\n\
145 [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
146 [--version] [--width=n] [--ignore-non-functions]\n\
147 [image-file] [profile-file...]\n",
150 fprintf (stream
, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
156 DEFUN (main
, (argc
, argv
), int argc AND
char **argv
)
160 int ch
, user_specified
= 0;
163 xmalloc_set_program_name (whoami
);
165 while ((ch
= getopt_long (argc
, argv
,
166 "aA::bBcCdD::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::",
173 ignore_static_funcs
= TRUE
;
178 sym_id_add (optarg
, INCL_ANNO
);
180 output_style
|= STYLE_ANNOTATED_SOURCE
;
181 user_specified
|= STYLE_ANNOTATED_SOURCE
;
184 print_descriptions
= FALSE
;
187 output_style
|= STYLE_CALL_GRAPH
;
188 user_specified
|= STYLE_CALL_GRAPH
;
191 ignore_direct_calls
= TRUE
;
196 sym_id_add (optarg
, INCL_EXEC
);
198 output_style
|= STYLE_EXEC_COUNTS
;
199 user_specified
|= STYLE_EXEC_COUNTS
;
204 debug_level
|= atoi (optarg
);
205 debug_level
|= ANYDEBUG
;
211 DBG (ANYDEBUG
, printf ("[main] debug-level=0x%x\n", debug_level
));
213 printf ("%s: debugging not supported; -d ignored\n", whoami
);
217 ignore_non_functions
= TRUE
;
220 sym_id_add (optarg
, EXCL_TIME
);
222 sym_id_add (optarg
, EXCL_GRAPH
);
225 sym_id_add (optarg
, INCL_TIME
);
227 sym_id_add (optarg
, INCL_GRAPH
);
230 sym_id_add (optarg
, EXCL_FLAT
);
233 sym_id_add (optarg
, INCL_FLAT
);
238 output_style
|= STYLE_GMON_INFO
;
239 user_specified
|= STYLE_GMON_INFO
;
242 search_list_append (&src_search_list
, optarg
);
247 sym_id_add (optarg
, EXCL_ANNO
);
248 output_style
|= STYLE_ANNOTATED_SOURCE
;
252 output_style
&= ~STYLE_ANNOTATED_SOURCE
;
254 user_specified
|= STYLE_ANNOTATED_SOURCE
;
257 sym_id_add (optarg
, EXCL_ARCS
);
260 line_granularity
= TRUE
;
266 bb_min_calls
= atoi (optarg
);
269 sym_id_add (optarg
, INCL_TIME
);
272 sym_id_add (optarg
, EXCL_TIME
);
278 file_format
= FF_AUTO
;
281 file_format
= FF_MAGIC
;
284 file_format
= FF_BSD
;
287 file_format
= FF_PROF
;
290 fprintf (stderr
, "%s: unknown file format %s\n",
298 sym_id_add (optarg
, INCL_FLAT
);
300 output_style
|= STYLE_FLAT_PROFILE
;
301 user_specified
|= STYLE_FLAT_PROFILE
;
306 sym_id_add (optarg
, EXCL_FLAT
);
307 output_style
|= STYLE_FLAT_PROFILE
;
311 output_style
&= ~STYLE_FLAT_PROFILE
;
313 user_specified
|= STYLE_FLAT_PROFILE
;
318 if (strchr (optarg
, '/'))
320 sym_id_add (optarg
, INCL_ARCS
);
324 sym_id_add (optarg
, INCL_GRAPH
);
327 output_style
|= STYLE_CALL_GRAPH
;
328 user_specified
|= STYLE_CALL_GRAPH
;
331 output_style
|= STYLE_FUNCTION_ORDER
;
332 user_specified
|= STYLE_FUNCTION_ORDER
;
335 output_style
|= STYLE_FILE_ORDER
;
336 user_specified
|= STYLE_FILE_ORDER
;
337 function_mapping_file
= optarg
;
342 if (strchr (optarg
, '/'))
344 sym_id_add (optarg
, EXCL_ARCS
);
348 sym_id_add (optarg
, EXCL_GRAPH
);
350 output_style
|= STYLE_CALL_GRAPH
;
354 output_style
&= ~STYLE_CALL_GRAPH
;
356 user_specified
|= STYLE_CALL_GRAPH
;
359 output_style
|= STYLE_SUMMARY_FILE
;
360 user_specified
|= STYLE_SUMMARY_FILE
;
363 bb_table_length
= atoi (optarg
);
364 if (bb_table_length
< 0)
370 bsd_style_output
= TRUE
;
373 /* This output is intended to follow the GNU standards document. */
374 printf ("GNU gprof %s\n", VERSION
);
375 printf ("Based on BSD gprof, copyright 1983 Regents of the University of California.\n");
377 This program is free software. This program has absolutely no warranty.\n");
380 output_width
= atoi (optarg
);
381 if (output_width
< 1)
387 bb_annotate_all_lines
= TRUE
;
390 create_annotation_files
= TRUE
;
393 ignore_zeros
= FALSE
;
398 sym_id_add (optarg
, EXCL_EXEC
);
399 output_style
|= STYLE_EXEC_COUNTS
;
403 output_style
&= ~STYLE_EXEC_COUNTS
;
405 user_specified
|= STYLE_ANNOTATED_SOURCE
;
412 /* Don't allow both ordering options, they modify the arc data in-place. */
413 if ((user_specified
& STYLE_FUNCTION_ORDER
)
414 && (user_specified
& STYLE_FILE_ORDER
))
417 %s: Only one of --function-ordering and --file-ordering may be specified.\n",
422 /* --sum implies --line, otherwise we'd lose b-b counts in gmon.sum */
423 if (output_style
& STYLE_SUMMARY_FILE
)
425 line_granularity
= 1;
428 /* append value of GPROF_PATH to source search list if set: */
429 str
= (char *) getenv ("GPROF_PATH");
432 search_list_append (&src_search_list
, str
);
437 a_out_name
= argv
[optind
++];
441 gmon_name
= argv
[optind
++];
445 * Turn off default functions:
447 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
449 sym_id_add (*sp
, EXCL_TIME
);
450 sym_id_add (*sp
, EXCL_GRAPH
);
452 sym_id_add (*sp
, EXCL_FLAT
);
457 * For line-by-line profiling, also want to keep those
458 * functions off the flat profile:
460 if (line_granularity
)
462 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
464 sym_id_add (*sp
, EXCL_FLAT
);
469 * Read symbol table from core file:
471 core_init (a_out_name
);
474 * If we should ignore direct function calls, we need to load
475 * to core's text-space:
477 if (ignore_direct_calls
)
479 core_get_text_space (core_bfd
);
483 * Create symbols from core image:
485 if (line_granularity
)
487 core_create_line_syms (core_bfd
);
491 core_create_function_syms (core_bfd
);
495 * Translate sym specs into syms:
499 if (file_format
== FF_PROF
)
501 #ifdef PROF_SUPPORT_IMPLEMENTED
503 * Get information about mon.out file(s):
507 mon_out_read (gmon_name
);
510 gmon_name
= argv
[optind
];
513 while (optind
++ < argc
);
516 "%s: sorry, file format `prof' is not yet supported\n",
524 * Get information about gmon.out file(s):
528 gmon_out_read (gmon_name
);
531 gmon_name
= argv
[optind
];
534 while (optind
++ < argc
);
538 * If user did not specify output style, try to guess something
541 if (output_style
== 0)
543 if (gmon_input
& (INPUT_HISTOGRAM
| INPUT_CALL_GRAPH
))
545 output_style
= STYLE_FLAT_PROFILE
| STYLE_CALL_GRAPH
;
549 output_style
= STYLE_EXEC_COUNTS
;
551 output_style
&= ~user_specified
;
555 * Dump a gmon.sum file if requested (before any other processing!):
557 if (output_style
& STYLE_SUMMARY_FILE
)
559 gmon_out_write (GMONSUM
);
562 if (gmon_input
& INPUT_HISTOGRAM
)
564 hist_assign_samples ();
567 if (gmon_input
& INPUT_CALL_GRAPH
)
572 /* do some simple sanity checks: */
574 if ((output_style
& STYLE_FLAT_PROFILE
)
575 && !(gmon_input
& INPUT_HISTOGRAM
))
577 fprintf (stderr
, "%s: gmon.out file is missing histogram\n", whoami
);
581 if ((output_style
& STYLE_CALL_GRAPH
) && !(gmon_input
& INPUT_CALL_GRAPH
))
584 "%s: gmon.out file is missing call-graph data\n", whoami
);
588 /* output whatever user whishes to see: */
590 if (cg
&& (output_style
& STYLE_CALL_GRAPH
) && bsd_style_output
)
592 cg_print (cg
); /* print the dynamic profile */
595 if (output_style
& STYLE_FLAT_PROFILE
)
597 hist_print (); /* print the flat profile */
600 if (cg
&& (output_style
& STYLE_CALL_GRAPH
))
602 if (!bsd_style_output
)
604 cg_print (cg
); /* print the dynamic profile */
609 if (output_style
& STYLE_EXEC_COUNTS
)
611 print_exec_counts ();
614 if (output_style
& STYLE_ANNOTATED_SOURCE
)
616 print_annotated_source ();
618 if (output_style
& STYLE_FUNCTION_ORDER
)
620 cg_print_function_ordering ();
622 if (output_style
& STYLE_FILE_ORDER
)
624 cg_print_file_ordering ();
This page took 0.042618 seconds and 4 git commands to generate.