0f9dd85f7c1b64941b9bb94f82ed2c57a2d46287
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 bool ignore_non_functions
= FALSE
;
54 File_Format file_format
= FF_AUTO
;
56 bool first_output
= TRUE
;
59 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
60 All rights reserved.\n";
62 static char *gmon_name
= GMONNAME
; /* profile filename */
67 * Functions that get excluded by default:
69 static char *default_excluded_list
[] =
71 "_gprof_mcount", "mcount", "_mcount", "__mcleanup",
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 {"file-info", no_argument
, 0, 'i'},
93 {"sum", no_argument
, 0, 's'},
95 /* various options to affect output: */
97 {"all-lines", no_argument
, 0, 'x'},
98 {"directory-path", required_argument
, 0, 'I'},
99 {"display-unused-functions", no_argument
, 0, 'z'},
100 {"min-count", required_argument
, 0, 'm'},
101 {"print-path", no_argument
, 0, 'L'},
102 {"separate-files", no_argument
, 0, 'y'},
103 {"static-call-graph", no_argument
, 0, 'c'},
104 {"table-length", required_argument
, 0, 't'},
105 {"time", required_argument
, 0, 'n'},
106 {"no-time", required_argument
, 0, 'N'},
107 {"width", required_argument
, 0, 'w'},
109 * These are for backwards-compatibility only. Their functionality
110 * is provided by the output style options already:
112 {"", required_argument
, 0, 'e'},
113 {"", required_argument
, 0, 'E'},
114 {"", required_argument
, 0, 'f'},
115 {"", required_argument
, 0, 'F'},
116 {"", required_argument
, 0, 'k'},
120 {"brief", no_argument
, 0, 'b'},
121 {"debug", optional_argument
, 0, 'd'},
122 {"help", no_argument
, 0, 'h'},
123 {"file-format", required_argument
, 0, 'O'},
124 {"traditional", no_argument
, 0, 'T'},
125 {"version", no_argument
, 0, 'v'},
126 {0, no_argument
, 0, 0}
131 DEFUN (usage
, (stream
, status
), FILE * stream AND
int status
)
134 Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
135 [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
136 [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
137 [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
138 [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
139 [--directory-path=dirs] [--display-unused-functions]\n\
140 [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
141 [--no-static] [--print-path] [--separate-files]\n\
142 [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
143 [--version] [--width=n] [--ignore-non-functions]\n\
144 [image-file] [profile-file...]\n",
151 DEFUN (main
, (argc
, argv
), int argc AND
char **argv
)
155 int ch
, user_specified
= 0;
158 xmalloc_set_program_name (whoami
);
160 while ((ch
= getopt_long (argc
, argv
,
161 "aA::bBcCdD::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::",
168 ignore_static_funcs
= TRUE
;
173 sym_id_add (optarg
, INCL_ANNO
);
175 output_style
|= STYLE_ANNOTATED_SOURCE
;
176 user_specified
|= STYLE_ANNOTATED_SOURCE
;
179 print_descriptions
= FALSE
;
182 output_style
|= STYLE_CALL_GRAPH
;
183 user_specified
|= STYLE_CALL_GRAPH
;
186 ignore_direct_calls
= TRUE
;
191 sym_id_add (optarg
, INCL_EXEC
);
193 output_style
|= STYLE_EXEC_COUNTS
;
194 user_specified
|= STYLE_EXEC_COUNTS
;
199 debug_level
|= atoi (optarg
);
200 debug_level
|= ANYDEBUG
;
206 DBG (ANYDEBUG
, printf ("[main] debug-level=0x%x\n", debug_level
));
208 printf ("%s: debugging not supported; -d ignored\n", whoami
);
212 ignore_non_functions
= TRUE
;
215 sym_id_add (optarg
, EXCL_TIME
);
217 sym_id_add (optarg
, EXCL_GRAPH
);
220 sym_id_add (optarg
, INCL_TIME
);
222 sym_id_add (optarg
, INCL_GRAPH
);
225 sym_id_add (optarg
, EXCL_FLAT
);
228 sym_id_add (optarg
, INCL_FLAT
);
233 output_style
|= STYLE_GMON_INFO
;
234 user_specified
|= STYLE_GMON_INFO
;
237 search_list_append (&src_search_list
, optarg
);
242 sym_id_add (optarg
, EXCL_ANNO
);
243 output_style
|= STYLE_ANNOTATED_SOURCE
;
247 output_style
&= ~STYLE_ANNOTATED_SOURCE
;
249 user_specified
|= STYLE_ANNOTATED_SOURCE
;
252 sym_id_add (optarg
, EXCL_ARCS
);
255 line_granularity
= TRUE
;
261 bb_min_calls
= atoi (optarg
);
264 sym_id_add (optarg
, INCL_TIME
);
267 sym_id_add (optarg
, EXCL_TIME
);
273 file_format
= FF_AUTO
;
276 file_format
= FF_MAGIC
;
279 file_format
= FF_BSD
;
282 file_format
= FF_PROF
;
285 fprintf (stderr
, "%s: unknown file format %s\n",
293 sym_id_add (optarg
, INCL_FLAT
);
295 output_style
|= STYLE_FLAT_PROFILE
;
296 user_specified
|= STYLE_FLAT_PROFILE
;
301 sym_id_add (optarg
, EXCL_FLAT
);
302 output_style
|= STYLE_FLAT_PROFILE
;
306 output_style
&= ~STYLE_FLAT_PROFILE
;
308 user_specified
|= STYLE_FLAT_PROFILE
;
313 if (strchr (optarg
, '/'))
315 sym_id_add (optarg
, INCL_ARCS
);
319 sym_id_add (optarg
, INCL_GRAPH
);
322 output_style
|= STYLE_CALL_GRAPH
;
323 user_specified
|= STYLE_CALL_GRAPH
;
328 if (strchr (optarg
, '/'))
330 sym_id_add (optarg
, EXCL_ARCS
);
334 sym_id_add (optarg
, EXCL_GRAPH
);
336 output_style
|= STYLE_CALL_GRAPH
;
340 output_style
&= ~STYLE_CALL_GRAPH
;
342 user_specified
|= STYLE_CALL_GRAPH
;
345 output_style
|= STYLE_SUMMARY_FILE
;
346 user_specified
|= STYLE_SUMMARY_FILE
;
349 bb_table_length
= atoi (optarg
);
350 if (bb_table_length
< 0)
356 bsd_style_output
= TRUE
;
359 printf ("%s version %s\n", whoami
, VERSION
);
362 output_width
= atoi (optarg
);
363 if (output_width
< 1)
369 bb_annotate_all_lines
= TRUE
;
372 create_annotation_files
= TRUE
;
375 ignore_zeros
= FALSE
;
380 sym_id_add (optarg
, EXCL_EXEC
);
381 output_style
|= STYLE_EXEC_COUNTS
;
385 output_style
&= ~STYLE_EXEC_COUNTS
;
387 user_specified
|= STYLE_ANNOTATED_SOURCE
;
394 /* append value of GPROF_PATH to source search list if set: */
395 str
= (char *) getenv ("GPROF_PATH");
398 search_list_append (&src_search_list
, str
);
403 a_out_name
= argv
[optind
++];
407 gmon_name
= argv
[optind
++];
411 * Turn off default functions:
413 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
415 sym_id_add (*sp
, EXCL_TIME
);
416 sym_id_add (*sp
, EXCL_GRAPH
);
418 sym_id_add (*sp
, EXCL_FLAT
);
423 * For line-by-line profiling, also want to keep those
424 * functions off the flat profile:
426 if (line_granularity
)
428 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
430 sym_id_add (*sp
, EXCL_FLAT
);
435 * Read symbol table from core file:
437 core_init (a_out_name
);
440 * If we should ignore direct function calls, we need to load
441 * to core's text-space:
443 if (ignore_direct_calls
)
445 core_get_text_space (core_bfd
);
449 * Create symbols from core image:
451 if (line_granularity
)
453 core_create_line_syms (core_bfd
);
457 core_create_function_syms (core_bfd
);
461 * Translate sym specs into syms:
465 if (file_format
== FF_PROF
)
467 #ifdef PROF_SUPPORT_IMPLEMENTED
469 * Get information about mon.out file(s):
473 mon_out_read (gmon_name
);
476 gmon_name
= argv
[optind
];
479 while (optind
++ < argc
);
482 "%s: sorry, file format `prof' is not yet supported\n",
490 * Get information about gmon.out file(s):
494 gmon_out_read (gmon_name
);
497 gmon_name
= argv
[optind
];
500 while (optind
++ < argc
);
504 * If user did not specify output style, try to guess something
507 if (output_style
== 0)
509 if (gmon_input
& (INPUT_HISTOGRAM
| INPUT_CALL_GRAPH
))
511 output_style
= STYLE_FLAT_PROFILE
| STYLE_CALL_GRAPH
;
515 output_style
= STYLE_EXEC_COUNTS
;
517 output_style
&= ~user_specified
;
521 * Dump a gmon.sum file if requested (before any other processing!):
523 if (output_style
& STYLE_SUMMARY_FILE
)
525 gmon_out_write (GMONSUM
);
528 if (gmon_input
& INPUT_HISTOGRAM
)
530 hist_assign_samples ();
533 if (gmon_input
& INPUT_CALL_GRAPH
)
538 /* do some simple sanity checks: */
540 if ((output_style
& STYLE_FLAT_PROFILE
)
541 && !(gmon_input
& INPUT_HISTOGRAM
))
543 fprintf (stderr
, "%s: gmon.out file is missing histogram\n", whoami
);
547 if ((output_style
& STYLE_CALL_GRAPH
) && !(gmon_input
& INPUT_CALL_GRAPH
))
550 "%s: gmon.out file is missing call-graph data\n", whoami
);
554 /* output whatever user whishes to see: */
556 if (cg
&& (output_style
& STYLE_CALL_GRAPH
) && bsd_style_output
)
558 cg_print (cg
); /* print the dynamic profile */
561 if (output_style
& STYLE_FLAT_PROFILE
)
563 hist_print (); /* print the flat profile */
566 if (cg
&& (output_style
& STYLE_CALL_GRAPH
))
568 if (!bsd_style_output
)
570 cg_print (cg
); /* print the dynamic profile */
575 if (output_style
& STYLE_EXEC_COUNTS
)
577 print_exec_counts ();
580 if (output_style
& STYLE_ANNOTATED_SOURCE
)
582 print_annotated_source ();
This page took 0.050107 seconds and 3 git commands to generate.