This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] gprof: print source file names inline
- From: Conrad Hoffmann <ch at bitfehler dot net>
- To: binutils at sourceware dot org
- Date: Mon, 18 Nov 2013 20:21:04 +0100
- Subject: [PATCH] gprof: print source file names inline
- Authentication-results: sourceware.org; auth=none
Hi all,
this is my first attempt to contribute to binutils, so please excuse if
I missed anything in terms of etiquette and let me know :)
Attached is a patch agains current master that adds the option
"--inline-file-names" to gprof.
If used, gprof will print the source file and line after each symbol
name in both the flat profile and the call graph. As example, these are
the first few lines of a sample output:
http://pastebin.com/inyJ0rfP
The ouput obeys the -L option (full paths).
I find this useful for larger projects, both in terms of immediate
oversight when looking at the flat profile and the ability to
grep/search for certain things when automatically parsing the output of
gprof.
- Any interest at all in such an addition?
- What changes may be required in terms of style, naming conventions,
etc...?
- If the previous items are resolved, can patches be contributed by
mail or should I set up a repo that you can pull & merge from?
Cheers,
Conrad
diff --git a/gprof/gprof.c b/gprof/gprof.c
index 8d54538..508a024 100644
--- a/gprof/gprof.c
+++ b/gprof/gprof.c
@@ -68,6 +68,7 @@ bfd_boolean line_granularity = FALSE;
bfd_boolean print_descriptions = TRUE;
bfd_boolean print_path = FALSE;
bfd_boolean ignore_non_functions = FALSE;
+bfd_boolean inline_file_names = FALSE;
File_Format file_format = FF_AUTO;
bfd_boolean first_output = TRUE;
@@ -91,8 +92,9 @@ static char *default_excluded_list[] =
/* Codes used for the long options with no short synonyms. 150 isn't
special; it's just an arbitrary non-ASCII char value. */
-#define OPTION_DEMANGLE (150)
-#define OPTION_NO_DEMANGLE (OPTION_DEMANGLE + 1)
+#define OPTION_DEMANGLE (150)
+#define OPTION_NO_DEMANGLE (OPTION_DEMANGLE + 1)
+#define OPTION_INLINE_FILE_NAMES (OPTION_DEMANGLE + 2)
static struct option long_options[] =
{
@@ -123,6 +125,7 @@ static struct option long_options[] =
{"no-demangle", no_argument, 0, OPTION_NO_DEMANGLE},
{"directory-path", required_argument, 0, 'I'},
{"display-unused-functions", no_argument, 0, 'z'},
+ {"inline-file-names", no_argument, 0, OPTION_INLINE_FILE_NAMES},
{"min-count", required_argument, 0, 'm'},
{"print-path", no_argument, 0, 'L'},
{"separate-files", no_argument, 0, 'y'},
@@ -162,7 +165,7 @@ Usage: %s [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqSQZ][name]] [-I dirs]\n\
[--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]\n\
[--[no-]flat-profile[=name]] [--[no-]graph[=name]]\n\
[--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]\n\
- [--function-ordering] [--file-ordering]\n\
+ [--function-ordering] [--file-ordering] [--inline-file-names]\n\
[--directory-path=dirs] [--display-unused-functions]\n\
[--file-format=name] [--file-info] [--help] [--line] [--min-count=n]\n\
[--no-static] [--print-path] [--separate-files]\n\
@@ -470,6 +473,9 @@ This program is free software. This program has absolutely no warranty.\n"));
case OPTION_NO_DEMANGLE:
demangle = FALSE;
break;
+ case OPTION_INLINE_FILE_NAMES:
+ inline_file_names = TRUE;
+ break;
default:
usage (stderr, 1);
}
diff --git a/gprof/gprof.h b/gprof/gprof.h
index 69527fc..c919ea4 100644
--- a/gprof/gprof.h
+++ b/gprof/gprof.h
@@ -126,6 +126,7 @@ extern bfd_boolean line_granularity; /* function or line granularity? */
extern bfd_boolean print_descriptions; /* output profile description */
extern bfd_boolean print_path; /* print path or just filename? */
extern bfd_boolean ignore_non_functions; /* Ignore non-function symbols. */
+extern bfd_boolean inline_file_names; /* print file names after symbols */
extern File_Format file_format; /* requested file format */
diff --git a/gprof/gprof.texi b/gprof/gprof.texi
index 30f43f9..2481624 100644
--- a/gprof/gprof.texi
+++ b/gprof/gprof.texi
@@ -556,6 +556,11 @@ call graph.
If @var{symspec} is specified, @code{gprof} prints a call graph,
but excludes matching symbols.
+@item --inline-file-names
+This option causes @code{gprof} to print the source file after each
+symbol in both the flat profile and the call graph. The full path to the
+file is printed if used with the @samp{-L} option.
+
@item -t
@itemx --table-length=@var{num}
The @samp{-t} option causes the @var{num} most active source lines in
diff --git a/gprof/utils.c b/gprof/utils.c
index f349841..4fc2db6 100644
--- a/gprof/utils.c
+++ b/gprof/utils.c
@@ -58,7 +58,7 @@ print_name_only (Sym *self)
}
printf ("%s", name);
size = strlen (name);
- if (line_granularity && self->file)
+ if ((line_granularity || inline_file_names) && self->file)
{
filename = self->file->name;
if (!print_path)
@@ -73,8 +73,15 @@ print_name_only (Sym *self)
filename = self->file->name;
}
}
- sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
- (unsigned long) self->addr);
+ if (line_granularity)
+ {
+ sprintf (buf, " (%s:%d @ %lx)", filename, self->line_num,
+ (unsigned long) self->addr);
+ }
+ else
+ {
+ sprintf (buf, " (%s:%d)", filename, self->line_num);
+ }
printf ("%s", buf);
size += strlen (buf);
}