From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
paulus@samba.org, cjashfor@linux.vnet.ibm.com,
fweisbec@gmail.com
Cc: eranian@google.com, gorcunov@openvz.org, tzanussi@gmail.com,
mhiramat@redhat.com, robert.richter@amd.com, fche@redhat.com,
linux-kernel@vger.kernel.org, masami.hiramatsu.pt@hitachi.com,
drepper@gmail.com, asharma@fb.com,
benjamin.redelings@nescent.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 13/17] perf, tool: Support user regs and stack in sample parsing
Date: Sun, 22 Jul 2012 14:14:36 +0200 [thread overview]
Message-ID: <1342959280-5361-14-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1342959280-5361-1-git-send-email-jolsa@redhat.com>
Adding following info to be parsed out of the event sample:
- user register set
- user stack dump
Both are global and specific to all events within the session.
This info will be used in the unwind patches coming in shortly.
Adding simple output printout (report -D) for both register and
stack dumps.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
tools/perf/builtin-test.c | 4 ++--
tools/perf/util/event.h | 16 +++++++++++++++-
tools/perf/util/evlist.c | 8 ++++++++
tools/perf/util/evlist.h | 1 +
tools/perf/util/evsel.c | 30 +++++++++++++++++++++++++++++-
| 2 ++
tools/perf/util/python.c | 3 ++-
tools/perf/util/session.c | 36 ++++++++++++++++++++++++++++++++++++
tools/perf/util/session.h | 8 ++++++--
9 files changed, 101 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 5ce3030..5d59398 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -564,7 +564,7 @@ static int test__basic_mmap(void)
}
err = perf_event__parse_sample(event, attr.sample_type, sample_size,
- false, &sample, false);
+ false, 0, &sample, false);
if (err) {
pr_err("Can't parse sample, err = %d\n", err);
goto out_munmap;
@@ -790,7 +790,7 @@ static int test__PERF_RECORD(void)
err = perf_event__parse_sample(event, sample_type,
sample_size, true,
- &sample, false);
+ 0, &sample, false);
if (err < 0) {
if (verbose)
perf_event__fprintf(event, stderr);
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1b19728..ed978eb 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -69,6 +69,16 @@ struct sample_event {
u64 array[];
};
+struct regs_dump {
+ u64 *regs;
+};
+
+struct stack_dump {
+ u16 offset;
+ u64 size;
+ char *data;
+};
+
struct perf_sample {
u64 ip;
u32 pid, tid;
@@ -82,6 +92,8 @@ struct perf_sample {
void *raw_data;
struct ip_callchain *callchain;
struct branch_stack *branch_stack;
+ struct regs_dump user_regs;
+ struct stack_dump user_stack;
};
#define BUILD_ID_SIZE 20
@@ -199,7 +211,9 @@ const char *perf_event__name(unsigned int id);
int perf_event__parse_sample(const union perf_event *event, u64 type,
int sample_size, bool sample_id_all,
- struct perf_sample *sample, bool swapped);
+ u64 sample_regs_user, struct perf_sample *data,
+ bool swapped);
+
int perf_event__synthesize_sample(union perf_event *event, u64 type,
const struct perf_sample *sample,
bool swapped);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f74e956..02fd2e2b 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -689,6 +689,14 @@ bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
return true;
}
+u64 perf_evlist__sample_regs_user(const struct perf_evlist *evlist)
+{
+ struct perf_evsel *first;
+
+ first = list_entry(evlist->entries.next, struct perf_evsel, node);
+ return first->attr.sample_regs_user;
+}
+
u64 perf_evlist__sample_type(const struct perf_evlist *evlist)
{
struct perf_evsel *first;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 40d4d3c..8dbf46c 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -124,6 +124,7 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
+u64 perf_evlist__sample_regs_user(const struct perf_evlist *evlist);
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
struct list_head *list,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e817713..3a284b1 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -8,6 +8,7 @@
*/
#include <byteswap.h>
+#include <linux/bitops.h>
#include "asm/bug.h"
#include "evsel.h"
#include "evlist.h"
@@ -730,7 +731,8 @@ static bool sample_overlap(const union perf_event *event,
int perf_event__parse_sample(const union perf_event *event, u64 type,
int sample_size, bool sample_id_all,
- struct perf_sample *data, bool swapped)
+ u64 sample_regs_user, struct perf_sample *data,
+ bool swapped)
{
const u64 *array;
@@ -868,6 +870,32 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
sz /= sizeof(u64);
array += sz;
}
+
+ if (type & PERF_SAMPLE_REGS_USER) {
+ /* First u64 tells us if we have any regs in sample. */
+ u64 avail = *array++;
+
+ if (avail) {
+ data->user_regs.regs = (u64 *)array;
+ array += hweight_long(sample_regs_user);
+ }
+ }
+
+ if (type & PERF_SAMPLE_STACK_USER) {
+ u64 size = *array++;
+
+ data->user_stack.offset = ((char *)(array - 1)
+ - (char *) event);
+
+ if (!size) {
+ data->user_stack.size = 0;
+ } else {
+ data->user_stack.data = (char *)array;
+ array += size / sizeof(*array);
+ data->user_stack.size = *array;
+ }
+ }
+
return 0;
}
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 9678af6..d1e00c2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1815,6 +1815,8 @@ static const int attr_file_abi_sizes[] = {
[0] = PERF_ATTR_SIZE_VER0,
[1] = PERF_ATTR_SIZE_VER1,
[2] = PERF_ATTR_SIZE_VER2,
+ [3] = PERF_ATTR_SIZE_VER3,
+ [4] = PERF_ATTR_SIZE_VER4,
0,
};
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e03b58a..a35d9c9 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -807,7 +807,8 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
first = list_entry(evlist->entries.next, struct perf_evsel, node);
err = perf_event__parse_sample(event, first->attr.sample_type,
perf_evsel__sample_size(first),
- sample_id_all, &pevent->sample, false);
+ sample_id_all, 0,
+ &pevent->sample, false);
if (err)
return PyErr_Format(PyExc_OSError,
"perf: can't parse sample, err=%d", err);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8e48559..3345936 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -15,6 +15,7 @@
#include "util.h"
#include "cpumap.h"
#include "event-parse.h"
+#include "perf_regs.h"
static int perf_session__open(struct perf_session *self, bool force)
{
@@ -87,6 +88,7 @@ void perf_session__update_sample_type(struct perf_session *self)
self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
self->host_machine.id_hdr_size = self->id_hdr_size;
+ self->sample_regs_user = perf_evlist__sample_regs_user(self->evlist);
}
int perf_session__create_kernel_maps(struct perf_session *self)
@@ -860,6 +862,34 @@ static void branch_stack__printf(struct perf_sample *sample)
sample->branch_stack->entries[i].to);
}
+static void regs_dump__printf(u64 mask, u64 *regs)
+{
+ unsigned rid, i = 0;
+
+ for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
+ u64 val = regs[i++];
+
+ printf(".... %-5s 0x%" PRIx64 "\n",
+ perf_reg_name(rid), val);
+ }
+}
+
+static void regs_user__printf(struct perf_sample *sample, u64 mask)
+{
+ struct regs_dump *user_regs = &sample->user_regs;
+
+ if (user_regs->regs) {
+ printf("... user regs: mask 0x%" PRIx64 "\n", mask);
+ regs_dump__printf(mask, user_regs->regs);
+ }
+}
+
+static void stack_user__printf(struct stack_dump *dump)
+{
+ printf("... ustack: size %" PRIu64 ", offset 0x%x\n",
+ dump->size, dump->offset);
+}
+
static void perf_session__print_tstamp(struct perf_session *session,
union perf_event *event,
struct perf_sample *sample)
@@ -910,6 +940,12 @@ static void dump_sample(struct perf_session *session, union perf_event *event,
if (session->sample_type & PERF_SAMPLE_BRANCH_STACK)
branch_stack__printf(sample);
+
+ if (session->sample_type & PERF_SAMPLE_REGS_USER)
+ regs_user__printf(sample, session->sample_regs_user);
+
+ if (session->sample_type & PERF_SAMPLE_STACK_USER)
+ stack_user__printf(&sample->user_stack);
}
static struct machine *
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7c435bd..3436064 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -43,6 +43,7 @@ struct perf_session {
struct hists hists;
u64 sample_type;
int sample_size;
+ u64 sample_regs_user;
int fd;
bool fd_pipe;
bool repipe;
@@ -134,9 +135,12 @@ static inline int perf_session__parse_sample(struct perf_session *session,
const union perf_event *event,
struct perf_sample *sample)
{
- return perf_event__parse_sample(event, session->sample_type,
+ return perf_event__parse_sample(event,
+ session->sample_type,
session->sample_size,
- session->sample_id_all, sample,
+ session->sample_id_all,
+ session->sample_regs_user,
+ sample,
session->header.needs_swap);
}
--
1.7.7.6
next prev parent reply other threads:[~2012-07-22 12:17 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-22 12:14 [PATCHv7 00/17] perf: Add backtrace post dwarf unwind Jiri Olsa
2012-07-22 12:14 ` [PATCH 01/17] perf: Unified API to record selective sets of arch registers Jiri Olsa
2012-07-25 16:12 ` Frederic Weisbecker
2012-07-26 17:51 ` Arnaldo Carvalho de Melo
2012-07-29 22:45 ` Paul Mackerras
2012-07-22 12:14 ` [PATCH 02/17] perf: Add ability to attach user level registers dump to sample Jiri Olsa
2012-07-25 16:13 ` Frederic Weisbecker
2012-07-25 17:00 ` Arnaldo Carvalho de Melo
2012-07-25 17:39 ` Stephane Eranian
2012-07-25 18:27 ` Jiri Olsa
2012-07-26 17:42 ` Stephane Eranian
2012-07-26 17:58 ` Jiri Olsa
2012-07-22 12:14 ` [PATCH 03/17] perf, x86: Add copy_from_user_nmi_nochk for best effort copy Jiri Olsa
2012-07-25 16:11 ` Frederic Weisbecker
2012-07-25 17:16 ` Jiri Olsa
2012-07-25 17:25 ` Frederic Weisbecker
2012-07-25 17:30 ` Jiri Olsa
2012-07-25 17:35 ` Frederic Weisbecker
2012-08-02 18:47 ` Andy Lutomirski
2012-08-03 11:12 ` Jiri Olsa
2012-07-22 12:14 ` [PATCH 04/17] perf: Factor __output_copy to be usable with specific copy function Jiri Olsa
2012-07-22 12:14 ` [PATCH 05/17] perf: Add perf_output_skip function to skip bytes in sample Jiri Olsa
2012-07-22 12:14 ` [PATCH 06/17] perf: Add ability to attach user stack dump to sample Jiri Olsa
2012-07-25 16:36 ` Frederic Weisbecker
2012-07-25 17:03 ` Jiri Olsa
2012-07-22 12:14 ` [PATCH 07/17] perf: Add attribute to filter out callchains Jiri Olsa
2012-07-22 12:14 ` [PATCH 08/17] perf, tool: Adding PERF_ATTR_SIZE_VER2 to the header swap check Jiri Olsa
2012-07-22 12:14 ` [PATCH 09/17] perf, tool: Factor DSO symtab types to generic binary types Jiri Olsa
2012-07-25 19:24 ` [tip:perf/core] perf symbols: " tip-bot for Jiri Olsa
2012-07-22 12:14 ` [PATCH 10/17] perf, tool: Add interface to read DSO image data Jiri Olsa
2012-07-25 19:25 ` [tip:perf/core] perf symbols: " tip-bot for Jiri Olsa
2012-07-22 12:14 ` [PATCH 11/17] perf, tool: Add interface to arch registers sets Jiri Olsa
2012-07-22 12:14 ` [PATCH 12/17] perf, tool: Add libunwind dependency for dwarf cfi unwinding Jiri Olsa
2012-07-22 12:14 ` Jiri Olsa [this message]
2012-07-22 12:14 ` [PATCH 14/17] perf, tool: Support for dwarf cfi unwinding on post processing Jiri Olsa
2012-07-25 17:05 ` Frederic Weisbecker
2012-07-25 17:16 ` Arnaldo Carvalho de Melo
2012-07-25 17:21 ` Frederic Weisbecker
2012-07-22 12:14 ` [PATCH 15/17] perf, tool: Support for dwarf mode callchain on perf record Jiri Olsa
2012-07-22 12:14 ` [PATCH 16/17] perf, tool: Add dso data caching Jiri Olsa
2012-07-25 17:11 ` Frederic Weisbecker
2012-07-25 19:26 ` [tip:perf/core] perf symbols: " tip-bot for Jiri Olsa
2012-07-22 12:14 ` [PATCH 17/17] perf, tool: Add dso data caching tests Jiri Olsa
2012-07-25 19:28 ` [tip:perf/core] perf test: " tip-bot for Jiri Olsa
2012-07-25 17:15 ` [PATCHv7 00/17] perf: Add backtrace post dwarf unwind Frederic Weisbecker
2012-07-25 17:19 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2012-05-02 11:37 [RFCv3 " Jiri Olsa
2012-05-02 11:37 ` [PATCH 13/17] perf, tool: Support user regs and stack in sample parsing Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1342959280-5361-14-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=asharma@fb.com \
--cc=benjamin.redelings@nescent.org \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=drepper@gmail.com \
--cc=eranian@google.com \
--cc=fche@redhat.com \
--cc=fweisbec@gmail.com \
--cc=gorcunov@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mhiramat@redhat.com \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=robert.richter@amd.com \
--cc=tzanussi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).