perf evsel: Introduce perf_evlist
Commit-ID: 361c99a661a78ed22264649440e87fe4fe8da1f2 Gitweb: http://git.kernel.org/tip/361c99a661a78ed22264649440e87fe4fe8da1f2 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 11 Jan 2011 20:56:53 -0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Sat, 22 Jan 2011 19:56:28 -0200
perf evsel: Introduce perf_evlist
Killing two more perf wide global variables: nr_counters and evsel_list as a list_head.
There are more operations that will need more fields in perf_evlist, like the pollfd for polling all the fds in a list of evsel instances.
Use option->value to pass the evsel_list to parse_{events,filters}.
LKML-Reference: <new-submission>
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]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/Makefile | 2 + tools/perf/builtin-record.c | 47 ++++++++++++++++----------- tools/perf/builtin-stat.c | 34 +++++++++++-------- tools/perf/builtin-top.c | 60 +++++++++++++++++++-------------- tools/perf/util/evlist.c | 53 ++++++++++++++++++++++++++++++ tools/perf/util/evlist.h | 19 +++++++++++ tools/perf/util/header.c | 17 ++++++---- tools/perf/util/header.h | 7 +++- tools/perf/util/include/linux/list.h | 1 + tools/perf/util/parse-events.c | 51 +++++----------------------- tools/perf/util/parse-events.h | 7 ---- 11 files changed, 180 insertions(+), 118 deletions(-)
tools/perf/Makefile +2 -0
@@ -402,6 +402,7 @@ LIB_H += util/debug.h LIB_H += util/debugfs.h LIB_H += util/event.h LIB_H += util/evsel.h +LIB_H += util/evlist.h LIB_H += util/exec_cmd.h LIB_H += util/types.h LIB_H += util/levenshtein.h
@@ -440,6 +441,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/evlist.o LIB_OBJS += $(OUTPUT)util/evsel.o LIB_OBJS += $(OUTPUT)util/exec_cmd.o LIB_OBJS += $(OUTPUT)util/help.o
tools/perf/builtin-record.c +28 -19
159 lines not on this page · raw message
tools/perf/builtin-stat.c +19 -15
@@ -43,6 +43,7 @@#include "util/parse-options.h" #include "util/parse-events.h" #include "util/event.h" +#include "util/evlist.h" #include "util/evsel.h" #include "util/debug.h" #include "util/header.h"
@@ -71,6 +72,8 @@ static struct perf_event_attr default_attrs[] = { }; +struct perf_evlist *evsel_list; +static bool system_wide = false;static struct cpu_map *cpus;static int run_idx =0 ;
@@ -309,7 +312,7 @@ static int run_perf_stat(int argc __used, const char **argv)close (child_ready_pipe[0 ]); } -list_for_each_entry (counter, &evsel_list, node) { +list_for_each_entry (counter, &evsel_list->entries, node) {if (create_perf_stat_counter (counter) <0 ) {if (errno == -EPERM || errno == -EACCES ) { error("You may not have permission to collect %sstats.\n"
@@ -347,12 +350,12 @@ static int run_perf_stat(int argc __used, const char **argv)update_stats (&walltime_nsecs_stats, t1 - t0);if (no_aggr) { -list_for_each_entry (counter, &evsel_list, node) { +list_for_each_entry (counter, &evsel_list->entries, node) {read_counter (counter);perf_evsel__close_fd (counter, cpus->nr,1 ); } }else { -list_for_each_entry (counter, &evsel_list, node) { +list_for_each_entry (counter, &evsel_list->entries, node) {read_counter_aggr (counter);perf_evsel__close_fd (counter, cpus->nr, threads->nr); }
@@ -555,10 +558,10 @@ static void print_stat(int argc, const char **argv) }if (no_aggr) { -list_for_each_entry (counter, &evsel_list, node) +list_for_each_entry (counter, &evsel_list->entries, node)print_counter (counter); }else { -list_for_each_entry (counter, &evsel_list, node) +list_for_each_entry (counter, &evsel_list->entries, node)print_counter_aggr (counter); }
@@ -610,7 +613,7 @@ static int stat__set_big_num(const struct option *opt __used, }static const struct option options[] = { -OPT_CALLBACK ('e' ,"event" ,NULL ,"event" , +OPT_CALLBACK ('e' ,"event" , &evsel_list,"event" ,"event selector. use 'perf list' to list available events" , parse_events), OPT_BOOLEAN('i', "no-inherit", &no_inherit,
@@ -648,6 +651,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)setlocale (LC_ALL ,"" ); + evsel_list =perf_evlist__new (); +if (evsel_list ==NULL ) +return -ENOMEM ; + argc =parse_options (argc, argv, options, stat_usage,PARSE_OPT_STOP_AT_NON_OPTION );
@@ -679,17 +686,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)usage_with_options (stat_usage, options);/* Set attrs and nr_counters if no event is selected and !null_run */ -if (!null_run && !nr_counters) { +if (!null_run && !evsel_list->nr_entries) {size_t c; - nr_counters =ARRAY_SIZE (default_attrs); -for (c =0 ; c <ARRAY_SIZE (default_attrs); ++c) { - pos =perf_evsel__new (&default_attrs[c], - nr_counters); + pos =perf_evsel__new (&default_attrs[c], c);if (pos ==NULL ) goto out; -list_add (&pos->node, &evsel_list); +perf_evlist__add (evsel_list, pos); } }
@@ -713,7 +717,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)return -1 ; } -list_for_each_entry (pos, &evsel_list, node) { +list_for_each_entry (pos, &evsel_list->entries, node) {if (perf_evsel__alloc_stat_priv (pos) <0 ||perf_evsel__alloc_counts (pos, cpus->nr) <0 ||perf_evsel__alloc_fd (pos, cpus->nr, threads->nr) <0 )
@@ -741,9 +745,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)if (status !=-1 )print_stat (argc, argv); out_free_fd: -list_for_each_entry (pos, &evsel_list, node) +list_for_each_entry (pos, &evsel_list->entries, node)perf_evsel__free_stat_priv (pos); -perf_evsel_list__delete (); +perf_evlist__delete (evsel_list); out:thread_map__delete (threads); threads =NULL ;
tools/perf/builtin-top.c +34 -26
207 lines not on this page · raw message
tools/perf/util/evlist.c new file +53 -0
53 lines not on this page · raw message
tools/perf/util/evlist.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef __PERF_EVLIST_H +#define __PERF_EVLIST_H 1 + +#include <linux/list.h> + +struct perf_evlist { +struct list_head entries; +int nr_entries; +}; + +struct perf_evsel ; + +struct perf_evlist *perf_evlist__new (void ); +void perf_evlist__delete (struct perf_evlist *evlist); + +void perf_evlist__add (struct perf_evlist *evlist,struct perf_evsel *entry); +int perf_evlist__add_default (struct perf_evlist *evlist); + +#endif /* __PERF_EVLIST_H */
tools/perf/util/header.c +10 -7
@@ -8,6 +8,7 @@#include <linux/list.h> #include <linux/kernel.h> +#include "evlist.h" #include "util.h" #include "header.h" #include "../perf.h"
@@ -428,7 +429,8 @@ static bool perf_session__read_build_ids(struct perf_session *self, bool with_hireturn ret; } -static int perf_header__adds_write (struct perf_header *self,int fd) +static int perf_header__adds_write (struct perf_header *self, +struct perf_evlist *evlist,int fd) {int nr_sections;struct perf_session *session;
@@ -463,7 +465,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, &evsel_list); +read_tracing_data (fd, &evlist->entries); trace_sec->size =lseek (fd,0 ,SEEK_CUR ) - trace_sec->offset; }
@@ -513,7 +515,8 @@ int perf_header__write_pipe(int fd)return 0 ; } -int perf_header__write (struct perf_header *self,int fd,bool at_exit) +int perf_header__write (struct perf_header *self,struct perf_evlist *evlist, +int fd,bool at_exit) {struct perf_file_header f_header;struct perf_file_attr f_attr;
@@ -566,7 +569,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) self->data_offset =lseek (fd,0 ,SEEK_CUR );if (at_exit) { - err =perf_header__adds_write (self, fd); + err =perf_header__adds_write (self, evlist, fd);if (err <0 )return err; }
@@ -1133,7 +1136,7 @@ int event__process_event_type(event_t *self,return 0 ; } -int event__synthesize_tracing_data (int fd,struct list_head *pattrs, +int event__synthesize_tracing_data (int fd,struct perf_evlist *evlist,event__handler_t process, struct perf_session *session __unused) {
@@ -1144,7 +1147,7 @@ int event__synthesize_tracing_data(int fd, struct list_head *pattrs,memset (&ev,0 ,sizeof (ev)); ev.tracing_data.header.type =PERF_RECORD_HEADER_TRACING_DATA ; - size =read_tracing_data_size (fd, pattrs); + size =read_tracing_data_size (fd, &evlist->entries);if (size <=0 )return size; aligned_size =ALIGN (size,sizeof (u64));
@@ -1154,7 +1157,7 @@ int event__synthesize_tracing_data(int fd, struct list_head *pattrs,process (&ev,NULL , session); - err =read_tracing_data (fd, pattrs); + err =read_tracing_data (fd, &evlist->entries);write_padded (fd,NULL ,0 , padding);return aligned_size;
tools/perf/util/header.h +5 -2
@@ -65,8 +65,11 @@ struct perf_header {int perf_header__init (struct perf_header *self);void perf_header__exit (struct perf_header *self); +struct perf_evlist ; +int perf_header__read (struct perf_session *session,int fd); -int perf_header__write (struct perf_header *self,int fd,bool at_exit); +int perf_header__write (struct perf_header *self,struct perf_evlist *evlist, +int fd,bool at_exit);int perf_header__write_pipe (int fd); int perf_header__add_attr(struct perf_header *self,
@@ -113,7 +116,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 list_head *pattrs, +int event__synthesize_tracing_data (int fd,struct perf_evlist *evlist,event__handler_t process,struct perf_session *session); int event__process_tracing_data(event_t *self,
tools/perf/util/include/linux/list.h +1 -0
@@ -1,3 +1,4 @@ +#include <linux/kernel.h> #include "../../../../include/linux/list.h" #ifndef PERF_LIST_H
tools/perf/util/parse-events.c +9 -42
91 lines not on this page · raw message
tools/perf/util/parse-events.h +0 -7
@@ -9,11 +9,6 @@struct list_head ;struct perf_evsel ; -extern struct list_head evsel_list; - -int perf_evsel_list__create_default (void ); -void perf_evsel_list__delete (void ); -struct option ;struct tracepoint_path {
@@ -25,8 +20,6 @@ struct tracepoint_path {extern struct tracepoint_path *tracepoint_id_to_path (u64 config);extern bool have_tracepoints (struct list_head *evlist); -extern int nr_counters; -const char *event_name (struct perf_evsel *event);extern const char *__event_name (int type,u64 config);