diff options
author | Robert Richter <robert.richter@amd.com> | 2012-02-10 09:41:56 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-02-13 20:33:36 -0500 |
commit | f1c67db7e351bf9fd328e368ba045cbeca11d513 (patch) | |
tree | f5992c509c655873da19c995b740ce89b60a216f /tools/perf/util | |
parent | 08d95bd256277f914e525aeb292da52f15173e7d (diff) |
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>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/header.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 5bb2d752ab8..9f867d96c6a 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1466,25 +1466,48 @@ out: | |||
1466 | return err; | 1466 | return err; |
1467 | } | 1467 | } |
1468 | 1468 | ||
1469 | static int process_trace_info(struct perf_file_section *section __unused, | ||
1470 | struct perf_header *ph __unused, | ||
1471 | int feat __unused, int fd) | ||
1472 | { | ||
1473 | trace_report(fd, false); | ||
1474 | return 0; | ||
1475 | } | ||
1476 | |||
1477 | static int process_build_id(struct perf_file_section *section, | ||
1478 | struct perf_header *ph, | ||
1479 | int feat __unused, int fd) | ||
1480 | { | ||
1481 | if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) | ||
1482 | pr_debug("Failed to read buildids, continuing...\n"); | ||
1483 | return 0; | ||
1484 | } | ||
1485 | |||
1469 | struct feature_ops { | 1486 | struct feature_ops { |
1470 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); | 1487 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); |
1471 | void (*print)(struct perf_header *h, int fd, FILE *fp); | 1488 | void (*print)(struct perf_header *h, int fd, FILE *fp); |
1489 | int (*process)(struct perf_file_section *section, | ||
1490 | struct perf_header *h, int feat, int fd); | ||
1472 | const char *name; | 1491 | const char *name; |
1473 | bool full_only; | 1492 | bool full_only; |
1474 | }; | 1493 | }; |
1475 | 1494 | ||
1476 | #define FEAT_OPA(n, func) \ | 1495 | #define FEAT_OPA(n, func) \ |
1477 | [n] = { .name = #n, .write = write_##func, .print = print_##func } | 1496 | [n] = { .name = #n, .write = write_##func, .print = print_##func } |
1497 | #define FEAT_OPP(n, func) \ | ||
1498 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ | ||
1499 | .process = process_##func } | ||
1478 | #define FEAT_OPF(n, func) \ | 1500 | #define FEAT_OPF(n, func) \ |
1479 | [n] = { .name = #n, .write = write_##func, .print = print_##func, .full_only = true } | 1501 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ |
1502 | .full_only = true } | ||
1480 | 1503 | ||
1481 | /* feature_ops not implemented: */ | 1504 | /* feature_ops not implemented: */ |
1482 | #define print_trace_info NULL | 1505 | #define print_trace_info NULL |
1483 | #define print_build_id NULL | 1506 | #define print_build_id NULL |
1484 | 1507 | ||
1485 | static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { | 1508 | static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { |
1486 | FEAT_OPA(HEADER_TRACE_INFO, trace_info), | 1509 | FEAT_OPP(HEADER_TRACE_INFO, trace_info), |
1487 | FEAT_OPA(HEADER_BUILD_ID, build_id), | 1510 | FEAT_OPP(HEADER_BUILD_ID, build_id), |
1488 | FEAT_OPA(HEADER_HOSTNAME, hostname), | 1511 | FEAT_OPA(HEADER_HOSTNAME, hostname), |
1489 | FEAT_OPA(HEADER_OSRELEASE, osrelease), | 1512 | FEAT_OPA(HEADER_OSRELEASE, osrelease), |
1490 | FEAT_OPA(HEADER_VERSION, version), | 1513 | FEAT_OPA(HEADER_VERSION, version), |
@@ -1900,19 +1923,10 @@ static int perf_file_section__process(struct perf_file_section *section, | |||
1900 | return 0; | 1923 | return 0; |
1901 | } | 1924 | } |
1902 | 1925 | ||
1903 | switch (feat) { | 1926 | if (!feat_ops[feat].process) |
1904 | case HEADER_TRACE_INFO: | 1927 | return 0; |
1905 | trace_report(fd, false); | ||
1906 | break; | ||
1907 | case HEADER_BUILD_ID: | ||
1908 | if (perf_header__read_build_ids(ph, fd, section->offset, section->size)) | ||
1909 | pr_debug("Failed to read buildids, continuing...\n"); | ||
1910 | break; | ||
1911 | default: | ||
1912 | break; | ||
1913 | } | ||
1914 | 1928 | ||
1915 | return 0; | 1929 | return feat_ops[feat].process(section, ph, feat, fd); |
1916 | } | 1930 | } |
1917 | 1931 | ||
1918 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, | 1932 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, |