Skip to content

Commit 610723f

Browse files
dsahernacmel
authored andcommitted
perf script: Make printing of dso a separate field option
The 'sym' option displays both the function name and the DSO it comes from. Split the display of the dso into a separate option. This allows display of the ip address and symbol without the dso, thus shortening line lengths - and decluttering the output a bit. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1306528124-25861-3-git-send-email-dsahern@gmail.com Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 787bef1 commit 610723f

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎tools/perf/Documentation/perf-script.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ OPTIONS
115115
-f::
116116
--fields::
117117
Comma separated list of fields to print. Options are:
118-
comm, tid, pid, time, cpu, event, trace, ip, sym. Field
118+
comm, tid, pid, time, cpu, event, trace, ip, sym, dso. Field
119119
list can be prepended with the type, trace, sw or hw,
120120
to indicate to which event type the field list applies.
121121
e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace

‎tools/perf/builtin-script.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum perf_output_field {
3232
PERF_OUTPUT_TRACE = 1U << 6,
3333
PERF_OUTPUT_IP = 1U << 7,
3434
PERF_OUTPUT_SYM = 1U << 8,
35+
PERF_OUTPUT_DSO = 1U << 9,
3536
};
3637

3738
struct output_option {
@@ -47,6 +48,7 @@ struct output_option {
4748
{.str = "trace", .field = PERF_OUTPUT_TRACE},
4849
{.str = "ip", .field = PERF_OUTPUT_IP},
4950
{.str = "sym", .field = PERF_OUTPUT_SYM},
51+
{.str = "dso", .field = PERF_OUTPUT_DSO},
5052
};
5153

5254
/* default set to maintain compatibility with current format */
@@ -63,7 +65,7 @@ static struct {
6365
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
6466
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
6567
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
66-
PERF_OUTPUT_SYM,
68+
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
6769

6870
.invalid_fields = PERF_OUTPUT_TRACE,
6971
},
@@ -74,7 +76,7 @@ static struct {
7476
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
7577
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
7678
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
77-
PERF_OUTPUT_SYM,
79+
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
7880

7981
.invalid_fields = PERF_OUTPUT_TRACE,
8082
},
@@ -93,7 +95,7 @@ static struct {
9395
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
9496
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
9597
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
96-
PERF_OUTPUT_SYM,
98+
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
9799

98100
.invalid_fields = PERF_OUTPUT_TRACE,
99101
},
@@ -176,6 +178,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
176178
"No addresses to convert to symbols.\n");
177179
return -EINVAL;
178180
}
181+
if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP)) {
182+
pr_err("Display of DSO requested but IP is not selected.\n"
183+
"No addresses to convert to dso.\n");
184+
return -EINVAL;
185+
}
179186

180187
if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
181188
perf_event_attr__check_stype(attr, PERF_SAMPLE_TID, "TID",
@@ -304,7 +311,7 @@ static void process_event(union perf_event *event __unused,
304311
else
305312
printf("\n");
306313
perf_session__print_ip(event, sample, session,
307-
PRINT_FIELD(SYM));
314+
PRINT_FIELD(SYM), PRINT_FIELD(DSO));
308315
}
309316

310317
printf("\n");
@@ -996,7 +1003,7 @@ static const struct option options[] = {
9961003
OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
9971004
"Look for files with symbols relative to this directory"),
9981005
OPT_CALLBACK('f', "fields", NULL, "str",
999-
"comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym",
1006+
"comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso",
10001007
parse_output_fields),
10011008

10021009
OPT_END()

‎tools/perf/util/session.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
12051205
void perf_session__print_ip(union perf_event *event,
12061206
struct perf_sample *sample,
12071207
struct perf_session *session,
1208-
int print_sym)
1208+
int print_sym, int print_dso)
12091209
{
12101210
struct addr_location al;
12111211
const char *symname, *dsoname;
@@ -1241,12 +1241,15 @@ void perf_session__print_ip(union perf_event *event,
12411241
else
12421242
symname = "";
12431243

1244+
printf(" %s", symname);
1245+
}
1246+
if (print_dso) {
12441247
if (node->map && node->map->dso && node->map->dso->name)
12451248
dsoname = node->map->dso->name;
12461249
else
12471250
dsoname = "";
12481251

1249-
printf(" %s (%s)", symname, dsoname);
1252+
printf(" (%s)", dsoname);
12501253
}
12511254
printf("\n");
12521255

@@ -1261,12 +1264,16 @@ void perf_session__print_ip(union perf_event *event,
12611264
else
12621265
symname = "";
12631266

1267+
printf(" %s", symname);
1268+
}
1269+
1270+
if (print_dso) {
12641271
if (al.map && al.map->dso && al.map->dso->name)
12651272
dsoname = al.map->dso->name;
12661273
else
12671274
dsoname = "";
12681275

1269-
printf(" %s (%s)", symname, dsoname);
1276+
printf(" (%s)", dsoname);
12701277
}
12711278
}
12721279
}

‎tools/perf/util/session.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,6 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
170170
void perf_session__print_ip(union perf_event *event,
171171
struct perf_sample *sample,
172172
struct perf_session *session,
173-
int print_sym);
173+
int print_sym, int print_dso);
174174

175175
#endif /* __PERF_SESSION_H */

0 commit comments

Comments
 (0)