diff options
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Documentation/perf-script.txt | 2 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 10 | ||||
-rw-r--r-- | tools/perf/util/map.c | 17 | ||||
-rw-r--r-- | tools/perf/util/map.h | 2 | ||||
-rw-r--r-- | tools/perf/util/session.c | 8 | ||||
-rw-r--r-- | tools/perf/util/session.h | 1 |
6 files changed, 39 insertions, 1 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index cfdbb1e045b5..c2a5071cf8f8 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt | |||
@@ -115,7 +115,7 @@ OPTIONS | |||
115 | -f:: | 115 | -f:: |
116 | --fields:: | 116 | --fields:: |
117 | Comma separated list of fields to print. Options are: | 117 | Comma separated list of fields to print. Options are: |
118 | comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff. | 118 | comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline. |
119 | Field list can be prepended with the type, trace, sw or hw, | 119 | Field list can be prepended with the type, trace, sw or hw, |
120 | to indicate to which event type the field list applies. | 120 | to indicate to which event type the field list applies. |
121 | e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace | 121 | e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4484886dcf08..7a571fb7eb8a 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -43,6 +43,7 @@ enum perf_output_field { | |||
43 | PERF_OUTPUT_DSO = 1U << 9, | 43 | PERF_OUTPUT_DSO = 1U << 9, |
44 | PERF_OUTPUT_ADDR = 1U << 10, | 44 | PERF_OUTPUT_ADDR = 1U << 10, |
45 | PERF_OUTPUT_SYMOFFSET = 1U << 11, | 45 | PERF_OUTPUT_SYMOFFSET = 1U << 11, |
46 | PERF_OUTPUT_SRCLINE = 1U << 12, | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | struct output_option { | 49 | struct output_option { |
@@ -61,6 +62,7 @@ struct output_option { | |||
61 | {.str = "dso", .field = PERF_OUTPUT_DSO}, | 62 | {.str = "dso", .field = PERF_OUTPUT_DSO}, |
62 | {.str = "addr", .field = PERF_OUTPUT_ADDR}, | 63 | {.str = "addr", .field = PERF_OUTPUT_ADDR}, |
63 | {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, | 64 | {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, |
65 | {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, | ||
64 | }; | 66 | }; |
65 | 67 | ||
66 | /* default set to maintain compatibility with current format */ | 68 | /* default set to maintain compatibility with current format */ |
@@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, | |||
210 | "to DSO.\n"); | 212 | "to DSO.\n"); |
211 | return -EINVAL; | 213 | return -EINVAL; |
212 | } | 214 | } |
215 | if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) { | ||
216 | pr_err("Display of source line number requested but sample IP is not\n" | ||
217 | "selected. Hence, no address to lookup the source line number.\n"); | ||
218 | return -EINVAL; | ||
219 | } | ||
213 | 220 | ||
214 | if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && | 221 | if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && |
215 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID", | 222 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID", |
@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr) | |||
245 | 252 | ||
246 | if (PRINT_FIELD(SYMOFFSET)) | 253 | if (PRINT_FIELD(SYMOFFSET)) |
247 | output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET; | 254 | output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET; |
255 | |||
256 | if (PRINT_FIELD(SRCLINE)) | ||
257 | output[type].print_ip_opts |= PRINT_IP_OPT_SRCLINE; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | /* | 260 | /* |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index ef5bc913ca7a..9b9bd719aa19 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include "strlist.h" | 11 | #include "strlist.h" |
12 | #include "vdso.h" | 12 | #include "vdso.h" |
13 | #include "build-id.h" | 13 | #include "build-id.h" |
14 | #include "util.h" | ||
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
15 | 16 | ||
16 | const char *map_type__name[MAP__NR_TYPES] = { | 17 | const char *map_type__name[MAP__NR_TYPES] = { |
@@ -252,6 +253,22 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) | |||
252 | return fprintf(fp, "%s", dsoname); | 253 | return fprintf(fp, "%s", dsoname); |
253 | } | 254 | } |
254 | 255 | ||
256 | int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, | ||
257 | FILE *fp) | ||
258 | { | ||
259 | char *srcline; | ||
260 | int ret = 0; | ||
261 | |||
262 | if (map && map->dso) { | ||
263 | srcline = get_srcline(map->dso, | ||
264 | map__rip_2objdump(map, addr)); | ||
265 | if (srcline != SRCLINE_UNKNOWN) | ||
266 | ret = fprintf(fp, "%s%s", prefix, srcline); | ||
267 | free_srcline(srcline); | ||
268 | } | ||
269 | return ret; | ||
270 | } | ||
271 | |||
255 | /** | 272 | /** |
256 | * map__rip_2objdump - convert symbol start address to objdump address. | 273 | * map__rip_2objdump - convert symbol start address to objdump address. |
257 | * @map: memory map | 274 | * @map: memory map |
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index e4e259c3ba16..18068c6b71c1 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -103,6 +103,8 @@ struct map *map__clone(struct map *map); | |||
103 | int map__overlap(struct map *l, struct map *r); | 103 | int map__overlap(struct map *l, struct map *r); |
104 | size_t map__fprintf(struct map *map, FILE *fp); | 104 | size_t map__fprintf(struct map *map, FILE *fp); |
105 | size_t map__fprintf_dsoname(struct map *map, FILE *fp); | 105 | size_t map__fprintf_dsoname(struct map *map, FILE *fp); |
106 | int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, | ||
107 | FILE *fp); | ||
106 | 108 | ||
107 | int map__load(struct map *map, symbol_filter_t filter); | 109 | int map__load(struct map *map, symbol_filter_t filter); |
108 | struct symbol *map__find_symbol(struct map *map, | 110 | struct symbol *map__find_symbol(struct map *map, |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c236b38ed02b..e748f29c53cf 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -1497,6 +1497,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, | |||
1497 | int print_dso = print_opts & PRINT_IP_OPT_DSO; | 1497 | int print_dso = print_opts & PRINT_IP_OPT_DSO; |
1498 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; | 1498 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; |
1499 | int print_oneline = print_opts & PRINT_IP_OPT_ONELINE; | 1499 | int print_oneline = print_opts & PRINT_IP_OPT_ONELINE; |
1500 | int print_srcline = print_opts & PRINT_IP_OPT_SRCLINE; | ||
1500 | char s = print_oneline ? ' ' : '\t'; | 1501 | char s = print_oneline ? ' ' : '\t'; |
1501 | 1502 | ||
1502 | if (symbol_conf.use_callchain && sample->callchain) { | 1503 | if (symbol_conf.use_callchain && sample->callchain) { |
@@ -1546,6 +1547,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, | |||
1546 | printf(")"); | 1547 | printf(")"); |
1547 | } | 1548 | } |
1548 | 1549 | ||
1550 | if (print_srcline) | ||
1551 | map__fprintf_srcline(node->map, addr, "\n ", | ||
1552 | stdout); | ||
1553 | |||
1549 | if (!print_oneline) | 1554 | if (!print_oneline) |
1550 | printf("\n"); | 1555 | printf("\n"); |
1551 | 1556 | ||
@@ -1575,6 +1580,9 @@ next: | |||
1575 | map__fprintf_dsoname(al->map, stdout); | 1580 | map__fprintf_dsoname(al->map, stdout); |
1576 | printf(")"); | 1581 | printf(")"); |
1577 | } | 1582 | } |
1583 | |||
1584 | if (print_srcline) | ||
1585 | map__fprintf_srcline(al->map, al->addr, "\n ", stdout); | ||
1578 | } | 1586 | } |
1579 | } | 1587 | } |
1580 | 1588 | ||
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 004d3e8116aa..2a3955ea4fd8 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -45,6 +45,7 @@ struct perf_session { | |||
45 | #define PRINT_IP_OPT_DSO (1<<2) | 45 | #define PRINT_IP_OPT_DSO (1<<2) |
46 | #define PRINT_IP_OPT_SYMOFFSET (1<<3) | 46 | #define PRINT_IP_OPT_SYMOFFSET (1<<3) |
47 | #define PRINT_IP_OPT_ONELINE (1<<4) | 47 | #define PRINT_IP_OPT_ONELINE (1<<4) |
48 | #define PRINT_IP_OPT_SRCLINE (1<<5) | ||
48 | 49 | ||
49 | struct perf_tool; | 50 | struct perf_tool; |
50 | 51 | ||