From: tip-bot for Robert Richter <robert.richter@amd.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com,
mingo@redhat.com, robert.richter@amd.com, tglx@linutronix.de,
mingo@elte.hu
Subject: [tip:perf/core] perf tools: Factor out feature op to process header sections
Date: Fri, 17 Feb 2012 01:54:47 -0800 [thread overview]
Message-ID: <tip-f1c67db7e351bf9fd328e368ba045cbeca11d513@git.kernel.org> (raw)
In-Reply-To: <1328884916-5901-2-git-send-email-robert.richter@amd.com>
Commit-ID: f1c67db7e351bf9fd328e368ba045cbeca11d513
Gitweb: http://git.kernel.org/tip/f1c67db7e351bf9fd328e368ba045cbeca11d513
Author: Robert Richter <robert.richter@amd.com>
AuthorDate: Fri, 10 Feb 2012 15:41:56 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Feb 2012 23:33:36 -0200
perf tools: Factor out feature op to process header sections
There is individual code for each feature to process header sections.
Adding a function pointer .process to struct feature_ops for keeping the
implementation in separate functions. Code to process header sections is
now a generic function.
Cc: Ingo Molnar <mingo@elte.hu>
Link: http://lkml.kernel.org/r/1328884916-5901-2-git-send-email-robert.richter@amd.com
Signed-off-by: Robert Richter <robert.richter@amd.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 44 +++++++++++++++++++++++++++++---------------
1 files changed, 29 insertions(+), 15 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 5bb2d75..9f867d9 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1466,25 +1466,48 @@ out:
return err;
}
+static int process_trace_info(struct perf_file_section *section __unused,
+ struct perf_header *ph __unused,
+ int feat __unused, int fd)
+{
+ trace_report(fd, false);
+ return 0;
+}
+
+static int process_build_id(struct perf_file_section *section,
+ struct perf_header *ph,
+ int feat __unused, int fd)
+{
+ if (perf_header__read_build_ids(ph, fd, section->offset, section->size))
+ pr_debug("Failed to read buildids, continuing...\n");
+ return 0;
+}
+
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);
+ int (*process)(struct perf_file_section *section,
+ struct perf_header *h, int feat, int fd);
const char *name;
bool full_only;
};
#define FEAT_OPA(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func }
+#define FEAT_OPP(n, func) \
+ [n] = { .name = #n, .write = write_##func, .print = print_##func, \
+ .process = process_##func }
#define FEAT_OPF(n, func) \
- [n] = { .name = #n, .write = write_##func, .print = print_##func, .full_only = true }
+ [n] = { .name = #n, .write = write_##func, .print = print_##func, \
+ .full_only = true }
/* feature_ops not implemented: */
#define print_trace_info NULL
#define print_build_id NULL
static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
- FEAT_OPA(HEADER_TRACE_INFO, trace_info),
- FEAT_OPA(HEADER_BUILD_ID, build_id),
+ FEAT_OPP(HEADER_TRACE_INFO, trace_info),
+ FEAT_OPP(HEADER_BUILD_ID, build_id),
FEAT_OPA(HEADER_HOSTNAME, hostname),
FEAT_OPA(HEADER_OSRELEASE, osrelease),
FEAT_OPA(HEADER_VERSION, version),
@@ -1900,19 +1923,10 @@ static int perf_file_section__process(struct perf_file_section *section,
return 0;
}
- switch (feat) {
- case HEADER_TRACE_INFO:
- trace_report(fd, false);
- break;
- case HEADER_BUILD_ID:
- if (perf_header__read_build_ids(ph, fd, section->offset, section->size))
- pr_debug("Failed to read buildids, continuing...\n");
- break;
- default:
- break;
- }
+ if (!feat_ops[feat].process)
+ return 0;
- return 0;
+ return feat_ops[feat].process(section, ph, feat, fd);
}
static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
next prev parent reply other threads:[~2012-02-17 9:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 16:32 [PATCH 0/4] perf tools: More fixes and updates Robert Richter
2011-12-15 16:32 ` [PATCH 1/4] perf tools: Fix uninitialized memory access to struct perf_sample Robert Richter
2011-12-21 8:41 ` [tip:perf/core] perf evsel: " tip-bot for Robert Richter
2011-12-15 16:32 ` [PATCH 2/4] perf record: Make feature initialization generic Robert Richter
2012-02-07 19:33 ` [tip:perf/core] " tip-bot for Robert Richter
2011-12-15 16:32 ` [PATCH 3/4] perf tools: Moving code in header.c Robert Richter
2011-12-15 16:32 ` [PATCH 4/4] perf tools: Factor out feature op to process header sections Robert Richter
2012-01-31 15:51 ` [PATCH 0/4] perf tools: More fixes and updates Robert Richter
2012-02-02 20:14 ` Arnaldo Carvalho de Melo
2012-02-10 11:31 ` Robert Richter
2012-02-10 14:30 ` Arnaldo Carvalho de Melo
2012-02-10 14:41 ` [PATCH 1/2] perf tools: Moving code in header.c Robert Richter
2012-02-10 14:41 ` [PATCH 2/2] perf tools: Factor out feature op to process header sections Robert Richter
2012-02-17 9:54 ` tip-bot for Robert Richter [this message]
2012-02-17 9:53 ` [tip:perf/core] perf tools: Moving code in header.c tip-bot for Robert Richter
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=tip-f1c67db7e351bf9fd328e368ba045cbeca11d513@git.kernel.org \
--to=robert.richter@amd.com \
--cc=acme@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/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).