[PATCH 5/7] perf header: Add ->process callbacks to most of features
>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. Cc: Stephane Eranian Cc: Robert Richter Signed-off-by: Namhyung Kim --- tools/perf/util/header.c | 318 +-- 1 file changed, 307 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 43425b75f0c9..9c6ab1b52a07 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -21,6 +21,7 @@ #include "debug.h" #include "cpumap.h" #include "pmu.h" +#include "strbuf.h" static bool no_buildid_cache = false; @@ -1638,6 +1639,99 @@ static int process_build_id(struct perf_file_section *section, return 0; } +static int process_hostname(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph->info.hostname = do_read_string(fd, ph); + return ph->info.hostname ? 0 : -ENOMEM; +} + +static int process_osrelease(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + ph->info.os_release = do_read_string(fd, ph); + return ph->info.os_release ? 0 : -ENOMEM; +} + +static int process_version(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph->info.version = do_read_string(fd, ph); + return ph->info.version ? 0 : -ENOMEM; +} + +static int process_arch(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph->info.arch = do_read_string(fd, ph); + return ph->info.arch ? 0 : -ENOMEM; +} + +static int process_nrcpus(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + size_t ret; + u32 nr; + + ret = read(fd, , sizeof(nr)); + if (ret != sizeof(nr)) + return -1; + + if (ph->needs_swap) + nr = bswap_32(nr); + + ph->info.nr_cpus_online = nr; + + ret = read(fd, , sizeof(nr)); + if (ret != sizeof(nr)) + return -1; + + if (ph->needs_swap) + nr = bswap_32(nr); + + ph->info.nr_cpus_avail = nr; + return 0; +} + +static int process_cpudesc(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph->info.cpu_desc = do_read_string(fd, ph); + return ph->info.cpu_desc ? 0 : -ENOMEM; +} + +static int process_cpuid(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + ph->info.cpuid = do_read_string(fd, ph); + return ph->info.cpuid ? 0 : -ENOMEM; +} + +static int process_total_mem(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + uint64_t mem; + size_t ret; + + ret = read(fd, , sizeof(mem)); + if (ret != sizeof(mem)) + return -1; + + if (ph->needs_swap) + mem = bswap_64(mem); + + ph->info.total_mem = mem; + return 0; +} + static struct perf_evsel * perf_evlist__find_by_index(struct perf_evlist *evlist, int idx) { @@ -1688,6 +1782,208 @@ process_event_desc(struct perf_file_section *section __unused, return 0; } +static int process_cmdline(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + size_t ret; + char *str; + u32 nr, i; + struct strbuf sb; + + ret = read(fd, , sizeof(nr)); + if (ret != sizeof(nr)) + return -1; + + if (ph->needs_swap) + nr = bswap_32(nr); + + ph->info.nr_cmdline = nr; + strbuf_init(, 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(, str, strlen(str) + 1); + free(str); + } + ph->info.cmdline = strbuf_detach(, NULL); + return 0; + +error: + strbuf_release(); + return -1; +} + +static int process_cpu_topology(struct perf_file_section *section __unused, +
[PATCH 5/7] perf header: Add -process callbacks to most of features
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. Cc: Stephane Eranian eran...@google.com Cc: Robert Richter robert.rich...@amd.com Signed-off-by: Namhyung Kim namhy...@kernel.org --- tools/perf/util/header.c | 318 +-- 1 file changed, 307 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 43425b75f0c9..9c6ab1b52a07 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -21,6 +21,7 @@ #include debug.h #include cpumap.h #include pmu.h +#include strbuf.h static bool no_buildid_cache = false; @@ -1638,6 +1639,99 @@ static int process_build_id(struct perf_file_section *section, return 0; } +static int process_hostname(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph-info.hostname = do_read_string(fd, ph); + return ph-info.hostname ? 0 : -ENOMEM; +} + +static int process_osrelease(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + ph-info.os_release = do_read_string(fd, ph); + return ph-info.os_release ? 0 : -ENOMEM; +} + +static int process_version(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph-info.version = do_read_string(fd, ph); + return ph-info.version ? 0 : -ENOMEM; +} + +static int process_arch(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph-info.arch = do_read_string(fd, ph); + return ph-info.arch ? 0 : -ENOMEM; +} + +static int process_nrcpus(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + 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-info.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-info.nr_cpus_avail = nr; + return 0; +} + +static int process_cpudesc(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + ph-info.cpu_desc = do_read_string(fd, ph); + return ph-info.cpu_desc ? 0 : -ENOMEM; +} + +static int process_cpuid(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + ph-info.cpuid = do_read_string(fd, ph); + return ph-info.cpuid ? 0 : -ENOMEM; +} + +static int process_total_mem(struct perf_file_section *section __unused, +struct perf_header *ph, +int feat __unused, int fd, void *data __used) +{ + 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-info.total_mem = mem; + return 0; +} + static struct perf_evsel * perf_evlist__find_by_index(struct perf_evlist *evlist, int idx) { @@ -1688,6 +1782,208 @@ process_event_desc(struct perf_file_section *section __unused, return 0; } +static int process_cmdline(struct perf_file_section *section __unused, + struct perf_header *ph, + int feat __unused, int fd, void *data __used) +{ + 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-info.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-info.cmdline = strbuf_detach(sb, NULL); + return 0; + +error: + strbuf_release(sb); + return -1; +} + +static int process_cpu_topology(struct