提交 7e94cfcc 编写于 作者: N Namhyung Kim 提交者: Arnaldo Carvalho de Melo

perf header: Use pre-processed session env when printing

From now on each feature information is processed and saved in perf
header so that it can be used for printing.  The event desc and branch
stack features are not touched since they're not saved.
Signed-off-by: NNamhyung 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-4-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 a1ae5655
...@@ -1103,118 +1103,80 @@ static int write_branch_stack(int fd __maybe_unused, ...@@ -1103,118 +1103,80 @@ static int write_branch_stack(int fd __maybe_unused,
return 0; return 0;
} }
static void print_hostname(struct perf_header *ph, int fd, FILE *fp) static void print_hostname(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# hostname : %s\n", ph->env.hostname);
fprintf(fp, "# hostname : %s\n", str);
free(str);
} }
static void print_osrelease(struct perf_header *ph, int fd, FILE *fp) static void print_osrelease(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# os release : %s\n", ph->env.os_release);
fprintf(fp, "# os release : %s\n", str);
free(str);
} }
static void print_arch(struct perf_header *ph, int fd, FILE *fp) static void print_arch(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# arch : %s\n", ph->env.arch);
fprintf(fp, "# arch : %s\n", str);
free(str);
} }
static void print_cpudesc(struct perf_header *ph, int fd, FILE *fp) static void print_cpudesc(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# cpudesc : %s\n", ph->env.cpu_desc);
fprintf(fp, "# cpudesc : %s\n", str);
free(str);
} }
static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp) static void print_nrcpus(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
ssize_t ret; fprintf(fp, "# nrcpus online : %u\n", ph->env.nr_cpus_online);
u32 nr; fprintf(fp, "# nrcpus avail : %u\n", ph->env.nr_cpus_avail);
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);
} }
static void print_version(struct perf_header *ph, int fd, FILE *fp) static void print_version(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# perf version : %s\n", ph->env.version);
fprintf(fp, "# perf version : %s\n", str);
free(str);
} }
static void print_cmdline(struct perf_header *ph, int fd, FILE *fp) static void print_cmdline(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
ssize_t ret; int nr, i;
char *str; char *str;
u32 nr, i;
ret = read(fd, &nr, sizeof(nr));
if (ret != (ssize_t)sizeof(nr))
return;
if (ph->needs_swap) nr = ph->env.nr_cmdline;
nr = bswap_32(nr); str = ph->env.cmdline;
fprintf(fp, "# cmdline : "); fprintf(fp, "# cmdline : ");
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
str = do_read_string(fd, ph);
fprintf(fp, "%s ", str); fprintf(fp, "%s ", str);
free(str); str += strlen(str) + 1;
} }
fputc('\n', fp); fputc('\n', fp);
} }
static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp) static void print_cpu_topology(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
ssize_t ret; int nr, i;
u32 nr, i;
char *str; char *str;
ret = read(fd, &nr, sizeof(nr)); nr = ph->env.nr_sibling_cores;
if (ret != (ssize_t)sizeof(nr)) str = ph->env.sibling_cores;
return;
if (ph->needs_swap)
nr = bswap_32(nr);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
str = do_read_string(fd, ph);
fprintf(fp, "# sibling cores : %s\n", str); fprintf(fp, "# sibling cores : %s\n", str);
free(str); str += strlen(str) + 1;
} }
ret = read(fd, &nr, sizeof(nr)); nr = ph->env.nr_sibling_threads;
if (ret != (ssize_t)sizeof(nr)) str = ph->env.sibling_threads;
return;
if (ph->needs_swap)
nr = bswap_32(nr);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
str = do_read_string(fd, ph);
fprintf(fp, "# sibling threads : %s\n", str); fprintf(fp, "# sibling threads : %s\n", str);
free(str); str += strlen(str) + 1;
} }
} }
...@@ -1375,126 +1337,89 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp) ...@@ -1375,126 +1337,89 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp)
free_event_desc(events); free_event_desc(events);
} }
static void print_total_mem(struct perf_header *h __maybe_unused, int fd, static void print_total_mem(struct perf_header *ph, int fd __maybe_unused,
FILE *fp) FILE *fp)
{ {
uint64_t mem; fprintf(fp, "# total memory : %Lu kB\n", ph->env.total_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");
} }
static void print_numa_topology(struct perf_header *h __maybe_unused, int fd, static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused,
FILE *fp) FILE *fp)
{ {
ssize_t ret;
u32 nr, c, i; u32 nr, c, i;
char *str; char *str, *tmp;
uint64_t mem_total, mem_free; uint64_t mem_total, mem_free;
/* nr nodes */ /* nr nodes */
ret = read(fd, &nr, sizeof(nr)); nr = ph->env.nr_numa_nodes;
if (ret != (ssize_t)sizeof(nr)) str = ph->env.numa_nodes;
goto error;
if (h->needs_swap)
nr = bswap_32(nr);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
/* node number */ /* node number */
ret = read(fd, &c, sizeof(c)); c = strtoul(str, &tmp, 0);
if (ret != (ssize_t)sizeof(c)) if (*tmp != ':')
goto error; goto error;
if (h->needs_swap) str = tmp + 1;
c = bswap_32(c); mem_total = strtoull(str, &tmp, 0);
if (*tmp != ':')
ret = read(fd, &mem_total, sizeof(u64));
if (ret != sizeof(u64))
goto error; goto error;
ret = read(fd, &mem_free, sizeof(u64)); str = tmp + 1;
if (ret != sizeof(u64)) mem_free = strtoull(str, &tmp, 0);
if (*tmp != ':')
goto error; goto error;
if (h->needs_swap) {
mem_total = bswap_64(mem_total);
mem_free = bswap_64(mem_free);
}
fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB,"
" free = %"PRIu64" kB\n", " free = %"PRIu64" kB\n",
c, c, mem_total, mem_free);
mem_total,
mem_free);
str = do_read_string(fd, h); str = tmp + 1;
fprintf(fp, "# node%u cpu list : %s\n", c, str); fprintf(fp, "# node%u cpu list : %s\n", c, str);
free(str);
} }
return; return;
error: error:
fprintf(fp, "# numa topology : not available\n"); 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 __maybe_unused, FILE *fp)
{ {
char *str = do_read_string(fd, ph); fprintf(fp, "# cpuid : %s\n", ph->env.cpuid);
fprintf(fp, "# cpuid : %s\n", str);
free(str);
} }
static void print_branch_stack(struct perf_header *ph __maybe_unused, static void print_branch_stack(struct perf_header *ph __maybe_unused,
int fd __maybe_unused, int fd __maybe_unused, FILE *fp)
FILE *fp)
{ {
fprintf(fp, "# contains samples with branch stack\n"); fprintf(fp, "# contains samples with branch stack\n");
} }
static void print_pmu_mappings(struct perf_header *ph, int fd, FILE *fp) static void print_pmu_mappings(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{ {
const char *delimiter = "# pmu mappings: "; const char *delimiter = "# pmu mappings: ";
char *name; char *str, *tmp;
int ret;
u32 pmu_num; u32 pmu_num;
u32 type; u32 type;
ret = read(fd, &pmu_num, sizeof(pmu_num)); pmu_num = ph->env.nr_pmu_mappings;
if (ret != sizeof(pmu_num))
goto error;
if (ph->needs_swap)
pmu_num = bswap_32(pmu_num);
if (!pmu_num) { if (!pmu_num) {
fprintf(fp, "# pmu mappings: not available\n"); fprintf(fp, "# pmu mappings: not available\n");
return; return;
} }
str = ph->env.pmu_mappings;
while (pmu_num) { while (pmu_num) {
if (read(fd, &type, sizeof(type)) != sizeof(type)) type = strtoul(str, &tmp, 0);
break; if (*tmp != ':')
if (ph->needs_swap) goto error;
type = bswap_32(type);
str = tmp + 1;
fprintf(fp, "%s%s = %" PRIu32, delimiter, str, type);
name = do_read_string(fd, ph);
if (!name)
break;
pmu_num--;
fprintf(fp, "%s%s = %" PRIu32, delimiter, name, type);
free(name);
delimiter = ", "; delimiter = ", ";
str += strlen(str) + 1;
pmu_num--;
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册