perf evlist: Store pointer to the cpu and thread maps
Commit-ID: 7e2ed097538c57ff5268e9a6bced7c0b885809c8 Gitweb: http://git.kernel.org/tip/7e2ed097538c57ff5268e9a6bced7c0b885809c8 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Sun, 30 Jan 2011 11:59:43 -0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 31 Jan 2011 12:40:52 -0200
perf evlist: Store pointer to the cpu and thread maps
So that we don't have to pass it around to the several methods that needs it, simplifying usage.
There is one case where we don't have the thread/cpu map in advance, which is in the parsing routines used by top, stat, record, that we have to wait till all options are parsed to know if a cpu or thread list was passed to then create those maps.
For that case consolidate the cpu and thread map creation via perf_evlist__create_maps() out of the code in top and record, while also providing a perf_evlist__set_maps() for cases where multiple evlists share maps or for when maps that represent CPU sockets, for instance, get crafted out of topology information or subsets of threads in a particular application are to be monitored, providing more granularity in specifying which cpus and threads to monitor.
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/builtin-record.c | 44 ++++++++++------------------ tools/perf/builtin-stat.c | 45 ++++++++++++++--------------- tools/perf/builtin-test.c | 6 ++-- tools/perf/builtin-top.c | 47 ++++++++++++------------------ tools/perf/python/twatch.py | 4 +- tools/perf/util/evlist.c | 67 ++++++++++++++++++++++++++++++++----------- tools/perf/util/evlist.h | 29 ++++++++++++++---- tools/perf/util/python.c | 25 +++++++++------- 8 files changed, 148 insertions(+), 119 deletions(-)
tools/perf/builtin-record.c +16 -28
@@ -42,7 +42,6 @@ static u64 user_interval = ULLONG_MAX;static u64 default_interval =0 ;static u64 sample_type; -static struct cpu_map *cpus;static unsigned int page_size;static unsigned int mmap_pages =128 ;static unsigned int user_freq =UINT_MAX ;
@@ -58,7 +57,6 @@ static bool sample_id_all_avail = true;static bool system_wide = false;static pid_t target_pid =-1 ;static pid_t target_tid =-1 ; -static struct thread_map *threads;static pid_t child_pid =-1 ;static bool no_inherit = false;static enum write_mode_t write_mode =WRITE_FORCE ;
@@ -189,7 +187,7 @@ static void create_counter(struct perf_evsel *evsel, int cpu)int thread_index;int ret; -for (thread_index =0 ; thread_index < threads->nr; thread_index++) { +for (thread_index =0 ; thread_index < evsel_list->threads->nr; thread_index++) { h_attr =get_header_attr (attr, evsel->idx);if (h_attr ==NULL )die ("nomem\n" );
@@ -317,7 +315,8 @@ static void open_counters(struct perf_evlist *evlist) retry_sample_id: attr->sample_id_all = sample_id_all_avail ?1 :0 ; try_again: -if (perf_evsel__open (pos, cpus, threads, group, !no_inherit) <0 ) { +if (perf_evsel__open (pos, evlist->cpus, evlist->threads, group, + !no_inherit) <0 ) {int err = errno;if (err ==EPERM || err ==EACCES )
@@ -368,10 +367,10 @@ try_again: } } -if (perf_evlist__mmap (evlist, cpus, threads, mmap_pages, false) <0 ) +if (perf_evlist__mmap (evlist, mmap_pages, false) <0 )die ("failed to mmap with %d (%s)\n" , errno,strerror (errno)); -for (cpu =0 ; cpu < cpus->nr; ++cpu) { +for (cpu =0 ; cpu < evsel_list->cpus->nr; ++cpu) {list_for_each_entry (pos, &evlist->entries, node)create_counter (pos, cpu); }
@@ -450,7 +449,7 @@ static void mmap_read_all(void) {int i; -for (i =0 ; i < cpus->nr; i++) { +for (i =0 ; i < evsel_list->cpus->nr; i++) {if (evsel_list->mmap[i].base)mmap_read (&evsel_list->mmap[i]); }
@@ -584,7 +583,7 @@ static int __cmd_record(int argc, const char **argv) }if (!system_wide && target_tid ==-1 && target_pid ==-1 ) - threads->map[0 ] = child_pid; + evsel_list->threads->map[0 ] = child_pid;close (child_ready_pipe[1 ]);close (go_pipe[0 ]);
@@ -718,12 +717,12 @@ static int __cmd_record(int argc, const char **argv) }if (done) { -for (i =0 ; i < cpus->nr; i++) { +for (i =0 ; i < evsel_list->cpus->nr; i++) {struct perf_evsel *pos;list_for_each_entry (pos, &evsel_list->entries, node) {for (thread =0 ; - thread < threads->nr; + thread < evsel_list->threads->nr; thread++)ioctl (FD (pos, i, thread),PERF_EVENT_IOC_DISABLE );
@@ -816,7 +815,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)int err = -ENOMEM ;struct perf_evsel *pos; - evsel_list =perf_evlist__new (); + evsel_list =perf_evlist__new (NULL ,NULL );if (evsel_list ==NULL )return -ENOMEM ;
@@ -850,28 +849,19 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)if (target_pid !=-1 ) target_tid = target_pid; - threads =thread_map__new (target_pid, target_tid); -if (threads ==NULL ) { -pr_err ("Problems finding threads of monitor\n" ); -usage_with_options (record_usage, record_options); - } - -if (target_tid !=-1 ) - cpus =cpu_map__dummy_new (); -else - cpus =cpu_map__new (cpu_list); - -if (cpus ==NULL ) +if (perf_evlist__create_maps (evsel_list, target_pid, + target_tid, cpu_list) <0 )usage_with_options (record_usage, record_options);list_for_each_entry (pos, &evsel_list->entries, node) { -if (perf_evsel__alloc_fd (pos, cpus->nr, threads->nr) <0 ) +if (perf_evsel__alloc_fd (pos, evsel_list->cpus->nr, + evsel_list->threads->nr) <0 ) goto out_free_fd;if (perf_header__push_event (pos->attr.config,event_name (pos))) goto out_free_fd; } -if (perf_evlist__alloc_pollfd (evsel_list, cpus->nr, threads->nr) <0 ) +if (perf_evlist__alloc_pollfd (evsel_list) <0 ) goto out_free_fd;if (user_interval !=ULLONG_MAX )
@@ -893,10 +883,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) } err =__cmd_record (argc, argv); - out_free_fd: -thread_map__delete (threads); - threads =NULL ; +perf_evlist__delete_maps (evsel_list); out_symbol_exit:symbol__exit ();return err;
tools/perf/builtin-stat.c +22 -23
151 lines not on this page · raw message
tools/perf/builtin-test.c +3 -3
@@ -509,7 +509,7 @@ static int test__basic_mmap(void) goto out_free_cpus; } - evlist =perf_evlist__new (); + evlist =perf_evlist__new (cpus, threads);if (evlist ==NULL ) {pr_debug ("perf_evlist__new\n" ); goto out_free_cpus;
@@ -537,7 +537,7 @@ static int test__basic_mmap(void) } } -if (perf_evlist__mmap (evlist, cpus, threads,128 , true) <0 ) { +if (perf_evlist__mmap (evlist,128 , true) <0 ) {pr_debug ("failed to mmap events: %d (%s)\n" , errno,strerror (errno)); goto out_close_fd;
@@ -579,7 +579,7 @@ static int test__basic_mmap(void) err =0 ; out_munmap: -perf_evlist__munmap (evlist,1 ); +perf_evlist__munmap (evlist); out_close_fd:for (i =0 ; i < nsyscalls; ++i)perf_evsel__close_fd (evsels[i],1 , threads->nr);
tools/perf/builtin-top.c +19 -28
113 lines not on this page · raw message
tools/perf/python/twatch.py +2 -2
@@ -23,9 +23,9 @@ def main(): sample_id_all = 1, sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_TID) evsel.open(cpus = cpus, threads = threads); - evlist = perf.evlist() + evlist = perf.evlist(cpus, threads) evlist.add(evsel) - evlist.mmap(cpus = cpus, threads = threads) + evlist.mmap() while True: evlist.poll(timeout = -1) for cpu in cpus:
tools/perf/util/evlist.c +50 -17
132 lines not on this page · raw message
tools/perf/util/evlist.h +22 -7
@@ -22,28 +22,43 @@ struct perf_evlist {union perf_event event_copy;struct perf_mmap *mmap;struct pollfd *pollfd; +struct thread_map *threads; +struct cpu_map *cpus; };struct perf_evsel ; -struct perf_evlist *perf_evlist__new (void ); -void perf_evlist__init (struct perf_evlist *evlist); +struct perf_evlist *perf_evlist__new (struct cpu_map *cpus, +struct thread_map *threads); +void perf_evlist__init (struct perf_evlist *evlist,struct cpu_map *cpus, +struct thread_map *threads);void perf_evlist__exit (struct perf_evlist *evlist);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); -int perf_evlist__alloc_pollfd (struct perf_evlist *evlist,int ncpus,int nthreads); +int perf_evlist__alloc_pollfd (struct perf_evlist *evlist);void perf_evlist__add_pollfd (struct perf_evlist *evlist,int fd);struct perf_evsel *perf_evlist__id2evsel (struct perf_evlist *evlist,u64 id);union perf_event *perf_evlist__read_on_cpu (struct perf_evlist *self,int cpu); -int perf_evlist__alloc_mmap (struct perf_evlist *evlist,int ncpus); -int perf_evlist__mmap (struct perf_evlist *evlist,struct cpu_map *cpus, -struct thread_map *threads,int pages,bool overwrite); -void perf_evlist__munmap (struct perf_evlist *evlist,int ncpus); +int perf_evlist__alloc_mmap (struct perf_evlist *evlist); +int perf_evlist__mmap (struct perf_evlist *evlist,int pages,bool overwrite); +void perf_evlist__munmap (struct perf_evlist *evlist); + +static inline void perf_evlist__set_maps (struct perf_evlist *evlist, +struct cpu_map *cpus, +struct thread_map *threads) +{ + evlist->cpus = cpus; + evlist->threads = threads; +} + +int perf_evlist__create_maps (struct perf_evlist *evlist,pid_t target_pid, +pid_t target_tid,const char *cpu_list); +void perf_evlist__delete_maps (struct perf_evlist *evlist);#endif /* __PERF_EVLIST_H */
tools/perf/util/python.c +14 -11
@@ -553,7 +553,16 @@ struct pyrf_evlist {static int pyrf_evlist__init (struct pyrf_evlist *pevlist,PyObject *args,PyObject *kwargs) { -perf_evlist__init (&pevlist->evlist); +PyObject *pcpus =NULL , *pthreads =NULL ; +struct cpu_map *cpus; +struct thread_map *threads; + +if (!PyArg_ParseTuple (args,"OO" , &pcpus, &pthreads)) +return -1 ; + + threads = ((struct pyrf_thread_map *)pthreads)->threads; + cpus = ((struct pyrf_cpu_map *)pcpus)->cpus; +perf_evlist__init (&pevlist->evlist, cpus, threads);return 0 ; }
@@ -567,21 +576,15 @@ static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) {struct perf_evlist *evlist = &pevlist->evlist; -PyObject *pcpus =NULL , *pthreads =NULL ; -struct cpu_map *cpus =NULL ; -struct thread_map *threads =NULL ; -static char *kwlist[] = {"cpus" ,"threads" ,"pages" ,"overwrite" , +static char *kwlist[] = {"pages" ,"overwrite" ,NULL ,NULL };int pages =128 , overwrite = false; -if (!PyArg_ParseTupleAndKeywords (args, kwargs,"OO|ii" , kwlist, - &pcpus, &pthreads, &pages, &overwrite)) +if (!PyArg_ParseTupleAndKeywords (args, kwargs,"|ii" , kwlist, + &pages, &overwrite))return NULL ; - threads = ((struct pyrf_thread_map *)pthreads)->threads; - cpus = ((struct pyrf_cpu_map *)pcpus)->cpus; - -if (perf_evlist__mmap (evlist, cpus, threads, pages, overwrite) <0 ) { +if (perf_evlist__mmap (evlist, pages, overwrite) <0 ) {PyErr_SetFromErrno (PyExc_OSError);return NULL ; }