Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1224304
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 01/27] perf tests: Take into account address of each objdump line |
| Date | 2015-09-14 18:40 +0200 |
| Message-ID | <q8EXo-3f1-25@gated-at.bofh.it> (permalink) |
| References | <q8EXn-3f1-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Jan Stancek <jstancek@redhat.com>
objdump output can contain repeated bytes. At the moment test reads all
output sequentially, assuming each address is represented in output only
once:
ffffffff8164efb3 <retint_swapgs+0x9>:
ffffffff8164efb3: c1 5d 00 eb rcrl $0xeb,0x0(%rbp)
ffffffff8164efb7: 00 4c 8b 5c add %cl,0x5c(%rbx,%rcx,4)
ffffffff8164efb8 <restore_c_regs_and_iret>:
ffffffff8164efb8: 4c 8b 5c 24 30 mov 0x30(%rsp),%r11
ffffffff8164efbd: 4c 8b 54 24 38 mov 0x38(%rsp),%r10
Store objdump output to buffer according to offset calculated from
address on each line.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/ad13289a55d6350f7717757c7e32c2d4286402bd.1441181335.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/code-reading.c | 51 ++++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 13 deletions(-)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 39c784a100a9..38ee90bc2228 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -33,20 +33,20 @@ static unsigned int hex(char c)
return c - 'A' + 10;
}
-static void read_objdump_line(const char *line, size_t line_len, void **buf,
- size_t *len)
+static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
+ size_t len)
{
const char *p;
- size_t i;
+ size_t i, j = 0;
/* Skip to a colon */
p = strchr(line, ':');
if (!p)
- return;
+ return 0;
i = p + 1 - line;
/* Read bytes */
- while (*len) {
+ while (j < len) {
char c1, c2;
/* Skip spaces */
@@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf,
if (i < line_len && line[i] && !isspace(line[i]))
break;
/* Store byte */
- *(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);
- *buf += 1;
- *len -= 1;
+ *(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
+ buf += 1;
+ j++;
}
+ /* return number of successfully read bytes */
+ return j;
}
-static int read_objdump_output(FILE *f, void **buf, size_t *len)
+static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
{
char *line = NULL;
- size_t line_len;
+ size_t line_len, off_last = 0;
ssize_t ret;
int err = 0;
+ u64 addr;
+
+ while (off_last < *len) {
+ size_t off, read_bytes, written_bytes;
+ unsigned char tmp[BUFSZ];
- while (1) {
ret = getline(&line, &line_len, f);
if (feof(f))
break;
@@ -87,9 +93,28 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len)
err = -1;
break;
}
- read_objdump_line(line, ret, buf, len);
+
+ /* read objdump data into temporary buffer */
+ read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
+ if (!read_bytes)
+ continue;
+
+ if (sscanf(line, "%"PRIx64, &addr) != 1)
+ continue;
+
+ /* copy it from temporary buffer to 'buf' according
+ * to address on current objdump line */
+ off = addr - start_addr;
+ if (off >= *len)
+ break;
+ written_bytes = MIN(read_bytes, *len - off);
+ memcpy(buf + off, tmp, written_bytes);
+ off_last = off + written_bytes;
}
+ /* len returns number of bytes that could not be read */
+ *len -= off_last;
+
free(line);
return err;
@@ -120,7 +145,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
return -1;
}
- ret = read_objdump_output(f, &buf, &len);
+ ret = read_objdump_output(f, buf, &len, addr);
if (len) {
pr_debug("objdump read too few bytes\n");
if (!ret)
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/27] perf/core2 improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
[PATCH 01/27] perf tests: Take into account address of each objdump line Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
[PATCH 03/27] perf tests: Stop reading if objdump output crossed sections Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:40 +0200
[PATCH 12/27] perf env: Rename some leftovers from rename to perf_env Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 16/27] perf tools: Add tools/include into tags directories Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 14/27] perf hists browser: Fixup the "cpu" column width calculation Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 21/27] perf env: Introduce read_cpu_topology_map() method Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 19/27] tools lib api cpu: Introduce cpu.[ch] to obtain cpu related information Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 22/27] perf machine: Add pointer to sample's environment Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 11/27] perf env: Move perf_env out of header.h and session.c into separate object Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 27/27] perf test: Add entry for hists socket filter Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 15/27] perf evsel: Remove forward declaration of 'struct perf_evlist' Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 10/27] perf tests: Introduce iterator function for tests Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 20/27] perf cpu_map: Use sysfs__read_int in get_{core,socket}_id() Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 13/27] perf env: Adopt perf_header__set_cmdline Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 24/27] perf tools: Introduce new sort type "socket" for the processor socket Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 08/27] perf tools: Switch to tracing_path interface on appropriate places Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 23/27] perf tools: Add processor socket info to hist_entry and addr_location Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 25/27] perf report: Introduce --socket-filter option Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 26/27] perf hists browser: Zoom in/out for processor socket Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 18/27] tools lib api fs: Introduce sysfs__read_{int,ull}() Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 17/27] perf env: Read msr pmu type from header Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 09/27] perf test: Add entry to test cpu topology Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 18:50 +0200
[PATCH 07/27] tools lib api fs: Remove debugfs, tracefs and findfs objects Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
[PATCH 06/27] tools lib api fs: Replace debugfs/tracefs objects interface with fs.c Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
[PATCH 05/27] tools lib api fs: Make tracing_path_strerror_open message generic Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 19:00 +0200
Re: [GIT PULL 00/27] perf/core2 improvements and fixes Ingo Molnar <mingo@kernel.org> - 2015-09-15 09:00 +0200
csiph-web