perf tools: Introduce event selectors
Commit-ID: 69aad6f1ee69546dea8535ab8f3da9f445d57328 Gitweb: http://git.kernel.org/tip/69aad6f1ee69546dea8535ab8f3da9f445d57328 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 3 Jan 2011 16:39:04 -0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 3 Jan 2011 16:39:04 -0200
perf tools: Introduce event selectors
Out of ad-hoc code and global arrays with hard coded sizes.
This is the first step on having a library that will be first used on regression tests in the 'perf test' tool.
[acme@felicio linux]$ size /tmp/perf.before
text data bss dec hex filename
1273776 97384 5104416 6475576 62cf38 /tmp/perf.before
[acme@felicio linux]$ size /tmp/perf.new
text data bss dec hex filename
1275422 97416 1392416 2765254 2a31c6 /tmp/perf.new
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <new-submission>
--- tools/perf/Makefile | 4 + tools/perf/builtin-record.c | 113 +++++++++++------------ tools/perf/builtin-stat.c | 175 ++++++++++++++++++++++-------------- tools/perf/builtin-top.c | 176 +++++++++++++++++++++--------------- tools/perf/util/evsel.c | 35 +++++++ tools/perf/util/evsel.h | 24 +++++ tools/perf/util/header.c | 9 +- tools/perf/util/header.h | 3 +- tools/perf/util/parse-events.c | 47 +++++++---- tools/perf/util/parse-events.h | 17 +++-- tools/perf/util/trace-event-info.c | 30 ++++--- tools/perf/util/trace-event.h | 5 +- tools/perf/util/xyarray.c | 20 ++++ tools/perf/util/xyarray.h | 20 ++++ 14 files changed, 433 insertions(+), 245 deletions(-)
tools/perf/Makefile +4 -0
@@ -396,6 +396,7 @@ LIB_H += util/build-id.h LIB_H += util/debug.h LIB_H += util/debugfs.h LIB_H += util/event.h +LIB_H += util/evsel.h LIB_H += util/exec_cmd.h LIB_H += util/types.h LIB_H += util/levenshtein.h
@@ -404,6 +405,7 @@ LIB_H += util/parse-options.h LIB_H += util/parse-events.h LIB_H += util/quote.h LIB_H += util/util.h +LIB_H += util/xyarray.h LIB_H += util/header.h LIB_H += util/help.h LIB_H += util/session.h
@@ -433,6 +435,7 @@ LIB_OBJS += $(OUTPUT)util/ctype.o LIB_OBJS += $(OUTPUT)util/debugfs.o LIB_OBJS += $(OUTPUT)util/environment.o LIB_OBJS += $(OUTPUT)util/event.o +LIB_OBJS += $(OUTPUT)util/evsel.o LIB_OBJS += $(OUTPUT)util/exec_cmd.o LIB_OBJS += $(OUTPUT)util/help.o LIB_OBJS += $(OUTPUT)util/levenshtein.o
@@ -470,6 +473,7 @@ LIB_OBJS += $(OUTPUT)util/sort.o LIB_OBJS += $(OUTPUT)util/hist.o LIB_OBJS += $(OUTPUT)util/probe-event.o LIB_OBJS += $(OUTPUT)util/util.o +LIB_OBJS += $(OUTPUT)util/xyarray.o LIB_OBJS += $(OUTPUT)util/cpumap.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
tools/perf/builtin-record.c +54 -59
270 lines not on this page · raw message
tools/perf/builtin-stat.c +107 -68
402 lines not on this page · raw message
tools/perf/builtin-top.c +104 -72
382 lines not on this page · raw message
tools/perf/util/evsel.c new file +35 -0
@@ -0,0 +1,35 @@ +#include "evsel.h" +#include "util.h" + +struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx) +{ +struct perf_evsel *evsel =zalloc (sizeof (*evsel)); + +if (evsel !=NULL ) { + evsel->idx = idx; + evsel->attr.type = type; + evsel->attr.config = config; +INIT_LIST_HEAD (&evsel->node); + } + +return evsel; +} + +int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads) +{ + evsel->fd =xyarray__new (ncpus, nthreads,sizeof (int )); +return evsel->fd !=NULL ?0 : -ENOMEM ; +} + +void perf_evsel__free_fd (struct perf_evsel *evsel) +{ +xyarray__delete (evsel->fd); + evsel->fd =NULL ; +} + +void perf_evsel__delete (struct perf_evsel *evsel) +{ +assert (list_empty (&evsel->node)); +xyarray__delete (evsel->fd); +free (evsel); +}
tools/perf/util/evsel.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __PERF_EVSEL_H +#define __PERF_EVSEL_H 1 + +#include <linux/list.h> +#include <linux/perf_event.h> +#include "types.h" +#include "xyarray.h" + +struct perf_evsel { +struct list_head node; +struct perf_event_attr attr; +char *filter; +struct xyarray *fd; +int idx; +void *priv; +}; + +struct perf_evsel *perf_evsel__new (u32 type,u64 config,int idx); +void perf_evsel__delete (struct perf_evsel *evsel); + +int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads); +void perf_evsel__free_fd (struct perf_evsel *evsel); + +#endif /* __PERF_EVSEL_H */
tools/perf/util/header.c +4 -5
@@ -461,7 +461,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd)/* Write trace info */ trace_sec->offset =lseek (fd,0 ,SEEK_CUR ); -read_tracing_data (fd, attrs, nr_counters); +read_tracing_data (fd, &evsel_list); trace_sec->size =lseek (fd,0 ,SEEK_CUR ) - trace_sec->offset; }
@@ -1131,8 +1131,7 @@ int event__process_event_type(event_t *self,return 0 ; } -int event__synthesize_tracing_data (int fd,struct perf_event_attr *pattrs, -int nb_events, +int event__synthesize_tracing_data (int fd,struct list_head *pattrs,event__handler_t process, struct perf_session *session __unused) {
@@ -1143,7 +1142,7 @@ int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs,memset (&ev,0 ,sizeof (ev)); ev.tracing_data.header.type =PERF_RECORD_HEADER_TRACING_DATA ; - size =read_tracing_data_size (fd, pattrs, nb_events); + size =read_tracing_data_size (fd, pattrs);if (size <=0 )return size; aligned_size =ALIGN (size,sizeof (u64));
@@ -1153,7 +1152,7 @@ int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs,process (&ev,NULL , session); - err =read_tracing_data (fd, pattrs, nb_events); + err =read_tracing_data (fd, pattrs);write_padded (fd,NULL ,0 , padding);return aligned_size;
tools/perf/util/header.h +1 -2
@@ -113,8 +113,7 @@ int event__synthesize_event_types(event__handler_t process,int event__process_event_type (event_t *self,struct perf_session *session); -int event__synthesize_tracing_data (int fd,struct perf_event_attr *pattrs, -int nb_events, +int event__synthesize_tracing_data (int fd,struct list_head *pattrs,event__handler_t process,struct perf_session *session); int event__process_tracing_data(event_t *self,
tools/perf/util/parse-events.c +31 -16
96 lines not on this page · raw message
tools/perf/util/parse-events.h +11 -6
@@ -4,6 +4,15 @@* Parse symbolic events/counts passed in as options: */ +#include <linux/perf_event.h> + +struct list_head ; +struct perf_evsel ; + +extern struct list_head evsel_list; + +int perf_evsel_list__create_default (void ); +struct option ;struct tracepoint_path {
@@ -13,14 +22,11 @@ struct tracepoint_path { };extern struct tracepoint_path *tracepoint_id_to_path (u64 config); -extern bool have_tracepoints (struct perf_event_attr *pattrs,int nb_events); +extern bool have_tracepoints (struct list_head *evsel_list);extern int nr_counters; -extern struct perf_event_attr attrs[MAX_COUNTERS ]; -extern char *filters[MAX_COUNTERS ]; - -extern const char *event_name (int ctr); +const char *event_name (struct perf_evsel *event);extern const char *__event_name (int type,u64 config);extern int parse_events (const struct option *opt,const char *str,int unset);
@@ -33,5 +39,4 @@ extern void print_events(void);extern char debugfs_path[];extern int valid_debugfs_mount (const char *debugfs); -#endif /* __PERF_PARSE_EVENTS_H */
tools/perf/util/trace-event-info.c +16 -14
@@ -34,11 +34,13 @@#include <ctype.h> #include <errno.h> #include <stdbool.h> +#include <linux/list.h> #include <linux/kernel.h> #include "../perf.h" #include "trace-event.h" #include "debugfs.h" +#include "evsel.h" #define VERSION "0.5"
@@ -469,16 +471,17 @@ out: }static struct tracepoint_path * -get_tracepoints_path (struct perf_event_attr *pattrs,int nb_events) +get_tracepoints_path (struct list_head *pattrs) {struct tracepoint_path path, *ppath = &path; -int i, nr_tracepoints =0 ; +struct perf_evsel *pos; +int nr_tracepoints =0 ; -for (i =0 ; i < nb_events; i++) { -if (pattrs[i].type !=PERF_TYPE_TRACEPOINT ) +list_for_each_entry (pos, pattrs, node) { +if (pos->attr.type !=PERF_TYPE_TRACEPOINT )continue ; ++nr_tracepoints; - ppath->next =tracepoint_id_to_path (pattrs[i].config); + ppath->next =tracepoint_id_to_path (pos->attr.config);if (!ppath->next)die ("%s\n" ,"No memory to alloc tracepoints list" ); ppath = ppath->next;
@@ -487,21 +490,21 @@ get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)return nr_tracepoints >0 ? path.next :NULL ; } -bool have_tracepoints (struct perf_event_attr *pattrs,int nb_events) +bool have_tracepoints (struct list_head *pattrs) { -int i; +struct perf_evsel *pos; -for (i =0 ; i < nb_events; i++) -if (pattrs[i].type ==PERF_TYPE_TRACEPOINT ) +list_for_each_entry (pos, pattrs, node) +if (pos->attr.type ==PERF_TYPE_TRACEPOINT )return true;return false; } -int read_tracing_data (int fd,struct perf_event_attr *pattrs,int nb_events) +int read_tracing_data (int fd,struct list_head *pattrs) {char buf[BUFSIZ ]; -struct tracepoint_path *tps =get_tracepoints_path (pattrs, nb_events); +struct tracepoint_path *tps =get_tracepoints_path (pattrs);/* * What? No tracepoints? No sense writing anything here, bail out.
@@ -545,14 +548,13 @@ int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)return 0 ; } -ssize_t read_tracing_data_size (int fd,struct perf_event_attr *pattrs, -int nb_events) +ssize_t read_tracing_data_size (int fd,struct list_head *pattrs) {ssize_t size;int err =0 ; calc_data_size =1 ; - err =read_tracing_data (fd, pattrs, nb_events); + err =read_tracing_data (fd, pattrs); size = calc_data_size -1 ; calc_data_size =0 ;
tools/perf/util/trace-event.h +2 -3
@@ -262,9 +262,8 @@ raw_field_value(struct event *event, const char *name, void *data);void *raw_field_ptr (struct event *event,const char *name,void *data);unsigned long long eval_flag (const char *flag); -int read_tracing_data (int fd,struct perf_event_attr *pattrs,int nb_events); -ssize_t read_tracing_data_size (int fd,struct perf_event_attr *pattrs, -int nb_events); +int read_tracing_data (int fd,struct list_head *pattrs); +ssize_t read_tracing_data_size (int fd,struct list_head *pattrs);/* taken from kernel/trace/trace.h */ enum trace_flag_type {
tools/perf/util/xyarray.c new file +20 -0
@@ -0,0 +1,20 @@ +#include "xyarray.h" +#include "util.h" + +struct xyarray *xyarray__new (int xlen,int ylen,size_t entry_size) +{ +size_t row_size = ylen * entry_size; +struct xyarray *xy =zalloc (sizeof (*xy) + xlen * row_size); + +if (xy !=NULL ) { + xy->entry_size = entry_size; + xy->row_size = row_size; + } + +return xy; +} + +void xyarray__delete (struct xyarray *xy) +{ +free (xy); +}
tools/perf/util/xyarray.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef _PERF_XYARRAY_H_ +#define _PERF_XYARRAY_H_ 1 + +#include <sys/types.h> + +struct xyarray { +size_t row_size; +size_t entry_size; +char contents[]; +}; + +struct xyarray *xyarray__new (int xlen,int ylen,size_t entry_size); +void xyarray__delete (struct xyarray *xy); + +static inline void *xyarray__entry (struct xyarray *xy,int x,int y) +{ +return &xy->contents[x * xy->row_size + y * xy->entry_size]; +} + +#endif /* _PERF_XYARRAY_H_ */