From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
David Ahern <dsahern@gmail.com>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Robert Richter <robert.richter@amd.com>,
Stephane Eranian <eranian@google.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 12/30] perf header: Add ->process callbacks to most of features
Date: Mon, 24 Sep 2012 12:59:26 -0300 [thread overview]
Message-ID: <1348502384-14442-13-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1348502384-14442-1-git-send-email-acme@infradead.org>
From: Namhyung Kim <namhyung@kernel.org>
>From now on each feature information is processed and saved in perf
header so that it can be used wherever needed. The BRANCH_STACK feature
is an exception since it needs nothing to be done.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 319 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 308 insertions(+), 11 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index ad72b28..d74b58d 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -22,6 +22,7 @@
#include "cpumap.h"
#include "pmu.h"
#include "vdso.h"
+#include "strbuf.h"
static bool no_buildid_cache = false;
@@ -1673,6 +1674,99 @@ static int process_build_id(struct perf_file_section *section,
return 0;
}
+static int process_hostname(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.hostname = do_read_string(fd, ph);
+ return ph->env.hostname ? 0 : -ENOMEM;
+}
+
+static int process_osrelease(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.os_release = do_read_string(fd, ph);
+ return ph->env.os_release ? 0 : -ENOMEM;
+}
+
+static int process_version(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.version = do_read_string(fd, ph);
+ return ph->env.version ? 0 : -ENOMEM;
+}
+
+static int process_arch(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.arch = do_read_string(fd, ph);
+ return ph->env.arch ? 0 : -ENOMEM;
+}
+
+static int process_nrcpus(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cpus_online = nr;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cpus_avail = nr;
+ return 0;
+}
+
+static int process_cpudesc(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.cpu_desc = do_read_string(fd, ph);
+ return ph->env.cpu_desc ? 0 : -ENOMEM;
+}
+
+static int process_cpuid(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.cpuid = do_read_string(fd, ph);
+ return ph->env.cpuid ? 0 : -ENOMEM;
+}
+
+static int process_total_mem(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ uint64_t mem;
+ size_t ret;
+
+ ret = read(fd, &mem, sizeof(mem));
+ if (ret != sizeof(mem))
+ return -1;
+
+ if (ph->needs_swap)
+ mem = bswap_64(mem);
+
+ ph->env.total_mem = mem;
+ return 0;
+}
+
static char *read_cpuid(struct perf_header *ph, int fd)
{
return do_read_string(fd, ph);
@@ -1728,6 +1822,208 @@ process_event_desc(struct perf_file_section *section __maybe_unused,
return 0;
}
+static int process_cmdline(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ char *str;
+ u32 nr, i;
+ struct strbuf sb;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cmdline = nr;
+ strbuf_init(&sb, 128);
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.cmdline = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_cpu_topology(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr, i;
+ char *str;
+ struct strbuf sb;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_sibling_cores = nr;
+ strbuf_init(&sb, 128);
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.sibling_cores = strbuf_detach(&sb, NULL);
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_sibling_threads = nr;
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.sibling_threads = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_numa_topology(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr, node, i;
+ char *str;
+ uint64_t mem_total, mem_free;
+ struct strbuf sb;
+
+ /* nr nodes */
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ goto error;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_numa_nodes = nr;
+ strbuf_init(&sb, 256);
+
+ for (i = 0; i < nr; i++) {
+ /* node number */
+ ret = read(fd, &node, sizeof(node));
+ if (ret != sizeof(node))
+ goto error;
+
+ ret = read(fd, &mem_total, sizeof(u64));
+ if (ret != sizeof(u64))
+ goto error;
+
+ ret = read(fd, &mem_free, sizeof(u64));
+ if (ret != sizeof(u64))
+ goto error;
+
+ if (ph->needs_swap) {
+ node = bswap_32(node);
+ mem_total = bswap_64(mem_total);
+ mem_free = bswap_64(mem_free);
+ }
+
+ strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":",
+ node, mem_total, mem_free);
+
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.numa_nodes = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_pmu_mappings(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ char *name;
+ u32 pmu_num;
+ u32 type;
+ struct strbuf sb;
+
+ ret = read(fd, &pmu_num, sizeof(pmu_num));
+ if (ret != sizeof(pmu_num))
+ return -1;
+
+ if (ph->needs_swap)
+ pmu_num = bswap_32(pmu_num);
+
+ if (!pmu_num) {
+ pr_debug("pmu mappings not available\n");
+ return 0;
+ }
+
+ ph->env.nr_pmu_mappings = pmu_num;
+ strbuf_init(&sb, 128);
+
+ while (pmu_num) {
+ if (read(fd, &type, sizeof(type)) != sizeof(type))
+ goto error;
+ if (ph->needs_swap)
+ type = bswap_32(type);
+
+ name = do_read_string(fd, ph);
+ if (!name)
+ goto error;
+
+ strbuf_addf(&sb, "%u:%s", type, name);
+ /* include a NULL character at the end */
+ strbuf_add(&sb, "", 1);
+
+ free(name);
+ pmu_num--;
+ }
+ ph->env.pmu_mappings = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
struct feature_ops {
int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
void (*print)(struct perf_header *h, int fd, FILE *fp);
@@ -1745,10 +2041,11 @@ struct feature_ops {
.process = process_##func }
#define FEAT_OPF(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
- .full_only = true }
+ .process = process_##func, .full_only = true }
#define FEAT_OPA_R(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
- .read = read_##func }
+ .read = read_##func, .process = process_##func, \
+ .full_only = true }
/* feature_ops not implemented: */
#define print_tracing_data NULL
@@ -1757,20 +2054,20 @@ struct feature_ops {
static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPP(HEADER_TRACING_DATA, tracing_data),
FEAT_OPP(HEADER_BUILD_ID, build_id),
- FEAT_OPA(HEADER_HOSTNAME, hostname),
- FEAT_OPA(HEADER_OSRELEASE, osrelease),
- FEAT_OPA(HEADER_VERSION, version),
- FEAT_OPA(HEADER_ARCH, arch),
- FEAT_OPA(HEADER_NRCPUS, nrcpus),
- FEAT_OPA(HEADER_CPUDESC, cpudesc),
+ FEAT_OPP(HEADER_HOSTNAME, hostname),
+ FEAT_OPP(HEADER_OSRELEASE, osrelease),
+ FEAT_OPP(HEADER_VERSION, version),
+ FEAT_OPP(HEADER_ARCH, arch),
+ FEAT_OPP(HEADER_NRCPUS, nrcpus),
+ FEAT_OPP(HEADER_CPUDESC, cpudesc),
FEAT_OPA_R(HEADER_CPUID, cpuid),
- FEAT_OPA(HEADER_TOTAL_MEM, total_mem),
+ FEAT_OPP(HEADER_TOTAL_MEM, total_mem),
FEAT_OPP(HEADER_EVENT_DESC, event_desc),
- FEAT_OPA(HEADER_CMDLINE, cmdline),
+ FEAT_OPP(HEADER_CMDLINE, cmdline),
FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology),
FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology),
FEAT_OPA(HEADER_BRANCH_STACK, branch_stack),
- FEAT_OPA(HEADER_PMU_MAPPINGS, pmu_mappings),
+ FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings),
};
struct header_print_data {
--
1.7.1
next prev parent reply other threads:[~2012-09-24 16:05 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 02/30] perf tools: Fix a compiling error in util/map.c Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 03/30] perf record: Print event causing perf_event_open() to fail Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 04/30] perf tools: Fix parallel build Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 06/30] perf kvm: Events analysis tool Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 07/30] perf kvm: Use perf_evsel__intval Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 09/30] perf lock: " Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 11/30] perf header: Add struct perf_session_env Arnaldo Carvalho de Melo
2012-09-24 15:59 ` Arnaldo Carvalho de Melo [this message]
2012-09-24 15:59 ` [PATCH 13/30] perf header: Use pre-processed session env when printing Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 16/30] perf header: Remove perf_header__read_feature Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 17/30] perf tools: remove sscanf extension %as Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 18/30] tools lib traceevent: Fix error path on process_array() Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
2012-09-24 23:58 ` Mike Frysinger
2012-09-25 6:47 ` Markus Trippelsdorf
2012-09-25 16:40 ` Mike Frysinger
2012-09-24 15:59 ` [PATCH 23/30] tools lib traceevent: Use asprintf were applicable Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 24/30] tools lib traceevent: Use calloc " Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 25/30] tools lib traceevent: Fix afterlife gotos Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 26/30] tools lib traceevent: Remove some die() calls Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
2012-09-25 4:15 ` Namhyung Kim
2012-09-25 11:12 ` Arnaldo Carvalho de Melo
2012-09-25 12:25 ` [PATCH] tools lib traceevent: Fix error path on pevent_parse_event Namhyung Kim
2012-09-27 5:51 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
2012-09-25 4:26 ` Namhyung Kim
2012-09-25 11:28 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
2012-09-25 4:31 ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure Arnaldo Carvalho de Melo
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=1348502384-14442-13-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=robert.richter@amd.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).