perf header: Do not write event_desc feature
Namhyung Kim
maintainerPATCH 1/5 perf header: Do not write event_desc feature
Since the event descriptions are saved already in the header, do not write them to the feature section.
--- tools/perf/util/header.c | 154 +++++++--------------------------------------- 1 file changed, 21 insertions(+), 133 deletions(-)
tools/perf/util/header.c +21 -133
@@ -596,61 +596,9 @@ static int write_nrcpus(int fd, struct perf_header *h __used,return do_write (fd, &nra,sizeof (nra)); } -static int write_event_desc (int fd,struct perf_header *h__used , -struct perf_evlist *evlist) +static int write_event_desc (int fd__used ,struct perf_header *h__used , +struct perf_evlist *evlist__used ) { -struct perf_evsel *attr; -u32 nre =0 , nri, sz; -int ret; - -list_for_each_entry (attr, &evlist->entries, node) - nre++; - -/* -* write number of events -*/ - ret =do_write (fd, &nre,sizeof (nre)); -if (ret <0 ) -return ret; - -/* -* size of perf_event_attr struct -*/ - sz = (u32 )sizeof (attr->attr); - ret =do_write (fd, &sz,sizeof (sz)); -if (ret <0 ) -return ret; - -list_for_each_entry (attr, &evlist->entries, node) { - - ret =do_write (fd, &attr->attr, sz); -if (ret <0 ) -return ret; -/* -* write number of unique id per event -* there is one id per instance of an event -* -* copy into an nri to be independent of the -* type of ids, -*/ - nri = attr->ids; - ret =do_write (fd, &nri,sizeof (nri)); -if (ret <0 ) -return ret; - -/* -* write event string as passed on cmdline -*/ - ret =do_write_string (fd,perf_evsel__name (attr)); -if (ret <0 ) -return ret; -/* -* write unique ids for this event -*/ - ret =do_write (fd, attr->id, attr->ids *sizeof (u64)); -if (ret <0 ) -return ret; - }return 0 ; }
@@ -1139,103 +1087,43 @@ static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp) } } -static void print_event_desc (struct perf_header *ph,int fd,FILE *fp) +static void print_event_desc (struct perf_header *ph,int fd__used ,FILE *fp) { -struct perf_event_attr attr; -uint64_t id; -void *buf =NULL ; -char *str; -u32 nre, sz, nr, i, j; -ssize_t ret; -size_t msz; - -/* number of events */ - ret =read (fd, &nre,sizeof (nre)); -if (ret != (ssize_t )sizeof (nre)) - goto error; - -if (ph->needs_swap) - nre =bswap_32 (nre); - - ret =read (fd, &sz,sizeof (sz)); -if (ret != (ssize_t )sizeof (sz)) - goto error; - -if (ph->needs_swap) - sz =bswap_32 (sz); - -memset (&attr,0 ,sizeof (attr)); - -/* buffer to hold on file attr struct */ - buf =malloc (sz); -if (!buf) - goto error; - - msz =sizeof (attr); -if (sz < msz) - msz = sz; - -for (i =0 ; i < nre; i++) { - -/* -* must read entire on-file attr struct to -* sync up with layout. -*/ - ret =read (fd, buf, sz); -if (ret != (ssize_t )sz) - goto error; - -if (ph->needs_swap) -perf_event__attr_swap (buf); +struct perf_session *session; +struct perf_evsel *evsel; +int i; -memcpy (&attr, buf, msz); + session = container_of(ph, struct perf_session, header); - ret =read (fd, &nr,sizeof (nr)); -if (ret != (ssize_t )sizeof (nr)) - goto error; +list_for_each_entry (evsel, &session->evlist->entries, node) { +struct perf_event_attr *attr = &evsel->attr; -if (ph->needs_swap) - nr =bswap_32 (nr); - - str =do_read_string (fd, ph); -fprintf (fp,"# event : name = %s, " , str); -free (str); +fprintf (fp,"# event : name = %s, " ,perf_evsel__name (evsel));fprintf (fp,"type = %d, config = 0x%" PRIx64", config1 = 0x%" PRIx64", config2 = 0x%" PRIx64, - attr.type, - (u64 )attr.config, - (u64 )attr.config1, - (u64 )attr.config2); + attr->type, + (u64 )attr->config, + (u64 )attr->config1, + (u64 )attr->config2);fprintf (fp,", excl_usr = %d, excl_kern = %d" , - attr.exclude_user, - attr.exclude_kernel); + attr->exclude_user, + attr->exclude_kernel); -if (nr) +if (evsel->ids)fprintf (fp,", id = {" ); -for (j =0 ; j < nr; j++) { - ret =read (fd, &id,sizeof (id)); -if (ret != (ssize_t )sizeof (id)) - goto error; - -if (ph->needs_swap) - id =bswap_64 (id); - -if (j) +for (i =0 ; i < evsel->ids; i++) { +if (i)fputc (',' , fp); -fprintf (fp," %" PRIu64, id); +fprintf (fp," %" PRIu64, evsel->id[i]); } -if (nr && j == nr) +if (evsel->ids && i == evsel->ids)fprintf (fp," }" );fputc ('\n' , fp); } -free (buf); -return ; -error: -fprintf (fp,"# event desc: not available or unable to read\n" ); }static void print_total_mem (struct perf_header *h__used ,int fd,FILE *fp)
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 2/5 perf header: add ->process callbacks to most of features
Quoted 1 line
From now for each feature information is processed and saved in perf
header so that it can be used wherever needed. The EVENT_DESC and BRANCH_STACK features are exceptions since they need nothing to be done.
--- tools/perf/util/header.c | 360 ++++++++++++++++++++++++++++++++++++++++++++-- tools/perf/util/header.h | 13 ++ 2 files changed, 363 insertions(+), 10 deletions(-)
tools/perf/util/header.c +350 -10
@@ -1377,6 +1377,346 @@ static int process_build_id(struct perf_file_section *section,return 0 ; } +static int process_hostname (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + ph->hostname =do_read_string (fd, ph); +return ph->hostname ?0 : -ENOMEM ; +} + +static int process_osrelease (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + + ph->os_release =do_read_string (fd, ph); +return ph->os_release ?0 : -ENOMEM ; +} + +static int process_arch (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + ph->arch =do_read_string (fd, ph); +return ph->arch ?0 : -ENOMEM ; +} + +static int process_cpudesc (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + ph->cpu_desc =do_read_string (fd, ph); +return ph->cpu_desc ?0 : -ENOMEM ; +} + +static int process_nrcpus (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ +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); + + ph->nr_cpus_online = 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); + + ph->nr_cpus_avail = nr; + +return 0 ; +} + +static int process_version (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + ph->version =do_read_string (fd, ph); +return ph->version ?0 : -ENOMEM ; +} + +/* Each argv would be separated by a NULL character */ +static int process_cmdline (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ +ssize_t ret; +char *str, *tmp; +u32 nr, i; +char *cmdline =NULL ; +size_t len =0 ; + + ret =read (fd, &nr,sizeof (nr)); +if (ret != (ssize_t )sizeof (nr)) +return -1 ; + +if (ph->needs_swap) + nr =bswap_32 (nr); + + ph->cmdline_argc = nr; + +for (i =0 ; i < nr; i++) { + str =do_read_string (fd, ph); +if (!str) + goto error; + + tmp =realloc (cmdline, len +strlen (str) +1 ); +if (!tmp) + goto error; + cmdline = tmp; + +/* include null character at the end */ +strcpy (cmdline + len, str); + + len +=strlen (str) +1 ; +free (str); + } + ph->cmdline = cmdline; +return 0 ; + +error: +free (cmdline); +free (str); +return -1 ; +} + +#define TOPO_STR_LEN ((size_t) 256) +#define TOPO_STR_DELIM ':' + +#define check_topo_len (topo, allocated, used, len) \ +({ \ + if (len > allocated - used) { \ + char *tmp = realloc(topo, allocated + TOPO_STR_LEN); \ + if (!tmp) \ + goto error; \ + topo = tmp; \ + allocated += TOPO_STR_LEN; \ + } \ +}) + +/* +* The topology string looks like below (':' is used for delimiter): +* +* "NR_CORE_SIBLINGS(N):SIBLING[0]:SIBLING[1]:...:SIBLING[N-1]\n" +* "NR_THREAD_SIBLINGS(M):SIBLING[0]:SIBLING[1]:...:SIBLING[M-1]\n" +*/ +static int process_cpu_topology (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used , +int fd,void *data__used ) +{ +ssize_t ret; +u32 nr, i; +char *str; +char buf[128 ]; +char *topo =NULL ; +size_t allocated =0 , used, len; + + ret =read (fd, &nr,sizeof (nr)); +if (ret != (ssize_t )sizeof (nr)) +return -1 ; + +if (ph->needs_swap) + nr =bswap_32 (nr); + + allocated =TOPO_STR_LEN ; + topo =malloc (TOPO_STR_LEN ); +if (!topo) +return -ENOMEM ; + +/* core siblings */ + used =scnprintf (topo, allocated,"%u" , nr); + +for (i =0 ; i < nr; i++) { + str =do_read_string (fd, ph); +if (!str) + goto error; + + len =strlen (str) +1 ; +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%c%s" , +TOPO_STR_DELIM , str); + used += len; +free (str); + } +check_topo_len (topo, allocated, used,1 ); +scnprintf (topo + used, allocated - used,"\n" ); + used++; + +/* thread siblings */ + ret =read (fd, &nr,sizeof (nr)); +if (ret != (ssize_t )sizeof (nr)) + goto error; + +if (ph->needs_swap) + nr =bswap_32 (nr); + + len =scnprintf (buf,sizeof (buf),"%u" , nr); +check_topo_len (topo, allocated, used, len); + +strcat (topo, buf); + used += len; + +for (i =0 ; i < nr; i++) { + str =do_read_string (fd, ph); +if (!str) + goto error; + + len =strlen (str) +1 ; +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%c%s" , +TOPO_STR_DELIM , str); + used += len; +free (str); + } +check_topo_len (topo, allocated, used,1 ); +scnprintf (topo + used, allocated - used,"\n" ); + + ph->cpu_topology = topo; +return 0 ; + +error: +free (topo); +return -1 ; +} + +/* +* The topology string looks like below (':' is used for delimiter): +* +* "NR_NODES(N)\n +* "NODE_NUM(0):MEM_TOTAL:MEM_FREE:CPULIST\n" +* "NODE_NUM(1):MEM_TOTAL:MEM_FREE:CPULIST\n" +* ... +* "NODE_NUM(N-1):MEM_TOTAL:MEM_FREE:CPULIST\n" +*/ +static int process_numa_topology (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used , +int fd,void *data__used ) +{ +ssize_t ret; +u32 nr, node, i; +char *str; +uint64_t mem_total, mem_free; +char *topo =NULL ; +size_t allocated =0 , used, len; + +/* nr nodes */ + ret =read (fd, &nr,sizeof (nr)); +if (ret != (ssize_t )sizeof (nr)) + goto error; + +if (ph->needs_swap) + nr =bswap_32 (nr); + + allocated =TOPO_STR_LEN ; + topo =malloc (TOPO_STR_LEN ); +if (!topo) +return -ENOMEM ; + + used =scnprintf (topo, allocated,"%u\n" , nr); + +for (i =0 ; i < nr; i++) { +char buf[128 ]; + +/* node number */ + ret =read (fd, &node,sizeof (node)); +if (ret != (ssize_t )sizeof (node)) + goto error; + +if (ph->needs_swap) + node =bswap_32 (node); + + len =scnprintf (buf,sizeof (buf),"%u%c" , node,TOPO_STR_DELIM ); +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%s" , buf); + used += len; + + ret =read (fd, &mem_total,sizeof (u64)); +if (ret !=sizeof (u64)) + goto error; + +if (ph->needs_swap) + mem_total =bswap_64 (mem_total); + + len =scnprintf (buf,sizeof (buf),"%" PRIu64"%c" , + mem_total,TOPO_STR_DELIM ); +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%s" , buf); + used += len; + + ret =read (fd, &mem_free,sizeof (u64)); +if (ret !=sizeof (u64)) + goto error; + +if (ph->needs_swap) + mem_free =bswap_64 (mem_free); + + len =scnprintf (buf,sizeof (buf),"%" PRIu64"%c" , + mem_total,TOPO_STR_DELIM ); +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%s" , buf); + used += len; + + str =do_read_string (fd, ph); +if (!str) + goto error; + + len =strlen (str) +1 ; +check_topo_len (topo, allocated, used, len); + +scnprintf (topo + used, allocated - used,"%s\n" , str); + used += len; +free (str); + } + + ph->numa_topology = topo; +return 0 ; +error: +free (topo); +return -1 ; +} + +static int process_cpuid (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ + ph->cpuid =do_read_string (fd, ph); +return ph->cpuid ?0 : -ENOMEM ; +} + +static int process_total_mem (struct perf_file_section *section__used , +struct perf_header *ph,int feat__used ,int fd, +void *data__used ) +{ +uint64_t mem; +ssize_t ret; + + ret =read (fd, &mem,sizeof (mem)); +if (ret !=sizeof (mem)) +return -1 ; + +if (ph->needs_swap) + mem =bswap_64 (mem); + + ph->total_mem = mem; +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);
@@ -1393,7 +1733,7 @@ struct feature_ops { .process = process_##func }#define FEAT_OPF (n, func) \ [n] = { .name = #n, .write = write_##func, .print = print_##func, \ - .full_only = true } + .process = process_##func, .full_only = true }/* feature_ops not implemented: */ #define print_tracing_data NULL
@@ -1402,16 +1742,16 @@ struct feature_ops {static const struct feature_ops feat_ops[HEADER_LAST_FEATURE ] = {FEAT_OPP (HEADER_TRACING_DATA , tracing_data),FEAT_OPP (HEADER_BUILD_ID , build_id), -FEAT_OPA (HEADER_HOSTNAME , hostname), -FEAT_OPA (HEADER_OSRELEASE , osrelease), -FEAT_OPA (HEADER_VERSION , version), -FEAT_OPA (HEADER_ARCH , arch), -FEAT_OPA (HEADER_NRCPUS , nrcpus), -FEAT_OPA (HEADER_CPUDESC , cpudesc), -FEAT_OPA (HEADER_CPUID , cpuid), -FEAT_OPA (HEADER_TOTAL_MEM , total_mem), +FEAT_OPP (HEADER_HOSTNAME , hostname), +FEAT_OPP (HEADER_OSRELEASE , osrelease), +FEAT_OPP (HEADER_VERSION , version), +FEAT_OPP (HEADER_ARCH , arch), +FEAT_OPP (HEADER_NRCPUS , nrcpus), +FEAT_OPP (HEADER_CPUDESC , cpudesc), +FEAT_OPP (HEADER_CPUID , cpuid), +FEAT_OPP (HEADER_TOTAL_MEM , total_mem),FEAT_OPA (HEADER_EVENT_DESC , event_desc), -FEAT_OPA (HEADER_CMDLINE , cmdline), +FEAT_OPP (HEADER_CMDLINE , cmdline),FEAT_OPF (HEADER_CPU_TOPOLOGY , cpu_topology),FEAT_OPF (HEADER_NUMA_TOPOLOGY , numa_topology),FEAT_OPA (HEADER_BRANCH_STACK , branch_stack),
tools/perf/util/header.h +13 -0
@@ -66,6 +66,19 @@ struct perf_header {u64 event_offset;u64 event_size;DECLARE_BITMAP (adds_features,HEADER_FEAT_BITS ); +char *hostname; +char *os_release; +char *version; +char *arch; +u32 nr_cpus_online; +u32 nr_cpus_avail; +char *cpu_desc; +char *cpuid; +u64 total_mem; +int cmdline_argc; +char *cmdline; +char *cpu_topology; +char *numa_topology; };struct perf_evlist ;
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 3/5 perf header: Make feat_ops->print use processed result
In reply to Namhyung KimNow we have all of necessary information in the perf_header so just use it for printing.
--- tools/perf/util/header.c | 219 +++++++++++++++++++--------------------------- 1 file changed, 92 insertions(+), 127 deletions(-)
tools/perf/util/header.c +92 -127
@@ -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) \ ({ \
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 5/5 perf header: Remove unused @feat arg from ->process callback
In reply to Namhyung KimAs the @feat arg is not used anywhere, get rid of it from the signature.
--- tools/perf/util/header.c | 48 ++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
tools/perf/util/header.c +19 -29
@@ -1325,17 +1325,16 @@ out:return err; } -static int process_tracing_data(struct perf_file_section *section __unused, - struct perf_header *ph __unused, - int feat __unused, int fd, void *data) +static int process_tracing_data (struct perf_file_section *section__used , +struct perf_header *ph__used ,int fd, +void *data) {trace_report (fd, data, false);return 0 ; }static int process_build_id (struct perf_file_section *section, -struct perf_header *ph, - int feat __unused, int fd, void *data __used) +struct perf_header *ph,int fd,void *data__used ) {if (perf_header__read_build_ids (ph, fd, section->offset, section->size))pr_debug ("Failed to read buildids, continuing...\n" );
@@ -1343,16 +1342,14 @@ static int process_build_id(struct perf_file_section *section, }static int process_hostname (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->hostname =do_read_string (fd, ph);return ph->hostname ?0 : -ENOMEM ; }static int process_osrelease (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->os_release =do_read_string (fd, ph);
@@ -1360,24 +1357,21 @@ static int process_osrelease(struct perf_file_section *section __used, }static int process_arch (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->arch =do_read_string (fd, ph);return ph->arch ?0 : -ENOMEM ; }static int process_cpudesc (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->cpu_desc =do_read_string (fd, ph);return ph->cpu_desc ?0 : -ENOMEM ; }static int process_nrcpus (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) {ssize_t ret;u32 nr;
@@ -1404,8 +1398,7 @@ static int process_nrcpus(struct perf_file_section *section __used, }static int process_version (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->version =do_read_string (fd, ph);return ph->version ?0 : -ENOMEM ;
@@ -1413,8 +1406,7 @@ static int process_version(struct perf_file_section *section __used,/* Each argv would be separated by a NULL character */ static int process_cmdline (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) {ssize_t ret;char *str, *tmp;
@@ -1476,8 +1468,8 @@ error:* "NR_THREAD_SIBLINGS(M):SIBLING[0]:SIBLING[1]:...:SIBLING[M-1]\n" */ static int process_cpu_topology (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used , -int fd,void *data__used ) +struct perf_header *ph,int fd, +void *data__used ) {ssize_t ret;u32 nr, i;
@@ -1566,8 +1558,8 @@ error:* "NODE_NUM(N-1):MEM_TOTAL:MEM_FREE:CPULIST\n" */ static int process_numa_topology (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used , -int fd,void *data__used ) +struct perf_header *ph,int fd, +void *data__used ) {ssize_t ret;u32 nr, node, i;
@@ -1656,16 +1648,14 @@ error: }static int process_cpuid (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) { ph->cpuid =do_read_string (fd, ph);return ph->cpuid ?0 : -ENOMEM ; }static int process_total_mem (struct perf_file_section *section__used , -struct perf_header *ph,int feat__used ,int fd, -void *data__used ) +struct perf_header *ph,int fd,void *data__used ) {uint64_t mem;ssize_t ret;
@@ -1685,7 +1675,7 @@ struct feature_ops {int (*write)(int fd,struct perf_header *h,struct perf_evlist *evlist);void (*print)(struct perf_header *h,FILE *fp);int (*process)(struct perf_file_section *section, -struct perf_header *h,int feat,int fd,void *data); +struct perf_header *h,int fd,void *data);const char *name;bool full_only; };
@@ -2196,7 +2186,7 @@ static int perf_file_section__process(struct perf_file_section *section,if (!feat_ops[feat].process)return 0 ; -return feat_ops[feat].process (section, ph, feat, fd, data); +return feat_ops[feat].process (section, ph, fd, data); } static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 4/5 perf header: Remove unused @fd arg from ->print callback
In reply to Namhyung KimAs we don't need the @fd in the ->print any more, get rid of it from the signature.
--- tools/perf/util/header.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
tools/perf/util/header.c +15 -16
@@ -973,38 +973,38 @@ 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__used ,FILE *fp) +static void print_hostname (struct perf_header *ph,FILE *fp) {fprintf (fp,"# hostname : %s\n" , ph->hostname); } -static void print_osrelease (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_osrelease (struct perf_header *ph,FILE *fp) {fprintf (fp,"# os release : %s\n" , ph->os_release); } -static void print_arch (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_arch (struct perf_header *ph,FILE *fp) {fprintf (fp,"# arch : %s\n" , ph->arch); } -static void print_cpudesc (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_cpudesc (struct perf_header *ph,FILE *fp) {fprintf (fp,"# cpudesc : %s\n" , ph->cpu_desc); } -static void print_nrcpus (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_nrcpus (struct perf_header *ph,FILE *fp) {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__used ,FILE *fp) +static void print_version (struct perf_header *ph,FILE *fp) {fprintf (fp,"# perf version : %s\n" , ph->version); } -static void print_cmdline (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_cmdline (struct perf_header *ph,FILE *fp) {char *str;int i;
@@ -1023,7 +1023,7 @@ static void print_cmdline(struct perf_header *ph, int fd __used, 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) +static void print_cpu_topology (struct perf_header *ph,FILE *fp) {u32 nr, i;char *str;
@@ -1074,7 +1074,7 @@ static void print_cpu_topology(struct perf_header *ph, int fd __used, FILE *fp) } } -static void print_event_desc (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_event_desc (struct perf_header *ph,FILE *fp) {struct perf_session *session;struct perf_evsel *evsel;
@@ -1113,13 +1113,13 @@ static void print_event_desc(struct perf_header *ph, int fd __used, FILE *fp) } } -static void print_total_mem (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_total_mem (struct perf_header *ph,FILE *fp) {fprintf (fp,"# total memory : %" PRIu64" kB\n" , ph->total_mem); }/* For string formatting, see process_numa_topology() */ -static void print_numa_topology (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_numa_topology (struct perf_header *ph,FILE *fp) {u32 nr, i, node;u64 mem_total, mem_free;
@@ -1165,13 +1165,12 @@ static void print_numa_topology(struct perf_header *ph, int fd __used, FILE *fp) } } -static void print_cpuid (struct perf_header *ph,int fd__used ,FILE *fp) +static void print_cpuid (struct perf_header *ph,FILE *fp) {fprintf (fp,"# cpuid : %s\n" , ph->cpuid); } -static void print_branch_stack (struct perf_header *ph__used ,int fd__used , -FILE *fp) +static void print_branch_stack (struct perf_header *ph__used ,FILE *fp) {fprintf (fp,"# contains samples with branch stack\n" ); }
@@ -1684,7 +1683,7 @@ static int process_total_mem(struct perf_file_section *section __used,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); +void (*print)(struct perf_header *h,FILE *fp);int (*process)(struct perf_file_section *section,struct perf_header *h,int feat,int fd,void *data);const char *name;
@@ -1746,7 +1745,7 @@ static int perf_file_section__fprintf_info(struct perf_file_section *section,return 0 ;if (!feat_ops[feat].full_only || hd->full) - feat_ops[feat].else fprintf (hd->fp,"# %s info available, use -I to display\n" , feat_ops[feat].name);
Signature · 1 line
1.7.9.2