From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 3/5] perf header: Make feat_ops->print use processed result
Date: Sun, 22 Jul 2012 01:45:33 +0900 [thread overview]
Message-ID: <1342889135-14825-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1342889135-14825-1-git-send-email-namhyung@kernel.org>
Now we have all of necessary information in the perf_header so just
use it for printing.
Cc: Stephane Eranian <eranian@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
| 219 +++++++++++++++++++---------------------------
1 file changed, 92 insertions(+), 127 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1a30f2831616..9ab1803d601d 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <linux/list.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
@@ -972,118 +973,104 @@ static int write_branch_stack(int fd __used, struct perf_header *h __used,
return 0;
}
-static void print_hostname(struct perf_header *ph, int fd, FILE *fp)
+static void print_hostname(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# hostname : %s\n", str);
- free(str);
+ fprintf(fp, "# hostname : %s\n", ph->hostname);
}
-static void print_osrelease(struct perf_header *ph, int fd, FILE *fp)
+static void print_osrelease(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# os release : %s\n", str);
- free(str);
+ fprintf(fp, "# os release : %s\n", ph->os_release);
}
-static void print_arch(struct perf_header *ph, int fd, FILE *fp)
+static void print_arch(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# arch : %s\n", str);
- free(str);
+ fprintf(fp, "# arch : %s\n", ph->arch);
}
-static void print_cpudesc(struct perf_header *ph, int fd, FILE *fp)
+static void print_cpudesc(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# cpudesc : %s\n", str);
- free(str);
+ fprintf(fp, "# cpudesc : %s\n", ph->cpu_desc);
}
-static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp)
+static void print_nrcpus(struct perf_header *ph, int fd __used, FILE *fp)
{
- ssize_t ret;
- u32 nr;
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- nr = -1; /* interpreted as error */
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
-
- fprintf(fp, "# nrcpus online : %u\n", nr);
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- nr = -1; /* interpreted as error */
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
-
- fprintf(fp, "# nrcpus avail : %u\n", nr);
+ fprintf(fp, "# nrcpus online : %u\n", ph->nr_cpus_online);
+ fprintf(fp, "# nrcpus avail : %u\n", ph->nr_cpus_avail);
}
-static void print_version(struct perf_header *ph, int fd, FILE *fp)
+static void print_version(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# perf version : %s\n", str);
- free(str);
+ fprintf(fp, "# perf version : %s\n", ph->version);
}
-static void print_cmdline(struct perf_header *ph, int fd, FILE *fp)
+static void print_cmdline(struct perf_header *ph, int fd __used, FILE *fp)
{
- ssize_t ret;
char *str;
- u32 nr, i;
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ int i;
fprintf(fp, "# cmdline : ");
- for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
+ str = ph->cmdline;
+ for (i = 0; i < ph->cmdline_argc; i++) {
+ /* each argv is null-terminated */
fprintf(fp, "%s ", str);
- free(str);
+ str += strlen(str) + 1;
}
fputc('\n', fp);
}
-static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp)
+#define TOPO_STR_DELIM ':'
+
+/* For string formatting, see process_cpu_topology() */
+static void print_cpu_topology(struct perf_header *ph, int fd __used, FILE *fp)
{
- ssize_t ret;
u32 nr, i;
char *str;
+ char *delim;
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
+ str = ph->cpu_topology;
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ nr = strtoul(str, &delim, 0);
+ if (*delim != TOPO_STR_DELIM)
+ return;
+ str = delim + 1;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
+ char c;
+
+ delim = strpbrk(str, ":\n");
+ if (!delim)
+ return;
+
+ c = *delim;
+ *delim = '\0';
fprintf(fp, "# sibling cores : %s\n", str);
- free(str);
+ *delim = c;
+
+ str = delim + 1;
}
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
+ BUG_ON(*(str-1) != '\n');
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ nr = strtoul(str, &delim, 0);
+ if (*delim != TOPO_STR_DELIM)
+ return;
+ str = delim + 1;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
+ char c;
+
+ delim = strpbrk(str, ":\n");
+ if (!delim)
+ return;
+
+ c = *delim;
+ *delim = '\0';
fprintf(fp, "# sibling threads : %s\n", str);
- free(str);
+ *delim = c;
+
+ str = delim + 1;
}
}
@@ -1126,82 +1113,61 @@ static void print_event_desc(struct perf_header *ph, int fd __used, FILE *fp)
}
}
-static void print_total_mem(struct perf_header *h __used, int fd, FILE *fp)
+static void print_total_mem(struct perf_header *ph, int fd __used, FILE *fp)
{
- uint64_t mem;
- ssize_t ret;
-
- ret = read(fd, &mem, sizeof(mem));
- if (ret != sizeof(mem))
- goto error;
-
- if (h->needs_swap)
- mem = bswap_64(mem);
-
- fprintf(fp, "# total memory : %"PRIu64" kB\n", mem);
- return;
-error:
- fprintf(fp, "# total memory : unknown\n");
+ fprintf(fp, "# total memory : %"PRIu64" kB\n", ph->total_mem);
}
-static void print_numa_topology(struct perf_header *h __used, int fd, FILE *fp)
+/* For string formatting, see process_numa_topology() */
+static void print_numa_topology(struct perf_header *ph, int fd __used, FILE *fp)
{
- ssize_t ret;
- u32 nr, c, i;
+ u32 nr, i, node;
+ u64 mem_total, mem_free;
char *str;
- uint64_t mem_total, mem_free;
+ char *delim;
- /* nr nodes */
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- goto error;
+ str = ph->numa_topology;
- if (h->needs_swap)
- nr = bswap_32(nr);
+ nr = strtoul(str, &delim, 0);
+ if (*delim != '\n')
+ return;
+ str = delim + 1;
for (i = 0; i < nr; i++) {
+ char c;
- /* node number */
- ret = read(fd, &c, sizeof(c));
- if (ret != (ssize_t)sizeof(c))
- goto error;
+ node = strtoul(str, &delim, 0);
+ if (*delim != TOPO_STR_DELIM)
+ return;
- if (h->needs_swap)
- c = bswap_32(c);
+ str = delim + 1;
+ mem_total = strtoull(str, &delim, 0);
+ if (*delim != TOPO_STR_DELIM)
+ return;
- ret = read(fd, &mem_total, sizeof(u64));
- if (ret != sizeof(u64))
- goto error;
+ str = delim + 1;
+ mem_free = strtoull(str, &delim, 0);
+ if (*delim != TOPO_STR_DELIM)
+ return;
- ret = read(fd, &mem_free, sizeof(u64));
- if (ret != sizeof(u64))
- goto error;
-
- if (h->needs_swap) {
- mem_total = bswap_64(mem_total);
- mem_free = bswap_64(mem_free);
- }
+ delim = strchr(str, '\n');
+ if (!delim)
+ return;
+ c = *delim;
+ *delim = '\0';
fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB,"
- " free = %"PRIu64" kB\n",
- c,
- mem_total,
- mem_free);
+ " free = %"PRIu64" kB\n", node, mem_total, mem_free);
+ fprintf(fp, "# node%u cpu list : %s\n", node, str);
+ *delim = c;
- str = do_read_string(fd, h);
- fprintf(fp, "# node%u cpu list : %s\n", c, str);
- free(str);
+ str = delim + 1;
}
- return;
-error:
- fprintf(fp, "# numa topology : not available\n");
}
-static void print_cpuid(struct perf_header *ph, int fd, FILE *fp)
+static void print_cpuid(struct perf_header *ph, int fd __used, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# cpuid : %s\n", str);
- free(str);
+ fprintf(fp, "# cpuid : %s\n", ph->cpuid);
}
static void print_branch_stack(struct perf_header *ph __used, int fd __used,
@@ -1492,7 +1458,6 @@ error:
}
#define TOPO_STR_LEN ((size_t) 256)
-#define TOPO_STR_DELIM ':'
#define check_topo_len(topo, allocated, used, len) \
({ \
--
1.7.9.2
next prev parent reply other threads:[~2012-07-21 16:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-21 16:45 [PATCH 1/5] perf header: Do not write event_desc feature Namhyung Kim
2012-07-21 16:45 ` [PATCH 2/5] perf header: add ->process callbacks to most of features Namhyung Kim
2012-07-21 16:45 ` Namhyung Kim [this message]
2012-07-21 16:45 ` [PATCH 4/5] perf header: Remove unused @fd arg from ->print callback Namhyung Kim
2012-07-21 16:45 ` [PATCH 5/5] perf header: Remove unused @feat arg from ->process callback Namhyung Kim
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=1342889135-14825-3-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@ghostprotocols.net \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/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
Powered by JetHome