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
[] =
70 "_gprof_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'},
82 {"annotated-source", optional_argument
, 0, 'A'},
83 {"no-annotated-source", optional_argument
, 0, 'J'},
84 {"flat-profile", optional_argument
, 0, 'p'},
85 {"no-flat-profile", optional_argument
, 0, 'P'},
86 {"graph", optional_argument
, 0, 'q'},
87 {"no-graph", optional_argument
, 0, 'Q'},
88 {"exec-counts", optional_argument
, 0, 'C'},
89 {"no-exec-counts", optional_argument
, 0, 'Z'},
90 {"file-info", no_argument
, 0, 'i'},
91 {"sum", no_argument
, 0, 's'},
93 /* various options to affect output: */
95 {"all-lines", no_argument
, 0, 'x'},
96 {"directory-path", required_argument
, 0, 'I'},
97 {"display-unused-functions", no_argument
, 0, 'z'},
98 {"min-count", required_argument
, 0, 'm'},
99 {"print-path", no_argument
, 0, 'L'},
100 {"separate-files", no_argument
, 0, 'y'},
101 {"static-call-graph", no_argument
, 0, 'c'},
102 {"table-length", required_argument
, 0, 't'},
103 {"time", required_argument
, 0, 'n'},
104 {"no-time", required_argument
, 0, 'N'},
105 {"width", required_argument
, 0, 'w'},
107 * These are for backwards-compatibility only. Their functionality
108 * is provided by the output style options already:
110 {"", required_argument
, 0, 'e'},
111 {"", required_argument
, 0, 'E'},
112 {"", required_argument
, 0, 'f'},
113 {"", required_argument
, 0, 'F'},
114 {"", required_argument
, 0, 'k'},
118 {"brief", no_argument
, 0, 'b'},
119 {"debug", optional_argument
, 0, 'd'},
120 {"help", no_argument
, 0, 'h'},
121 {"file-format", required_argument
, 0, 'O'},
122 {"traditional", no_argument
, 0, 'T'},
123 {"version", no_argument
, 0, 'v'},
124 {0, no_argument
, 0, 0}
129 DEFUN (usage
, (stream
, status
), FILE * stream AND
int status
)
132 Usage: %s [-[abchilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]\n\
133 [-d[num]] [-k from/to] [-m min-count] [-t table-length]\n\
134 [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
135 [--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
136 [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
137 [--directory-path=dirs] [--display-unused-functions]\n\
138 [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
139 [--no-static] [--print-path] [--separate-files]\n\
140 [--static-call-graph] [--sum] [--table-length=len] [--traditional]\n\
141 [--version] [--width=n]\n\
142 [image-file] [profile-file...]\n",
149 DEFUN (main
, (argc
, argv
), int argc AND
char **argv
)
153 int ch
, user_specified
= 0;
156 xmalloc_set_program_name (whoami
);
158 while ((ch
= getopt_long (argc
, argv
,
159 "aA::bBcCd::e:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::",
166 ignore_static_funcs
= TRUE
;
171 sym_id_add (optarg
, INCL_ANNO
);
173 output_style
|= STYLE_ANNOTATED_SOURCE
;
174 user_specified
|= STYLE_ANNOTATED_SOURCE
;
177 print_descriptions
= FALSE
;
180 output_style
|= STYLE_CALL_GRAPH
;
181 user_specified
|= STYLE_CALL_GRAPH
;
184 ignore_direct_calls
= TRUE
;
189 sym_id_add (optarg
, INCL_EXEC
);
191 output_style
|= STYLE_EXEC_COUNTS
;
192 user_specified
|= STYLE_EXEC_COUNTS
;
197 debug_level
|= atoi (optarg
);
198 debug_level
|= ANYDEBUG
;
204 DBG (ANYDEBUG
, printf ("[main] debug-level=0x%x\n", debug_level
));
206 printf ("%s: debugging not supported; -d ignored\n", whoami
);
210 sym_id_add (optarg
, EXCL_TIME
);
212 sym_id_add (optarg
, EXCL_GRAPH
);
215 sym_id_add (optarg
, INCL_TIME
);
217 sym_id_add (optarg
, INCL_GRAPH
);
220 sym_id_add (optarg
, EXCL_FLAT
);
223 sym_id_add (optarg
, INCL_FLAT
);
228 output_style
|= STYLE_GMON_INFO
;
229 user_specified
|= STYLE_GMON_INFO
;
232 search_list_append (&src_search_list
, optarg
);
237 sym_id_add (optarg
, EXCL_ANNO
);
238 output_style
|= STYLE_ANNOTATED_SOURCE
;
242 output_style
&= ~STYLE_ANNOTATED_SOURCE
;
244 user_specified
|= STYLE_ANNOTATED_SOURCE
;
247 sym_id_add (optarg
, EXCL_ARCS
);
250 line_granularity
= TRUE
;
256 bb_min_calls
= atoi (optarg
);
259 sym_id_add (optarg
, INCL_TIME
);
262 sym_id_add (optarg
, EXCL_TIME
);
268 file_format
= FF_AUTO
;
271 file_format
= FF_MAGIC
;
274 file_format
= FF_BSD
;
277 file_format
= FF_PROF
;
280 fprintf (stderr
, "%s: unknown file format %s\n",
288 sym_id_add (optarg
, INCL_FLAT
);
290 output_style
|= STYLE_FLAT_PROFILE
;
291 user_specified
|= STYLE_FLAT_PROFILE
;
296 sym_id_add (optarg
, EXCL_FLAT
);
297 output_style
|= STYLE_FLAT_PROFILE
;
301 output_style
&= ~STYLE_FLAT_PROFILE
;
303 user_specified
|= STYLE_FLAT_PROFILE
;
308 if (strchr (optarg
, '/'))
310 sym_id_add (optarg
, INCL_ARCS
);
314 sym_id_add (optarg
, INCL_GRAPH
);
317 output_style
|= STYLE_CALL_GRAPH
;
318 user_specified
|= STYLE_CALL_GRAPH
;
323 if (strchr (optarg
, '/'))
325 sym_id_add (optarg
, EXCL_ARCS
);
329 sym_id_add (optarg
, EXCL_GRAPH
);
331 output_style
|= STYLE_CALL_GRAPH
;
335 output_style
&= ~STYLE_CALL_GRAPH
;
337 user_specified
|= STYLE_CALL_GRAPH
;
340 output_style
|= STYLE_SUMMARY_FILE
;
341 user_specified
|= STYLE_SUMMARY_FILE
;
344 bb_table_length
= atoi (optarg
);
345 if (bb_table_length
< 0)
351 bsd_style_output
= TRUE
;
354 printf ("%s version %s\n", whoami
, VERSION
);
357 output_width
= atoi (optarg
);
358 if (output_width
< 1)
364 bb_annotate_all_lines
= TRUE
;
367 create_annotation_files
= TRUE
;
370 ignore_zeros
= FALSE
;
375 sym_id_add (optarg
, EXCL_EXEC
);
376 output_style
|= STYLE_EXEC_COUNTS
;
380 output_style
&= ~STYLE_EXEC_COUNTS
;
382 user_specified
|= STYLE_ANNOTATED_SOURCE
;
389 /* append value of GPROF_PATH to source search list if set: */
390 str
= getenv ("GPROF_PATH");
393 search_list_append (&src_search_list
, str
);
398 a_out_name
= argv
[optind
++];
402 gmon_name
= argv
[optind
++];
406 * Turn off default functions:
408 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
410 sym_id_add (*sp
, EXCL_TIME
);
411 sym_id_add (*sp
, EXCL_GRAPH
);
413 sym_id_add (*sp
, EXCL_FLAT
);
418 * For line-by-line profiling, also want to keep those
419 * functions off the flat profile:
421 if (line_granularity
)
423 for (sp
= &default_excluded_list
[0]; *sp
; sp
++)
425 sym_id_add (*sp
, EXCL_FLAT
);
430 * Read symbol table from core file:
432 core_init (a_out_name
);
435 * If we should ignore direct function calls, we need to load
436 * to core's text-space:
438 if (ignore_direct_calls
)
440 core_get_text_space (core_bfd
);
444 * Create symbols from core image:
446 if (line_granularity
)
448 core_create_line_syms (core_bfd
);
452 core_create_function_syms (core_bfd
);
456 * Translate sym specs into syms:
460 if (file_format
== FF_PROF
)
462 #ifdef PROF_SUPPORT_IMPLEMENTED
464 * Get information about mon.out file(s):
468 mon_out_read (gmon_name
);
471 gmon_name
= argv
[optind
];
474 while (optind
++ < argc
);
477 "%s: sorry, file format `prof' is not yet supported\n",
485 * Get information about gmon.out file(s):
489 gmon_out_read (gmon_name
);
492 gmon_name
= argv
[optind
];
495 while (optind
++ < argc
);
499 * If user did not specify output style, try to guess something
502 if (output_style
== 0)
504 if (gmon_input
& (INPUT_HISTOGRAM
| INPUT_CALL_GRAPH
))
506 output_style
= STYLE_FLAT_PROFILE
| STYLE_CALL_GRAPH
;
510 output_style
= STYLE_EXEC_COUNTS
;
512 output_style
&= ~user_specified
;
516 * Dump a gmon.sum file if requested (before any other processing!):
518 if (output_style
& STYLE_SUMMARY_FILE
)
520 gmon_out_write (GMONSUM
);
523 if (gmon_input
& INPUT_HISTOGRAM
)
525 hist_assign_samples ();
528 if (gmon_input
& INPUT_CALL_GRAPH
)
533 /* do some simple sanity checks: */
535 if ((output_style
& STYLE_FLAT_PROFILE
)
536 && !(gmon_input
& INPUT_HISTOGRAM
))
538 fprintf (stderr
, "%s: gmon.out file is missing histogram\n", whoami
);
542 if ((output_style
& STYLE_CALL_GRAPH
) && !(gmon_input
& INPUT_CALL_GRAPH
))
545 "%s: gmon.out file is missing call-graph data\n", whoami
);
549 /* output whatever user whishes to see: */
551 if (cg
&& (output_style
& STYLE_CALL_GRAPH
) && bsd_style_output
)
553 cg_print (cg
); /* print the dynamic profile */
556 if (output_style
& STYLE_FLAT_PROFILE
)
558 hist_print (); /* print the flat profile */
561 if (cg
&& (output_style
& STYLE_CALL_GRAPH
))
563 if (!bsd_style_output
)
565 cg_print (cg
); /* print the dynamic profile */
570 if (output_style
& STYLE_EXEC_COUNTS
)
572 print_exec_counts ();
575 if (output_style
& STYLE_ANNOTATED_SOURCE
)
577 print_annotated_source ();
This page took 0.040853 seconds and 4 git commands to generate.