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", "__mcleanup",
71 "<locore>", "<hicore>",
75 static struct option long_options
[] =
77 {"line", no_argument
, 0, 'l'},
78 {"no-static", no_argument
, 0, 'a'},
79 {"ignore-non-functions", no_argument
, 0, 'D'},
83 {"annotated-source", optional_argument
, 0, 'A'},
84 {"no-annotated-source", optional_argument
, 0, 'J'},
85 {"flat-profile", optional_argument
, 0, 'p'},
86 {"no-flat-profile", optional_argument
, 0, 'P'},
87 {"graph", optional_argument
, 0, 'q'},
88 {"no-graph", optional_argument
, 0, 'Q'},
89 {"exec-counts", optional_argument
, 0, 'C'},
90 {"no-exec-counts", optional_argument
, 0, 'Z'},
91 {"function-ordering", no_argument
, 0, 'r'},
92 {"file-ordering", required_argument
, 0, 'R'},
93 {"file-info", no_argument
, 0, 'i'},
94 {"sum", no_argument
, 0, 's'},
96 /* various options to affect output: */
98 {"all-lines", no_argument
, 0, 'x'},
99 {"directory-path", required_argument
, 0, 'I'},
100 {"display-unused-functions", no_argument
, 0, 'z'},
101 {"min-count", required_argument
, 0, 'm'},
102 {"print-path", no_argument
, 0, 'L'},
103 {"separate-files", no_argument
, 0, 'y'},
104 {"static-call-graph", no_argument
, 0, 'c'},
105 {"table-length", required_argument
, 0, 't'},
106 {"time", required_argument
, 0, 'n'},
107 {"no-time", required_argument
, 0, 'N'},
108 {"width", required_argument
, 0, 'w'},
110 * These are for backwards-compatibility only. Their functionality
111 * is provided by the output style options already:
113 {"", required_argument
, 0, 'e'},
114 {"", required_argument
, 0, 'E'},
115 {"", required_argument
, 0, 'f'},
116 {"", required_argument
, 0, 'F'},
117 {"", required_argument
, 0, 'k'},
121 {"brief", no_argument
, 0, 'b'},
122 {"debug", optional_argument
, 0, 'd'},
123 {"help", no_argument
, 0, 'h'},
124 {"file-format", required_argument
, 0, 'O'},
125 {"traditional", no_argument
, 0, 'T'},
126 {"version", no_argument
, 0, 'v'},
127 {0, no_argument
, 0, 0}
132 DEFUN (usage
, (stream
, status
), FILE * stream AND
int status
)
135 Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
136 [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
137 [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
138 [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
139 [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
140 [--function-ordering] [--file-ordering]\n\
141 [--directory-path=dirs] [--display-unused-functions]\n\
142 [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
143 [--no-static] [--print-path] [--separate-files]\n\
144 [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
145 [--version] [--width=n] [--ignore-non-functions]\n\
146 [image-file] [profile-file...]\n",
149 fprintf (stream
, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
155 DEFUN (main
, (argc
, argv
), int argc AND
char **argv
)
159 int ch
, user_specified
= 0;
162 xmalloc_set_program_name (whoami
);
164 while ((ch
= getopt_long (argc
, argv
,
165 "aA::bBcCdD::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::",
172 ignore_static_funcs
= TRUE
;
177 sym_id_add (optarg
, INCL_ANNO
);
179 output_style
|= STYLE_ANNOTATED_SOURCE
;
180 user_specified
|= STYLE_ANNOTATED_SOURCE
;
183 print_descriptions
= FALSE
;
186 output_style
|= STYLE_CALL_GRAPH
;
187 user_specified
|= STYLE_CALL_GRAPH
;
190 ignore_direct_calls
= TRUE
;
195 sym_id_add (optarg
, INCL_EXEC
);
197 output_style
|= STYLE_EXEC_COUNTS
;
198 user_specified
|= STYLE_EXEC_COUNTS
;
203 debug_level
|= atoi (optarg
);
204 debug_level
|= ANYDEBUG
;
210 DBG (ANYDEBUG
, printf ("[main] debug-level=0x%x\n", debug_level
));
212 printf ("%s: debugging not supported; -d ignored\n", whoami
);
216 ignore_non_functions
= TRUE
;
219 sym_id_add (optarg
, EXCL_TIME
);
221 sym_id_add (optarg
, EXCL_GRAPH
);
224 sym_id_add (optarg
, INCL_TIME
);
226 sym_id_add (optarg
, INCL_GRAPH
);
229 sym_id_add (optarg
, EXCL_FLAT
);
232 sym_id_add (optarg
, INCL_FLAT
);
237 output_style
|= STYLE_GMON_INFO
;
238 user_specified
|= STYLE_GMON_INFO
;
241 search_list_append (&src_search_list
, optarg
);
246 sym_id_add (optarg
, EXCL_ANNO
);
247 output_style
|= STYLE_ANNOTATED_SOURCE
;
251 output_style
&= ~STYLE_ANNOTATED_SOURCE
;
253 user_specified
|= STYLE_ANNOTATED_SOURCE
;
256 sym_id_add (optarg
, EXCL_ARCS
);
259 line_granularity
= TRUE
;
265 bb_min_calls
= atoi (optarg
);
268 sym_id_add (optarg
, INCL_TIME
);
271 sym_id_add (optarg
, EXCL_TIME
);
277 file_format
= FF_AUTO
;
280 file_format
= FF_MAGIC
;
283 file_format
= FF_BSD
;
286 file_format
= FF_PROF
;
289 fprintf (stderr
, "%s: unknown file format %s\n",
297 sym_id_add (optarg
, INCL_FLAT
);
299 output_style
|= STYLE_FLAT_PROFILE
;
300 user_specified
|= STYLE_FLAT_PROFILE
;
305 sym_id_add (optarg
, EXCL_FLAT
);
306 output_style
|= STYLE_FLAT_PROFILE
;
310 output_style
&= ~STYLE_FLAT_PROFILE
;
312 user_specified
|= STYLE_FLAT_PROFILE
;
317 if (strchr (optarg
, '/'))
319 sym_id_add (optarg
, INCL_ARCS
);
323 sym_id_add (optarg
, INCL_GRAPH
);
326 output_style
|= STYLE_CALL_GRAPH
;
327 user_specified
|= STYLE_CALL_GRAPH
;
330 output_style
|= STYLE_FUNCTION_ORDER
;
331 user_specified
|= STYLE_FUNCTION_ORDER
;
334 output_style
|= STYLE_FILE_ORDER
;
335 user_specified
|= STYLE_FILE_ORDER
;
336 function_mapping_file
= optarg
;
341 if (strchr (optarg
, '/'))
343 sym_id_add (optarg
, EXCL_ARCS
);
347 sym_id_add (optarg
, EXCL_GRAPH
);
349 output_style
|= STYLE_CALL_GRAPH
;
353 output_style
&= ~STYLE_CALL_GRAPH
;
355 user_specified
|= STYLE_CALL_GRAPH
;
358 output_style
|= STYLE_SUMMARY_FILE
;
359 user_specified
|= STYLE_SUMMARY_FILE
;
362 bb_table_length
= atoi (optarg
);
363 if (bb_table_length
< 0)
369 bsd_style_output
= TRUE
;
372 /* This output is intended to follow the GNU standards document. */
373 printf ("GNU gprof %s\n", VERSION
);
374 printf ("Based on BSD gprof, copyright 1983 Regents of the University of California.\n");
376 This program is free software. This program has absolutely no warranty.\n");
379 output_width
= atoi (optarg
);
380 if (output_width
< 1)
386 bb_annotate_all_lines
= TRUE
;
389 create_annotation_files
= TRUE
;
392 ignore_zeros
= FALSE
;
397 sym_id_add (optarg
, EXCL_EXEC
);
398 output_style
|= STYLE_EXEC_COUNTS
;
402 output_style
&= ~STYLE_EXEC_COUNTS
;
404 user_specified
|= STYLE_ANNOTATED_SOURCE
;
411 /* Don't allow both ordering options, they modify the arc data in-place. */
412 if ((user_specified
& STYLE_FUNCTION_ORDER
)
413 && (user_specified
& STYLE_FILE_ORDER
))
416 %s: Only one of --function-ordering and --file-ordering may be specified.\n",
421 /* append value of GPROF_PATH to source search list if set: */
422 str
= (char *) getenv ("GPROF_PATH");
425 search_list_append (&src_search_list
, str
);
430 a_out_name
= argv
[optind
++];
434 gmon_name
= argv
[optind
++];
438 * Turn off default functions:
440 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
442 sym_id_add (*sp
, EXCL_TIME
);
443 sym_id_add (*sp
, EXCL_GRAPH
);
445 sym_id_add (*sp
, EXCL_FLAT
);
450 * For line-by-line profiling, also want to keep those
451 * functions off the flat profile:
453 if (line_granularity
)
455 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
457 sym_id_add (*sp
, EXCL_FLAT
);
462 * Read symbol table from core file:
464 core_init (a_out_name
);
467 * If we should ignore direct function calls, we need to load
468 * to core's text-space:
470 if (ignore_direct_calls
)
472 core_get_text_space (core_bfd
);
476 * Create symbols from core image:
478 if (line_granularity
)
480 core_create_line_syms (core_bfd
);
484 core_create_function_syms (core_bfd
);
488 * Translate sym specs into syms:
492 if (file_format
== FF_PROF
)
494 #ifdef PROF_SUPPORT_IMPLEMENTED
496 * Get information about mon.out file(s):
500 mon_out_read (gmon_name
);
503 gmon_name
= argv
[optind
];
506 while (optind
++ < argc
);
509 "%s: sorry, file format `prof' is not yet supported\n",
517 * Get information about gmon.out file(s):
521 gmon_out_read (gmon_name
);
524 gmon_name
= argv
[optind
];
527 while (optind
++ < argc
);
531 * If user did not specify output style, try to guess something
534 if (output_style
== 0)
536 if (gmon_input
& (INPUT_HISTOGRAM
| INPUT_CALL_GRAPH
))
538 output_style
= STYLE_FLAT_PROFILE
| STYLE_CALL_GRAPH
;
542 output_style
= STYLE_EXEC_COUNTS
;
544 output_style
&= ~user_specified
;
548 * Dump a gmon.sum file if requested (before any other processing!):
550 if (output_style
& STYLE_SUMMARY_FILE
)
552 gmon_out_write (GMONSUM
);
555 if (gmon_input
& INPUT_HISTOGRAM
)
557 hist_assign_samples ();
560 if (gmon_input
& INPUT_CALL_GRAPH
)
565 /* do some simple sanity checks: */
567 if ((output_style
& STYLE_FLAT_PROFILE
)
568 && !(gmon_input
& INPUT_HISTOGRAM
))
570 fprintf (stderr
, "%s: gmon.out file is missing histogram\n", whoami
);
574 if ((output_style
& STYLE_CALL_GRAPH
) && !(gmon_input
& INPUT_CALL_GRAPH
))
577 "%s: gmon.out file is missing call-graph data\n", whoami
);
581 /* output whatever user whishes to see: */
583 if (cg
&& (output_style
& STYLE_CALL_GRAPH
) && bsd_style_output
)
585 cg_print (cg
); /* print the dynamic profile */
588 if (output_style
& STYLE_FLAT_PROFILE
)
590 hist_print (); /* print the flat profile */
593 if (cg
&& (output_style
& STYLE_CALL_GRAPH
))
595 if (!bsd_style_output
)
597 cg_print (cg
); /* print the dynamic profile */
602 if (output_style
& STYLE_EXEC_COUNTS
)
604 print_exec_counts ();
607 if (output_style
& STYLE_ANNOTATED_SOURCE
)
609 print_annotated_source ();
611 if (output_style
& STYLE_FUNCTION_ORDER
)
613 cg_print_function_ordering ();
615 if (output_style
& STYLE_FILE_ORDER
)
617 cg_print_file_ordering ();
This page took 0.749122 seconds and 4 git commands to generate.