perf tools: Factorize the dprintf definition
PATCH 1/1 perf tools: Factorize the dprintf definition
We have two users of dprintf: report and annotate. Another one is coming with perf trace. Then factorize it into the debug file.
While at it, rename dprintf() to dump_printf() so that it doesn't conflicts with its libc homograph.
--- tools/perf/builtin-annotate.c | 40 +++++++++++++---------------- tools/perf/builtin-report.c | 56 +++++++++++++++++++--------------------- tools/perf/util/debug.c | 15 +++++++++++ tools/perf/util/debug.h | 2 + 4 files changed, 62 insertions(+), 51 deletions(-)
tools/perf/builtin-annotate.c +18 -22
@@ -34,10 +34,6 @@ static char *sort_order = default_sort_order;static int input;static int show_mask =SHOW_KERNEL |SHOW_USER |SHOW_HV ; -static int dump_trace =0 ; -#define dprintf(x...) do { if (dump_trace) printf(x); } while (0) - -static int full_paths;static int print_line;
@@ -507,14 +503,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->ip.pid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n" , +dump_printf ("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->header.misc, event->ip.pid, (void *)(long )ip); -dprintf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid);if (thread ==NULL ) { fprintf(stderr, "problem processing %d event, skipping it.\n",
@@ -528,7 +524,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) dso = kernel_dso; -dprintf (" ...... dso: %s\n" , dso->name); +dump_printf (" ...... dso: %s\n" , dso->name); }else if (event->header.misc &PERF_EVENT_MISC_USER ) {
@@ -549,12 +545,12 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)if ((long long )ip <0 ) dso = kernel_dso; } -dprintf (" ...... dso: %s\n" , dso ? dso->name :"<not found>" ); +dump_printf (" ...... dso: %s\n" , dso ? dso->name :"<not found>" ); }else { show =SHOW_HV ; level ='H' ; -dprintf (" ...... dso: [hypervisor]\n" ); +dump_printf (" ...... dso: [hypervisor]\n" ); }if (show & show_mask) {
@@ -582,7 +578,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->mmap.pid, &threads, &last_match); - dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", + dump_printf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", (void *)(offset + head), (void *)(long)(event->header.size), event->mmap.pid,
@@ -592,7 +588,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) event->mmap.filename);if (thread ==NULL || map ==NULL ) { -dprintf ("problem processing PERF_EVENT_MMAP, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_MMAP, skipping event.\n" );return 0 ; }
@@ -608,14 +604,14 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)struct thread *thread; thread =threads__findnew (event->comm.pid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT_COMM: %s:%d\n" , +dump_printf ("%p [%p]: PERF_EVENT_COMM: %s:%d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->comm.comm, event->comm.pid);if (thread ==NULL ||thread__set_comm (thread, event->comm.comm)) { -dprintf ("problem processing PERF_EVENT_COMM, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_COMM, skipping event.\n" );return -1 ; } total_comm++;
@@ -631,13 +627,13 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->fork.pid, &threads, &last_match); parent =threads__findnew (event->fork.ppid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT_FORK: %d:%d\n" , +dump_printf ("%p [%p]: PERF_EVENT_FORK: %d:%d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->fork.pid, event->fork.ppid);if (!thread || !parent ||thread__fork (thread, parent)) { -dprintf ("problem processing PERF_EVENT_FORK, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_FORK, skipping event.\n" );return -1 ; } total_fork++;
@@ -1022,14 +1018,14 @@ more: size = event->header.size; -dprintf ("%p [%p]: event: %d\n" , +dump_printf ("%p [%p]: event: %d\n" , (void *)(offset + head), (void *)(long )event->header.size, event->header.type);if (!size ||process_event (event, offset, head) <0 ) { -dprintf ("%p [%p]: skipping unknown header type: %d\n" , +dump_printf ("%p [%p]: skipping unknown header type: %d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->header.type);
@@ -1055,11 +1051,11 @@ more: rc =EXIT_SUCCESS ;close (input); -dprintf (" IP events: %10ld\n" , total); -dprintf (" mmap events: %10ld\n" , total_mmap); -dprintf (" comm events: %10ld\n" , total_comm); -dprintf (" fork events: %10ld\n" , total_fork); -dprintf (" unknown events: %10ld\n" , total_unknown); +dump_printf (" IP events: %10ld\n" , total); +dump_printf (" mmap events: %10ld\n" , total_mmap); +dump_printf (" comm events: %10ld\n" , total_comm); +dump_printf (" fork events: %10ld\n" , total_fork); +dump_printf (" unknown events: %10ld\n" , total_unknown);if (dump_trace)return 0 ;
tools/perf/builtin-report.c +27 -29
183 lines not on this page · raw message
tools/perf/util/debug.c +15 -0
@@ -6,6 +6,7 @@#include <stdio.h> int verbose =0 ; +int dump_trace =0 ;int eprintf (const char *fmt, ...) {
@@ -20,3 +21,17 @@ int eprintf(const char *fmt, ...)return ret; } + +int dump_printf (const char *fmt, ...) +{ +va_list args; +int ret =0 ; + +if (dump_trace) { +va_start (args, fmt); + ret =vprintf (fmt, args); +va_end (args); + } + +return ret; +}
tools/perf/util/debug.h +2 -0
@@ -1,5 +1,7 @@/* For debugging general purposes */ extern int verbose; +extern int dump_trace;int eprintf (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +int dump_printf (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));
Signature · 1 line
1.6.2.3
PATCH 1/1 perf tools: Put the show mode into the event headers files
Annotate and report share the same flags to filter events considering their context (kernel, user, hypervisor).
Both tools have their own definitions of these flags. Factorize them in the event headers file.
--- tools/perf/builtin-annotate.c | 4 ---- tools/perf/builtin-report.c | 4 ---- tools/perf/util/event.h | 6 ++++++ 3 files changed, 6 insertions(+), 8 deletions(-)
tools/perf/builtin-annotate.c +0 -4
@@ -22,10 +22,6 @@#include "util/parse-events.h" #include "util/thread.h" -#define SHOW_KERNEL 1 -#define SHOW_USER 2 -#define SHOW_HV 4 -static char const *input_name ="perf.data" ;static char default_sort_order[] ="comm,symbol" ;
tools/perf/builtin-report.c +0 -4
@@ -27,10 +27,6 @@#include "util/thread.h" -#define SHOW_KERNEL 1 -#define SHOW_USER 2 -#define SHOW_HV 4 -static char const *input_name ="perf.data" ;static char default_sort_order[] ="comm,dso,symbol" ;
tools/perf/util/event.h +6 -0
@@ -4,6 +4,12 @@#include "util.h" #include <linux/list.h> +enum { +SHOW_KERNEL =1 , +SHOW_USER =2 , +SHOW_HV =4 , +}; +/* * PERF_SAMPLE_IP | PERF_SAMPLE_TID | * */
Signature · 1 line
1.6.2.3
[tip:perfcounters/core] perf tools: Put the show mode into the event headers files
Commit-ID: 0f25bfc8d8b31a4ac8e4ff6cbc3911fb7092a4a7 Gitweb: http://git.kernel.org/tip/0f25bfc8d8b31a4ac8e4ff6cbc3911fb7092a4a7 Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 16 Aug 2009 19:56:54 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 16 Aug 2009 19:59:13 +0200
perf tools: Put the show mode into the event headers files
Annotate and report share the same flags to filter events considering their context (kernel, user, hypervisor).
Both tools have their own definitions of these flags. Factorize them out into the event headers file.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 4 ---- tools/perf/builtin-report.c | 4 ---- tools/perf/util/event.h | 6 ++++++ 3 files changed, 6 insertions(+), 8 deletions(-)
tools/perf/builtin-annotate.c +0 -4
@@ -22,10 +22,6 @@#include "util/parse-events.h" #include "util/thread.h" -#define SHOW_KERNEL 1 -#define SHOW_USER 2 -#define SHOW_HV 4 -static char const *input_name ="perf.data" ;static char default_sort_order[] ="comm,symbol" ;
tools/perf/builtin-report.c +0 -4
@@ -27,10 +27,6 @@#include "util/thread.h" -#define SHOW_KERNEL 1 -#define SHOW_USER 2 -#define SHOW_HV 4 -static char const *input_name ="perf.data" ;static char default_sort_order[] ="comm,dso,symbol" ;
tools/perf/util/event.h +6 -0
@@ -4,6 +4,12 @@#include "util.h" #include <linux/list.h> +enum { +SHOW_KERNEL =1 , +SHOW_USER =2 , +SHOW_HV =4 , +}; +/* * PERF_SAMPLE_IP | PERF_SAMPLE_TID | * */
Commit-ID: 2cec19d9d0716f8d68f1c5a87667d0387d4d252d Gitweb: http://git.kernel.org/tip/2cec19d9d0716f8d68f1c5a87667d0387d4d252d Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 16 Aug 2009 19:24:21 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 16 Aug 2009 19:42:31 +0200
perf tools: Factorize the dprintf definition
We have two users of dprintf: report and annotate. Another one is coming with perf trace. Then factorize it into the debug file.
While at it, rename dprintf() to dump_printf() so that it doesn't conflicts with its libc homograph.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 40 +++++++++++++---------------- tools/perf/builtin-report.c | 56 +++++++++++++++++++--------------------- tools/perf/util/debug.c | 15 +++++++++++ tools/perf/util/debug.h | 2 + 4 files changed, 62 insertions(+), 51 deletions(-)
tools/perf/builtin-annotate.c +18 -22
@@ -34,10 +34,6 @@ static char *sort_order = default_sort_order;static int input;static int show_mask =SHOW_KERNEL |SHOW_USER |SHOW_HV ; -static int dump_trace =0 ; -#define dprintf(x...) do { if (dump_trace) printf(x); } while (0) - -static int full_paths;static int print_line;
@@ -507,14 +503,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->ip.pid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n" , +dump_printf ("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->header.misc, event->ip.pid, (void *)(long )ip); -dprintf (" ... thread: %s:%d\n" , thread->comm, thread->pid); +dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid);if (thread ==NULL ) { fprintf(stderr, "problem processing %d event, skipping it.\n",
@@ -528,7 +524,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) dso = kernel_dso; -dprintf (" ...... dso: %s\n" , dso->name); +dump_printf (" ...... dso: %s\n" , dso->name); }else if (event->header.misc &PERF_EVENT_MISC_USER ) {
@@ -549,12 +545,12 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)if ((long long )ip <0 ) dso = kernel_dso; } -dprintf (" ...... dso: %s\n" , dso ? dso->name :"<not found>" ); +dump_printf (" ...... dso: %s\n" , dso ? dso->name :"<not found>" ); }else { show =SHOW_HV ; level ='H' ; -dprintf (" ...... dso: [hypervisor]\n" ); +dump_printf (" ...... dso: [hypervisor]\n" ); }if (show & show_mask) {
@@ -582,7 +578,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->mmap.pid, &threads, &last_match); - dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", + dump_printf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", (void *)(offset + head), (void *)(long)(event->header.size), event->mmap.pid,
@@ -592,7 +588,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) event->mmap.filename);if (thread ==NULL || map ==NULL ) { -dprintf ("problem processing PERF_EVENT_MMAP, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_MMAP, skipping event.\n" );return 0 ; }
@@ -608,14 +604,14 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)struct thread *thread; thread =threads__findnew (event->comm.pid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT_COMM: %s:%d\n" , +dump_printf ("%p [%p]: PERF_EVENT_COMM: %s:%d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->comm.comm, event->comm.pid);if (thread ==NULL ||thread__set_comm (thread, event->comm.comm)) { -dprintf ("problem processing PERF_EVENT_COMM, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_COMM, skipping event.\n" );return -1 ; } total_comm++;
@@ -631,13 +627,13 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head) thread =threads__findnew (event->fork.pid, &threads, &last_match); parent =threads__findnew (event->fork.ppid, &threads, &last_match); -dprintf ("%p [%p]: PERF_EVENT_FORK: %d:%d\n" , +dump_printf ("%p [%p]: PERF_EVENT_FORK: %d:%d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->fork.pid, event->fork.ppid);if (!thread || !parent ||thread__fork (thread, parent)) { -dprintf ("problem processing PERF_EVENT_FORK, skipping event.\n" ); +dump_printf ("problem processing PERF_EVENT_FORK, skipping event.\n" );return -1 ; } total_fork++;
@@ -1022,14 +1018,14 @@ more: size = event->header.size; -dprintf ("%p [%p]: event: %d\n" , +dump_printf ("%p [%p]: event: %d\n" , (void *)(offset + head), (void *)(long )event->header.size, event->header.type);if (!size ||process_event (event, offset, head) <0 ) { -dprintf ("%p [%p]: skipping unknown header type: %d\n" , +dump_printf ("%p [%p]: skipping unknown header type: %d\n" , (void *)(offset + head), (void *)(long )(event->header.size), event->header.type);
@@ -1055,11 +1051,11 @@ more: rc =EXIT_SUCCESS ;close (input); -dprintf (" IP events: %10ld\n" , total); -dprintf (" mmap events: %10ld\n" , total_mmap); -dprintf (" comm events: %10ld\n" , total_comm); -dprintf (" fork events: %10ld\n" , total_fork); -dprintf (" unknown events: %10ld\n" , total_unknown); +dump_printf (" IP events: %10ld\n" , total); +dump_printf (" mmap events: %10ld\n" , total_mmap); +dump_printf (" comm events: %10ld\n" , total_comm); +dump_printf (" fork events: %10ld\n" , total_fork); +dump_printf (" unknown events: %10ld\n" , total_unknown);if (dump_trace)return 0 ;
tools/perf/builtin-report.c +27 -29
183 lines not on this page · raw message
tools/perf/util/debug.c +15 -0
@@ -6,6 +6,7 @@#include <stdio.h> int verbose =0 ; +int dump_trace =0 ;int eprintf (const char *fmt, ...) {
@@ -20,3 +21,17 @@ int eprintf(const char *fmt, ...)return ret; } + +int dump_printf (const char *fmt, ...) +{ +va_list args; +int ret =0 ; + +if (dump_trace) { +va_start (args, fmt); + ret =vprintf (fmt, args); +va_end (args); + } + +return ret; +}
tools/perf/util/debug.h +2 -0
@@ -1,5 +1,7 @@/* For debugging general purposes */ extern int verbose; +extern int dump_trace;int eprintf (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +int dump_printf (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));
PATCH 1/1 perf tools: Librarize sample type and attr finding from headers
In reply to Frederic WeisbeckerLibrarize the sample type and attr fetching from perf data file headers so that we can also use it from perf trace.
--- tools/perf/builtin-report.c | 44 +++++------------------------------------- tools/perf/util/header.c | 35 ++++++++++++++++++++++++++++++++++ tools/perf/util/header.h | 4 +++ 3 files changed, 45 insertions(+), 38 deletions(-)
tools/perf/builtin-report.c +6 -38
@@ -70,6 +70,8 @@ static int cwdlen;static struct rb_root threads;static struct thread *last_match; +static struct perf_header *header; +static struct callchain_param callchain_param = { .mode =CHAIN_GRAPH_REL ,
@@ -1319,29 +1321,12 @@ static void trace_event(event_t *event)dump_printf (".\n" ); } -static struct perf_header *header; - -static struct perf_counter_attr *perf_header__find_attr (u64 id) -{ -int i; - -for (i =0 ; i < header->attrs; i++) { -struct perf_header_attr *attr = header->attr[i]; -int j; - -for (j =0 ; j < attr->ids; j++) { -if (attr->id[j] == id) -return &attr->attr; - } - } - -return NULL ; -} -static int process_read_event (event_t *event,unsigned long offset,unsigned long head) { -struct perf_counter_attr *attr =perf_header__find_attr (event->read.id); +struct perf_counter_attr *attr; + + attr =perf_header__find_attr (event->read.id, header);if (show_threads) { const char *name = attr ? __event_name(attr->type, attr->config)
@@ -1405,23 +1390,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)return 0 ; } -static u64 perf_header__sample_type (void ) -{ -u64 type =0 ; -int i; - -for (i =0 ; i < header->attrs; i++) { -struct perf_header_attr *attr = header->attr[i]; - -if (!type) - type = attr->attr.sample_type; -else if (type != attr->attr.sample_type) -die ("non matching sample_type" ); - } - -return type; -} -static int __cmd_report (void ) {int ret, rc =EXIT_FAILURE ;
@@ -1460,7 +1428,7 @@ static int __cmd_report(void) header =perf_header__read (input); head = header->data_offset; - sample_type =perf_header__sample_type (); + sample_type =perf_header__sample_type (header);if (!(sample_type &PERF_SAMPLE_CALLCHAIN )) {if (sort__has_parent) {
tools/perf/util/header.c +35 -0
@@ -243,3 +243,38 @@ struct perf_header *perf_header__read(int fd)return self; } + +u64 perf_header__sample_type (struct perf_header *header) +{ +u64 type =0 ; +int i; + +for (i =0 ; i < header->attrs; i++) { +struct perf_header_attr *attr = header->attr[i]; + +if (!type) + type = attr->attr.sample_type; +else if (type != attr->attr.sample_type) +die ("non matching sample_type" ); + } + +return type; +} + +struct perf_counter_attr * +perf_header__find_attr (u64 id,struct perf_header *header) +{ +int i; + +for (i =0 ; i < header->attrs; i++) { +struct perf_header_attr *attr = header->attr[i]; +int j; + +for (j =0 ; j < attr->ids; j++) { +if (attr->id[j] == id) +return &attr->attr; + } + } + +return NULL ; +}
tools/perf/util/header.h +4 -0
@@ -31,6 +31,10 @@ struct perf_header_attr * perf_header_attr__new(struct perf_counter_attr *attr);void perf_header_attr__add_id (struct perf_header_attr *self,u64 id); +u64 perf_header__sample_type (struct perf_header *header); +struct perf_counter_attr * +perf_header__find_attr (u64 id,struct perf_header *header); +struct perf_header *perf_header__new (void );
Signature · 1 line
1.6.2.3
[tip:perfcounters/core] perf tools: Librarize sample type and attr finding from headers
Commit-ID: 0d3a5c885971de1e3124d85bfadf818abac9ba12 Gitweb: http://git.kernel.org/tip/0d3a5c885971de1e3124d85bfadf818abac9ba12 Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 16 Aug 2009 20:56:37 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 16 Aug 2009 23:06:44 +0200
perf tools: Librarize sample type and attr finding from headers
Librarize the sample type and attr fetching from perf data file headers so that we can also use it from perf trace.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-report.c | 44 +++++------------------------------------- tools/perf/util/header.c | 35 ++++++++++++++++++++++++++++++++++ tools/perf/util/header.h | 4 +++ 3 files changed, 45 insertions(+), 38 deletions(-)
tools/perf/builtin-report.c +6 -38
@@ -70,6 +70,8 @@ static int cwdlen;static struct rb_root threads;static struct thread *last_match; +static struct perf_header *header; +static struct callchain_param callchain_param = { .mode =CHAIN_GRAPH_REL ,
@@ -1319,29 +1321,12 @@ static void trace_event(event_t *event)dump_printf (".\n" ); } -static struct perf_header *header; - -static struct perf_counter_attr *perf_header__find_attr (u64 id) -{ -int i; - -for (i =0 ; i < header->attrs; i++) { -struct perf_header_attr *attr = header->attr[i]; -int j; - -for (j =0 ; j < attr->ids; j++) { -if (attr->id[j] == id) -return &attr->attr; - } - } - -return NULL ; -} -static int process_read_event (event_t *event,unsigned long offset,unsigned long head) { -struct perf_counter_attr *attr =perf_header__find_attr (event->read.id); +struct perf_counter_attr *attr; + + attr =perf_header__find_attr (event->read.id, header);if (show_threads) { const char *name = attr ? __event_name(attr->type, attr->config)
@@ -1405,23 +1390,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)return 0 ; } -static u64 perf_header__sample_type (void ) -{ -u64 type =0 ; -int i; - -for (i =0 ; i < header->attrs; i++) { -struct perf_header_attr *attr = header->attr[i]; - -if (!type) - type = attr->attr.sample_type; -else if (type != attr->attr.sample_type) -die ("non matching sample_type" ); - } - -return type; -} -static int __cmd_report (void ) {int ret, rc =EXIT_FAILURE ;
@@ -1460,7 +1428,7 @@ static int __cmd_report(void) header =perf_header__read (input); head = header->data_offset; - sample_type =perf_header__sample_type (); + sample_type =perf_header__sample_type (header);if (!(sample_type &PERF_SAMPLE_CALLCHAIN )) {if (sort__has_parent) {
tools/perf/util/header.c +35 -0
@@ -243,3 +243,38 @@ struct perf_header *perf_header__read(int fd)return self; } + +u64 perf_header__sample_type (struct perf_header *header) +{ +u64 type =0 ; +int i; + +for (i =0 ; i < header->attrs; i++) { +struct perf_header_attr *attr = header->attr[i]; + +if (!type) + type = attr->attr.sample_type; +else if (type != attr->attr.sample_type) +die ("non matching sample_type" ); + } + +return type; +} + +struct perf_counter_attr * +perf_header__find_attr (u64 id,struct perf_header *header) +{ +int i; + +for (i =0 ; i < header->attrs; i++) { +struct perf_header_attr *attr = header->attr[i]; +int j; + +for (j =0 ; j < attr->ids; j++) { +if (attr->id[j] == id) +return &attr->attr; + } + } + +return NULL ; +}
tools/perf/util/header.h +4 -0
@@ -31,6 +31,10 @@ struct perf_header_attr * perf_header_attr__new(struct perf_counter_attr *attr);void perf_header_attr__add_id (struct perf_header_attr *self,u64 id); +u64 perf_header__sample_type (struct perf_header *header); +struct perf_counter_attr * +perf_header__find_attr (u64 id,struct perf_header *header); +struct perf_header *perf_header__new (void );
PATCH 1/1 perf tools: Librarize trace_event() helper
In reply to Frederic WeisbeckerLibrarize trace_event() helper so that perf trace can use it too. Also cleanup a bit the debug.h includes. It's not good to have it included in perf.h because it doesn't make it flexible against other headers it may need (headers that can also depend on perf.h and then create a recursive header dependency).
--- tools/perf/builtin-annotate.c | 1 + tools/perf/builtin-record.c | 1 + tools/perf/builtin-report.c | 39 +-------------------------- tools/perf/builtin-stat.c | 2 + tools/perf/builtin-top.c | 2 + tools/perf/perf.h | 1 - tools/perf/util/color.c | 10 +++++-- tools/perf/util/color.h | 1 + tools/perf/util/debug.c | 58 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/debug.h | 1 + tools/perf/util/symbol.c | 2 + 11 files changed, 76 insertions(+), 42 deletions(-)
tools/perf/builtin-annotate.c +1 -0
@@ -17,6 +17,7 @@#include "util/string.h" #include "perf.h" +#include "util/debug.h" #include "util/parse-options.h" #include "util/parse-events.h"
tools/perf/builtin-record.c +1 -0
@@ -16,6 +16,7 @@#include "util/header.h" #include "util/event.h" +#include "util/debug.h" #include <unistd.h> #include <sched.h>
tools/perf/builtin-report.c +1 -38
@@ -20,6 +20,7 @@#include "util/values.h" #include "perf.h" +#include "util/debug.h" #include "util/header.h" #include "util/parse-options.h"
@@ -39,8 +40,6 @@ static char *field_sep;static int input;static int show_mask =SHOW_KERNEL |SHOW_USER |SHOW_HV ; -#define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0) -static int full_paths;static int show_nr_samples;
@@ -1285,42 +1284,6 @@ process_lost_event(event_t *event, unsigned long offset, unsigned long head)return 0 ; } -static void trace_event (event_t *event) -{ -unsigned char *raw_event = (void *)event; -const char *color =PERF_COLOR_BLUE ; -int i, j; - -if (!dump_trace) -return ; - -dump_printf ("." ); -cdprintf ("\n. ... raw event: size %d bytes\n" , event->header.size); - -for (i =0 ; i < event->header.size; i++) { -if ((i &15 ) ==0 ) { -dump_printf ("." ); -cdprintf (" %04x: " , i); - } - -cdprintf (" %02x" , raw_event[i]); - -if (((i &15 ) ==15 ) || i == event->header.size-1 ) { -cdprintf (" " ); -for (j =0 ; j <15 -(i &15 ); j++) -cdprintf (" " ); -for (j =0 ; j < (i &15 ); j++) { -if (isprint (raw_event[i-15 +j])) -cdprintf ("%c" , raw_event[i-15 +j]); -else -cdprintf ("." ); - } -cdprintf ("\n" ); - } - } -dump_printf (".\n" ); -} -static int process_read_event (event_t *event,unsigned long offset,unsigned long head) {
tools/perf/builtin-stat.c +2 -0
@@ -42,6 +42,8 @@#include "util/util.h" #include "util/parse-options.h" #include "util/parse-events.h" +#include "util/event.h" +#include "util/debug.h" #include <sys/prctl.h> #include <math.h>
tools/perf/builtin-top.c +2 -0
@@ -27,6 +27,8 @@#include "util/parse-options.h" #include "util/parse-events.h" +#include "util/debug.h" +#include <assert.h> #include <fcntl.h>
tools/perf/perf.h +0 -1
@@ -48,7 +48,6 @@#include "../../include/linux/perf_counter.h" #include "util/types.h" -#include "util/debug.h" /* * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
tools/perf/util/color.c +7 -3
@@ -166,7 +166,7 @@ int perf_color_default_config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } -static int color_vfprintf (FILE *fp,const char *color,const char *fmt, +static int __color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args,const char *trail) {int r =0 ;
@@ -191,6 +191,10 @@ static int color_vfprintf(FILE *fp, const char *color, const char *fmt,return r; } +int color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args) +{ +return __color_vfprintf (fp, color, fmt, args,NULL ); +}int color_fprintf (FILE *fp,const char *color,const char *fmt, ...)
@@ -199,7 +203,7 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)int r;va_start (args, fmt); - r =color_vfprintf (fp, color, fmt, args,NULL ); + r =color_vfprintf (fp, color, fmt, args);va_end (args);return r; }
@@ -209,7 +213,7 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)va_list args;int r;va_start (args, fmt); - r =color_vfprintf (fp, color, fmt, args,"\n" ); + r =__color_vfprintf (fp, color, fmt, args,"\n" );va_end (args);return r; }
tools/perf/util/color.h +1 -0
@@ -32,6 +32,7 @@ int perf_color_default_config(const char *var, const char *value, void *cb);int perf_config_colorbool (const char *var,const char *value,int stdout_is_tty);void color_parse (const char *value,const char *var,char *dst);void color_parse_mem (const char *value,int len,const char *var,char *dst); +int color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args);int color_fprintf (FILE *fp,const char *color,const char *fmt, ...);int color_fprintf_ln (FILE *fp,const char *color,const char *fmt, ...);int color_fwrite_lines (FILE *fp,const char *color,size_t count,const char *buf);
tools/perf/util/debug.c +58 -0
71 lines not on this page · raw message
tools/perf/util/debug.h +1 -0
@@ -5,3 +5,4 @@ extern int dump_trace;int eprintf (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));int dump_printf (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +void trace_event (event_t *event);
tools/perf/util/symbol.c +2 -0
@@ -3,6 +3,8 @@#include "string.h" #include "symbol.h" +#include "debug.h" +#include <libelf.h> #include <gelf.h> #include <elf.h>
Signature · 1 line
1.6.2.3
[tip:perfcounters/core] perf tools: Librarize trace_event() helper
Commit-ID: 8f28827a162fd1e8da4e96bed69b06d2606e8322 Gitweb: http://git.kernel.org/tip/8f28827a162fd1e8da4e96bed69b06d2606e8322 Author: Frederic Weisbecker <[email protected]> AuthorDate: Sun, 16 Aug 2009 22:05:48 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 16 Aug 2009 23:06:45 +0200
perf tools: Librarize trace_event() helper
Librarize trace_event() helper so that perf trace can use it too. Also clean up the debug.h includes a bit.
It's not good to have it included in perf.h because it doesn't make it flexible against other headers it may need (headers that can also depend on perf.h and then create a recursive header dependency).
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 1 + tools/perf/builtin-record.c | 1 + tools/perf/builtin-report.c | 39 +-------------------------- tools/perf/builtin-stat.c | 2 + tools/perf/builtin-top.c | 2 + tools/perf/perf.h | 1 - tools/perf/util/color.c | 10 +++++-- tools/perf/util/color.h | 1 + tools/perf/util/debug.c | 58 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/debug.h | 1 + tools/perf/util/symbol.c | 2 + 11 files changed, 76 insertions(+), 42 deletions(-)
tools/perf/builtin-annotate.c +1 -0
@@ -17,6 +17,7 @@#include "util/string.h" #include "perf.h" +#include "util/debug.h" #include "util/parse-options.h" #include "util/parse-events.h"
tools/perf/builtin-record.c +1 -0
@@ -16,6 +16,7 @@#include "util/header.h" #include "util/event.h" +#include "util/debug.h" #include <unistd.h> #include <sched.h>
tools/perf/builtin-report.c +1 -38
@@ -20,6 +20,7 @@#include "util/values.h" #include "perf.h" +#include "util/debug.h" #include "util/header.h" #include "util/parse-options.h"
@@ -39,8 +40,6 @@ static char *field_sep;static int input;static int show_mask =SHOW_KERNEL |SHOW_USER |SHOW_HV ; -#define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0) -static int full_paths;static int show_nr_samples;
@@ -1285,42 +1284,6 @@ process_lost_event(event_t *event, unsigned long offset, unsigned long head)return 0 ; } -static void trace_event (event_t *event) -{ -unsigned char *raw_event = (void *)event; -const char *color =PERF_COLOR_BLUE ; -int i, j; - -if (!dump_trace) -return ; - -dump_printf ("." ); -cdprintf ("\n. ... raw event: size %d bytes\n" , event->header.size); - -for (i =0 ; i < event->header.size; i++) { -if ((i &15 ) ==0 ) { -dump_printf ("." ); -cdprintf (" %04x: " , i); - } - -cdprintf (" %02x" , raw_event[i]); - -if (((i &15 ) ==15 ) || i == event->header.size-1 ) { -cdprintf (" " ); -for (j =0 ; j <15 -(i &15 ); j++) -cdprintf (" " ); -for (j =0 ; j < (i &15 ); j++) { -if (isprint (raw_event[i-15 +j])) -cdprintf ("%c" , raw_event[i-15 +j]); -else -cdprintf ("." ); - } -cdprintf ("\n" ); - } - } -dump_printf (".\n" ); -} -static int process_read_event (event_t *event,unsigned long offset,unsigned long head) {
tools/perf/builtin-stat.c +2 -0
@@ -42,6 +42,8 @@#include "util/util.h" #include "util/parse-options.h" #include "util/parse-events.h" +#include "util/event.h" +#include "util/debug.h" #include <sys/prctl.h> #include <math.h>
tools/perf/builtin-top.c +2 -0
@@ -27,6 +27,8 @@#include "util/parse-options.h" #include "util/parse-events.h" +#include "util/debug.h" +#include <assert.h> #include <fcntl.h>
tools/perf/perf.h +0 -1
@@ -48,7 +48,6 @@#include "../../include/linux/perf_counter.h" #include "util/types.h" -#include "util/debug.h" /* * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
tools/perf/util/color.c +7 -3
@@ -166,7 +166,7 @@ int perf_color_default_config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } -static int color_vfprintf (FILE *fp,const char *color,const char *fmt, +static int __color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args,const char *trail) {int r =0 ;
@@ -191,6 +191,10 @@ static int color_vfprintf(FILE *fp, const char *color, const char *fmt,return r; } +int color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args) +{ +return __color_vfprintf (fp, color, fmt, args,NULL ); +}int color_fprintf (FILE *fp,const char *color,const char *fmt, ...)
@@ -199,7 +203,7 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)int r;va_start (args, fmt); - r =color_vfprintf (fp, color, fmt, args,NULL ); + r =color_vfprintf (fp, color, fmt, args);va_end (args);return r; }
@@ -209,7 +213,7 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)va_list args;int r;va_start (args, fmt); - r =color_vfprintf (fp, color, fmt, args,"\n" ); + r =__color_vfprintf (fp, color, fmt, args,"\n" );va_end (args);return r; }
tools/perf/util/color.h +1 -0
@@ -32,6 +32,7 @@ int perf_color_default_config(const char *var, const char *value, void *cb);int perf_config_colorbool (const char *var,const char *value,int stdout_is_tty);void color_parse (const char *value,const char *var,char *dst);void color_parse_mem (const char *value,int len,const char *var,char *dst); +int color_vfprintf (FILE *fp,const char *color,const char *fmt,va_list args);int color_fprintf (FILE *fp,const char *color,const char *fmt, ...);int color_fprintf_ln (FILE *fp,const char *color,const char *fmt, ...);int color_fwrite_lines (FILE *fp,const char *color,size_t count,const char *buf);
tools/perf/util/debug.c +58 -0
71 lines not on this page · raw message
tools/perf/util/debug.h +1 -0
@@ -5,3 +5,4 @@ extern int dump_trace;int eprintf (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));int dump_printf (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +void trace_event (event_t *event);
tools/perf/util/symbol.c +2 -0
@@ -3,6 +3,8 @@#include "string.h" #include "symbol.h" +#include "debug.h" +#include <libelf.h> #include <gelf.h> #include <elf.h>