perf evlist: Remove cpus and threads arguments from perf_evlist__new()
Namhyung Kim
maintainerPATCH 1/7 perf evlist: Remove cpus and threads arguments from perf_evlist__new()
From: Namhyung Kim <[email protected]>
It's almost always used with NULL for both arguments. Get rid of the arguments from the signature and use perf_evlist__set_maps() if needed.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 ++-- tools/perf/tests/hists_link.c | 2 +- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/open-syscall-tp-fields.c | 2 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 5 ++--- tools/perf/util/evlist.h | 3 +-- tools/perf/util/header.c | 4 ++-- 13 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -964,7 +964,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)struct perf_record *rec = &record;char errbuf[BUFSIZ ]; - evsel_list =perf_evlist__new (NULL ,NULL ); + evsel_list =perf_evlist__new ();if (evsel_list ==NULL )return -ENOMEM ;
tools/perf/builtin-stat.c +1 -1
@@ -1336,7 +1336,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)setlocale (LC_ALL ,"" ); - evsel_list =perf_evlist__new (NULL ,NULL ); + evsel_list =perf_evlist__new ();if (evsel_list ==NULL )return -ENOMEM ;
tools/perf/builtin-top.c +1 -1
@@ -1116,7 +1116,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) NULL }; - top.evlist =perf_evlist__new (NULL ,NULL ); + top.evlist =perf_evlist__new ();if (top.evlist ==NULL )return -ENOMEM ;
tools/perf/builtin-trace.c +1 -1
@@ -419,7 +419,7 @@ out_dump:static int trace__run (struct trace *trace,int argc,const char **argv) { -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;int err =-1 , i;unsigned long before;
tools/perf/tests/evsel-roundtrip-name.c +2 -2
@@ -8,7 +8,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)char name[128 ];int type, op, err =0 , ret =0 , i, idx;struct perf_evsel *evsel; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
@@ -64,7 +64,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names) {int i, err;struct perf_evsel *evsel; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/hists_link.c +1 -1
@@ -436,7 +436,7 @@ int test__hists_link(void)struct machines machines;struct machine *machine =NULL ;struct perf_evsel *evsel, *first; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/mmap-basic.c +3 -1
@@ -53,12 +53,14 @@ int test__basic_mmap(void) goto out_free_cpus; } - evlist =perf_evlist__new (cpus, threads); + evlist =perf_evlist__new ();if (evlist ==NULL ) {pr_debug ("perf_evlist__new\n" ); goto out_free_cpus; } +perf_evlist__set_maps (evlist, cpus, threads); +for (i =0 ; i < nsyscalls; ++i) {char name[64 ];
tools/perf/tests/open-syscall-tp-fields.c +1 -1
@@ -18,7 +18,7 @@ int test__syscall_open_tp_fields(void) };const char *filename ="/etc/passwd" ;int flags =O_RDONLY |O_DIRECTORY ; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;int err =-1 , i, nr_events =0 , nr_polls =0 ;
tools/perf/tests/parse-events.c +1 -1
@@ -1218,7 +1218,7 @@ static int test_event(struct evlist_test *e)struct perf_evlist *evlist;int ret; - evlist =perf_evlist__new (NULL ,NULL ); + evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/perf-record.c +1 -1
@@ -45,7 +45,7 @@ int test__PERF_RECORD(void) };cpu_set_t cpu_mask;size_t cpu_mask_size =sizeof (cpu_mask); -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;struct perf_sample sample;const char *cmd ="sleep" ;
tools/perf/util/evlist.c +2 -3
@@ -38,13 +38,12 @@ void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, evlist->workload.pid =-1 ; } -struct perf_evlist *perf_evlist__new (struct cpu_map *cpus, -struct thread_map *threads) +struct perf_evlist *perf_evlist__new (void ) {struct perf_evlist *evlist =zalloc (sizeof (*evlist));if (evlist !=NULL ) -perf_evlist__init (evlist, cpus, threads); +perf_evlist__init (evlist,NULL ,NULL );return evlist; }
tools/perf/util/evlist.h +1 -2
@@ -49,8 +49,7 @@ struct perf_evsel_str_handler {void *handler; }; -struct perf_evlist *perf_evlist__new (struct cpu_map *cpus, -struct thread_map *threads); +struct perf_evlist *perf_evlist__new (void );void perf_evlist__init (struct perf_evlist *evlist,struct cpu_map *cpus,struct thread_map *threads);void perf_evlist__exit (struct perf_evlist *evlist);
tools/perf/util/header.c +2 -2
@@ -2789,7 +2789,7 @@ int perf_session__read_header(struct perf_session *session, int fd)u64 f_id;int nr_attrs, nr_ids, i, j; - session->evlist =perf_evlist__new (NULL ,NULL ); + session->evlist =perf_evlist__new ();if (session->evlist ==NULL )return -ENOMEM ;
@@ -2940,7 +2940,7 @@ int perf_event__process_attr(union perf_event *event,struct perf_evlist *evlist = *pevlist;if (evlist ==NULL ) { - *pevlist = evlist =perf_evlist__new (NULL ,NULL ); + *pevlist = evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ; }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 2/7 perf evlist: Use cpu_map__nr() helper
From: Namhyung Kim <[email protected]>
Use the cpu_map__nr() helper to protect a possible NULL cpu map dereference.
--- tools/perf/util/evlist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/evlist.c +4 -4
@@ -228,7 +228,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)int cpu, thread;struct perf_evsel *pos; -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ;
@@ -443,7 +443,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mstruct perf_evsel *evsel;int cpu, thread; -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {int output =-1 ;for (thread =0 ; thread < evlist->threads->nr; thread++) {
@@ -470,7 +470,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mreturn 0 ; out_unmap: -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {if (evlist->mmap[cpu].base !=NULL ) {munmap (evlist->mmap[cpu].base, evlist->mmap_len); evlist->mmap[cpu].base =NULL ;
@@ -725,7 +725,7 @@ int perf_evlist__open(struct perf_evlist *evlist)return 0 ; out_err: - ncpus = evlist->cpus ? evlist->cpus->nr :1 ; + ncpus =cpu_map__nr (evlist->cpus); nthreads = evlist->threads ? evlist->threads->nr :1 ;list_for_each_entry_reverse (evsel, &evlist->entries, node)
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf evlist: Use cpu_map__nr() helper
perf evlist: Use cpu_map__nr() helper
Commit-ID: 85397956de304106e2fdace2db8f69ab4e966bc5 Gitweb: http://git.kernel.org/tip/85397956de304106e2fdace2db8f69ab4e966bc5 Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:13 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:02 -0300
perf evlist: Use cpu_map__nr() helper
Use the cpu_map__nr() helper to protect a possible NULL cpu map dereference.
--- tools/perf/util/evlist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/evlist.c +4 -4
@@ -228,7 +228,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)int cpu, thread;struct perf_evsel *pos; -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ;
@@ -443,7 +443,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mstruct perf_evsel *evsel;int cpu, thread; -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {int output =-1 ;for (thread =0 ; thread < evlist->threads->nr; thread++) {
@@ -470,7 +470,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mreturn 0 ; out_unmap: -for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { +for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) {if (evlist->mmap[cpu].base !=NULL ) {munmap (evlist->mmap[cpu].base, evlist->mmap_len); evlist->mmap[cpu].base =NULL ;
@@ -725,7 +725,7 @@ int perf_evlist__open(struct perf_evlist *evlist)return 0 ; out_err: - ncpus = evlist->cpus ? evlist->cpus->nr :1 ; + ncpus =cpu_map__nr (evlist->cpus); nthreads = evlist->threads ? evlist->threads->nr :1 ;list_for_each_entry_reverse (evsel, &evlist->entries, node)
Namhyung Kim
maintainerPATCH 3/7 perf evlist: Add thread_map__nr() helper
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
Introduce and use the thread_map__nr() function to protect a possible NULL pointer dereference and cleanup the code a bit.
--- tools/perf/builtin-stat.c | 4 ++-- tools/perf/util/evlist.c | 37 +++++++++++++++++++++++-------------- tools/perf/util/thread_map.h | 5 +++++ 3 files changed, 30 insertions(+), 16 deletions(-)
tools/perf/builtin-stat.c +2 -2
@@ -249,7 +249,7 @@ static int read_counter_aggr(struct perf_evsel *counter)int i;if (__perf_evsel__read (counter,perf_evsel__nr_cpus (counter), - evsel_list->threads->nr, scale) <0 ) +thread_map__nr (evsel_list->threads), scale) <0 )return -1 ;for (i =0 ; i <3 ; i++)
@@ -488,7 +488,7 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)list_for_each_entry (counter, &evsel_list->entries, node) {read_counter_aggr (counter);perf_evsel__close_fd (counter,perf_evsel__nr_cpus (counter), - evsel_list->threads->nr); +thread_map__nr (evsel_list->threads)); } }
tools/perf/util/evlist.c +23 -14
@@ -227,12 +227,14 @@ void perf_evlist__disable(struct perf_evlist *evlist) {int cpu, thread;struct perf_evsel *pos; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ; -for (thread =0 ; thread < evlist->threads->nr; thread++) +for (thread =0 ; thread < nr_threads; thread++)ioctl (FD (pos, cpu, thread),PERF_EVENT_IOC_DISABLE ,0 ); }
@@ -243,12 +245,14 @@ void perf_evlist__enable(struct perf_evlist *evlist) {int cpu, thread;struct perf_evsel *pos; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ; -for (thread =0 ; thread < evlist->threads->nr; thread++) +for (thread =0 ; thread < nr_threads; thread++)ioctl (FD (pos, cpu, thread),PERF_EVENT_IOC_ENABLE ,0 ); }
@@ -257,7 +261,9 @@ void perf_evlist__enable(struct perf_evlist *evlist)static int perf_evlist__alloc_pollfd (struct perf_evlist *evlist) { -int nfds =cpu_map__nr (evlist->cpus) * evlist->threads->nr * evlist->nr_entries; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); +int nfds = nr_cpus * nr_threads * evlist->nr_entries; evlist->pollfd =malloc (sizeof (struct pollfd ) * nfds);return evlist->pollfd !=NULL ?0 : -ENOMEM ; }
@@ -417,7 +423,7 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) { evlist->nr_mmaps =cpu_map__nr (evlist->cpus);if (cpu_map__all (evlist->cpus)) - evlist->nr_mmaps = evlist->threads->nr; + evlist->nr_mmaps =thread_map__nr (evlist->threads); evlist->mmap =zalloc (evlist->nr_mmaps *sizeof (struct perf_mmap ));return evlist->mmap !=NULL ?0 : -ENOMEM ; }
@@ -442,11 +448,13 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m {struct perf_evsel *evsel;int cpu, thread; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {int output =-1 ; -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {list_for_each_entry (evsel, &evlist->entries, node) {int fd =FD (evsel, cpu, thread);
@@ -470,7 +478,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mreturn 0 ; out_unmap: -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {if (evlist->mmap[cpu].base !=NULL ) {munmap (evlist->mmap[cpu].base, evlist->mmap_len); evlist->mmap[cpu].base =NULL ;
@@ -483,8 +491,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in {struct perf_evsel *evsel;int thread; +int nr_threads =thread_map__nr (evlist->threads); -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {int output =-1 ;list_for_each_entry (evsel, &evlist->entries, node) {
@@ -509,7 +518,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, inreturn 0 ; out_unmap: -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {if (evlist->mmap[thread].base !=NULL ) {munmap (evlist->mmap[thread].base, evlist->mmap_len); evlist->mmap[thread].base =NULL ;
@@ -610,7 +619,7 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist)struct perf_evsel *evsel;int err =0 ;const int ncpus =cpu_map__nr (evlist->cpus), - nthreads = evlist->threads->nr; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry (evsel, &evlist->entries, node) {if (evsel->filter ==NULL )
@@ -629,7 +638,7 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)struct perf_evsel *evsel;int err =0 ;const int ncpus =cpu_map__nr (evlist->cpus), - nthreads = evlist->threads->nr; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry (evsel, &evlist->entries, node) { err =perf_evsel__set_filter (evsel, ncpus, nthreads, filter);
@@ -726,7 +735,7 @@ int perf_evlist__open(struct perf_evlist *evlist)return 0 ; out_err: ncpus =cpu_map__nr (evlist->cpus); - nthreads = evlist->threads ? evlist->threads->nr :1 ; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry_reverse (evsel, &evlist->entries, node)perf_evsel__close (evsel, ncpus, nthreads);
tools/perf/util/thread_map.h +5 -0
@@ -21,4 +21,9 @@ void thread_map__delete(struct thread_map *threads);size_t thread_map__fprintf (struct thread_map *threads,FILE *fp); +static inline int thread_map__nr (struct thread_map *threads) +{ +return threads ? threads->nr :1 ; +} +#endif /* __PERF_THREAD_MAP_H */
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf evlist: Add thread_map__nr() helper
perf evlist: Add thread_map__nr() helper
Commit-ID: b3a319d528fd57ef600731ee1b84d00b7204881d Gitweb: http://git.kernel.org/tip/b3a319d528fd57ef600731ee1b84d00b7204881d Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:14 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:02 -0300
perf evlist: Add thread_map__nr() helper
Introduce and use the thread_map__nr() function to protect a possible NULL pointer dereference and cleanup the code a bit.
--- tools/perf/builtin-stat.c | 4 ++-- tools/perf/util/evlist.c | 37 +++++++++++++++++++++++-------------- tools/perf/util/thread_map.h | 5 +++++ 3 files changed, 30 insertions(+), 16 deletions(-)
tools/perf/builtin-stat.c +2 -2
@@ -249,7 +249,7 @@ static int read_counter_aggr(struct perf_evsel *counter)int i;if (__perf_evsel__read (counter,perf_evsel__nr_cpus (counter), - evsel_list->threads->nr, scale) <0 ) +thread_map__nr (evsel_list->threads), scale) <0 )return -1 ;for (i =0 ; i <3 ; i++)
@@ -488,7 +488,7 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)list_for_each_entry (counter, &evsel_list->entries, node) {read_counter_aggr (counter);perf_evsel__close_fd (counter,perf_evsel__nr_cpus (counter), - evsel_list->threads->nr); +thread_map__nr (evsel_list->threads)); } }
tools/perf/util/evlist.c +23 -14
@@ -227,12 +227,14 @@ void perf_evlist__disable(struct perf_evlist *evlist) {int cpu, thread;struct perf_evsel *pos; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ; -for (thread =0 ; thread < evlist->threads->nr; thread++) +for (thread =0 ; thread < nr_threads; thread++)ioctl (FD (pos, cpu, thread),PERF_EVENT_IOC_DISABLE ,0 ); }
@@ -243,12 +245,14 @@ void perf_evlist__enable(struct perf_evlist *evlist) {int cpu, thread;struct perf_evsel *pos; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {list_for_each_entry (pos, &evlist->entries, node) {if (!perf_evsel__is_group_leader (pos))continue ; -for (thread =0 ; thread < evlist->threads->nr; thread++) +for (thread =0 ; thread < nr_threads; thread++)ioctl (FD (pos, cpu, thread),PERF_EVENT_IOC_ENABLE ,0 ); }
@@ -257,7 +261,9 @@ void perf_evlist__enable(struct perf_evlist *evlist)static int perf_evlist__alloc_pollfd (struct perf_evlist *evlist) { -int nfds =cpu_map__nr (evlist->cpus) * evlist->threads->nr * evlist->nr_entries; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); +int nfds = nr_cpus * nr_threads * evlist->nr_entries; evlist->pollfd =malloc (sizeof (struct pollfd ) * nfds);return evlist->pollfd !=NULL ?0 : -ENOMEM ; }
@@ -417,7 +423,7 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) { evlist->nr_mmaps =cpu_map__nr (evlist->cpus);if (cpu_map__all (evlist->cpus)) - evlist->nr_mmaps = evlist->threads->nr; + evlist->nr_mmaps =thread_map__nr (evlist->threads); evlist->mmap =zalloc (evlist->nr_mmaps *sizeof (struct perf_mmap ));return evlist->mmap !=NULL ?0 : -ENOMEM ; }
@@ -442,11 +448,13 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m {struct perf_evsel *evsel;int cpu, thread; +int nr_cpus =cpu_map__nr (evlist->cpus); +int nr_threads =thread_map__nr (evlist->threads); -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {int output =-1 ; -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {list_for_each_entry (evsel, &evlist->entries, node) {int fd =FD (evsel, cpu, thread);
@@ -470,7 +478,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mreturn 0 ; out_unmap: -for (cpu =0 ; cpu <cpu_map__nr (evlist->cpus); cpu++) { +for (cpu =0 ; cpu < nr_cpus; cpu++) {if (evlist->mmap[cpu].base !=NULL ) {munmap (evlist->mmap[cpu].base, evlist->mmap_len); evlist->mmap[cpu].base =NULL ;
@@ -483,8 +491,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in {struct perf_evsel *evsel;int thread; +int nr_threads =thread_map__nr (evlist->threads); -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {int output =-1 ;list_for_each_entry (evsel, &evlist->entries, node) {
@@ -509,7 +518,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, inreturn 0 ; out_unmap: -for (thread =0 ; thread < evlist->threads->nr; thread++) { +for (thread =0 ; thread < nr_threads; thread++) {if (evlist->mmap[thread].base !=NULL ) {munmap (evlist->mmap[thread].base, evlist->mmap_len); evlist->mmap[thread].base =NULL ;
@@ -610,7 +619,7 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist)struct perf_evsel *evsel;int err =0 ;const int ncpus =cpu_map__nr (evlist->cpus), - nthreads = evlist->threads->nr; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry (evsel, &evlist->entries, node) {if (evsel->filter ==NULL )
@@ -629,7 +638,7 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)struct perf_evsel *evsel;int err =0 ;const int ncpus =cpu_map__nr (evlist->cpus), - nthreads = evlist->threads->nr; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry (evsel, &evlist->entries, node) { err =perf_evsel__set_filter (evsel, ncpus, nthreads, filter);
@@ -726,7 +735,7 @@ int perf_evlist__open(struct perf_evlist *evlist)return 0 ; out_err: ncpus =cpu_map__nr (evlist->cpus); - nthreads = evlist->threads ? evlist->threads->nr :1 ; + nthreads =thread_map__nr (evlist->threads);list_for_each_entry_reverse (evsel, &evlist->entries, node)perf_evsel__close (evsel, ncpus, nthreads);
tools/perf/util/thread_map.h +5 -0
@@ -21,4 +21,9 @@ void thread_map__delete(struct thread_map *threads);size_t thread_map__fprintf (struct thread_map *threads,FILE *fp); +static inline int thread_map__nr (struct thread_map *threads) +{ +return threads ? threads->nr :1 ; +} +#endif /* __PERF_THREAD_MAP_H */
Namhyung Kim
maintainerPATCH 4/7 perf evlist: Pass struct perf_target to perf_evlist__prepare_workload()
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
It's a preparation step of removing @opts arg from the function so that it can be used more widely.
--- tools/perf/builtin-record.c | 3 ++- tools/perf/builtin-trace.c | 3 ++- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 3 ++- tools/perf/util/evlist.h | 1 + 5 files changed, 8 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +2 -1
@@ -474,7 +474,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) }if (forks) { - err =perf_evlist__prepare_workload (evsel_list, opts, argv); + err =perf_evlist__prepare_workload (evsel_list, &opts->target, + opts, argv);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +2 -1
@@ -461,7 +461,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)signal (SIGINT , sig_handler);if (forks) { - err =perf_evlist__prepare_workload (evlist, &trace->opts, argv); + err =perf_evlist__prepare_workload (evlist, &trace->opts.target, + &trace->opts, argv);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +1 -1
@@ -93,7 +93,7 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts, argv); + err =perf_evlist__prepare_workload (evlist, &opts.target, &opts, argv);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +2 -1
@@ -745,6 +745,7 @@ out_err: }int perf_evlist__prepare_workload (struct perf_evlist *evlist, +struct perf_target *target,struct perf_record_opts *opts,const char *argv[]) {
@@ -800,7 +801,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,exit (-1 ); } -if (perf_target__none (&opts->target)) +if (perf_target__none (target)) evlist->threads->map[0 ] = evlist->workload.pid;close (child_ready_pipe[1 ]);
tools/perf/util/evlist.h +1 -0
@@ -86,6 +86,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct perf_record_opts *opts);int perf_evlist__prepare_workload (struct perf_evlist *evlist, +struct perf_target *target,struct perf_record_opts *opts,const char *argv[]);int perf_evlist__start_workload (struct perf_evlist *evlist);
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf evlist: Pass struct perf_target to perf_evlist__prepare_workload()
perf evlist: Pass struct perf_target to perf_evlist__prepare_workload()
Commit-ID: 6ef73ec449af998ca34673636d00decc8e808544 Gitweb: http://git.kernel.org/tip/6ef73ec449af998ca34673636d00decc8e808544 Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:15 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:02 -0300
perf evlist: Pass struct perf_target to perf_evlist__prepare_workload()
It's a preparation step of removing @opts arg from the function so that it can be used more widely.
--- tools/perf/builtin-record.c | 3 ++- tools/perf/builtin-trace.c | 3 ++- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 3 ++- tools/perf/util/evlist.h | 1 + 5 files changed, 8 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +2 -1
@@ -474,7 +474,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv) }if (forks) { - err =perf_evlist__prepare_workload (evsel_list, opts, argv); + err =perf_evlist__prepare_workload (evsel_list, &opts->target, + opts, argv);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +2 -1
@@ -461,7 +461,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)signal (SIGINT , sig_handler);if (forks) { - err =perf_evlist__prepare_workload (evlist, &trace->opts, argv); + err =perf_evlist__prepare_workload (evlist, &trace->opts.target, + &trace->opts, argv);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +1 -1
@@ -93,7 +93,7 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts, argv); + err =perf_evlist__prepare_workload (evlist, &opts.target, &opts, argv);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +2 -1
@@ -745,6 +745,7 @@ out_err: }int perf_evlist__prepare_workload (struct perf_evlist *evlist, +struct perf_target *target,struct perf_record_opts *opts,const char *argv[]) {
@@ -800,7 +801,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,exit (-1 ); } -if (perf_target__none (&opts->target)) +if (perf_target__none (target)) evlist->threads->map[0 ] = evlist->workload.pid;close (child_ready_pipe[1 ]);
tools/perf/util/evlist.h +1 -0
@@ -86,6 +86,7 @@ void perf_evlist__config(struct perf_evlist *evlist, struct perf_record_opts *opts);int perf_evlist__prepare_workload (struct perf_evlist *evlist, +struct perf_target *target,struct perf_record_opts *opts,const char *argv[]);int perf_evlist__start_workload (struct perf_evlist *evlist);
Namhyung Kim
maintainerPATCH 5/7 perf evlist: Do not pass struct record_opts to perf_evlist__prepare_workload()
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
Since it's only used for checking ->pipe_output, we can pass the result directly.
Now the perf_evlist__prepare_workload() don't have a dependency of struct perf_record_opts, it can be called from other places like perf stat.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 5 ++--- tools/perf/util/evlist.h | 3 +-- 5 files changed, 6 insertions(+), 8 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -475,7 +475,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evsel_list, &opts->target, - opts, argv); + argv, opts->pipe_output);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +1 -1
@@ -462,7 +462,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evlist, &trace->opts.target, - &trace->opts, argv); + argv, false);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +1 -1
@@ -93,7 +93,7 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts.target, &opts, argv); + err =perf_evlist__prepare_workload (evlist, &opts.target, argv, false);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +2 -3
@@ -746,8 +746,7 @@ out_err:int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -struct perf_record_opts *opts, -const char *argv[]) +const char *argv[],bool pipe_output) {int child_ready_pipe[2 ], go_pipe[2 ];char bf;
@@ -769,7 +768,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, }if (!evlist->workload.pid) { -if (opts->pipe_output) +if (pipe_output)dup2 (2 ,1 );close (child_ready_pipe[0 ]);
tools/perf/util/evlist.h +1 -2
@@ -87,8 +87,7 @@ void perf_evlist__config(struct perf_evlist *evlist,int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -struct perf_record_opts *opts, -const char *argv[]); +const char *argv[],bool pipe_output);int perf_evlist__start_workload (struct perf_evlist *evlist); int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf evlist: Do not pass struct record_opts to perf_evlist__prepare_workload()
perf evlist: Do not pass struct record_opts to perf_evlist__prepare_workload()
Commit-ID: 119fa3c922ff53a334507e198b2e3c66e99f54dc Gitweb: http://git.kernel.org/tip/119fa3c922ff53a334507e198b2e3c66e99f54dc Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:16 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:02 -0300
perf evlist: Do not pass struct record_opts to perf_evlist__prepare_workload()
Since it's only used for checking ->pipe_output, we can pass the result directly.
Now the perf_evlist__prepare_workload() don't have a dependency of struct perf_record_opts, it can be called from other places like perf stat.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 5 ++--- tools/perf/util/evlist.h | 3 +-- 5 files changed, 6 insertions(+), 8 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -475,7 +475,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evsel_list, &opts->target, - opts, argv); + argv, opts->pipe_output);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +1 -1
@@ -462,7 +462,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evlist, &trace->opts.target, - &trace->opts, argv); + argv, false);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +1 -1
@@ -93,7 +93,7 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts.target, &opts, argv); + err =perf_evlist__prepare_workload (evlist, &opts.target, argv, false);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +2 -3
@@ -746,8 +746,7 @@ out_err:int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -struct perf_record_opts *opts, -const char *argv[]) +const char *argv[],bool pipe_output) {int child_ready_pipe[2 ], go_pipe[2 ];char bf;
@@ -769,7 +768,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, }if (!evlist->workload.pid) { -if (opts->pipe_output) +if (pipe_output)dup2 (2 ,1 );close (child_ready_pipe[0 ]);
tools/perf/util/evlist.h +1 -2
@@ -87,8 +87,7 @@ void perf_evlist__config(struct perf_evlist *evlist,int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -struct perf_record_opts *opts, -const char *argv[]); +const char *argv[],bool pipe_output);int perf_evlist__start_workload (struct perf_evlist *evlist); int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
Namhyung Kim
maintainerPATCH 6/7 perf evlist: Add want_signal parameter to perf_evlist__prepare_workload()
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
In case a caller doesn't want to receive SIGUSR1 when the child failed to exec().
--- tools/perf/builtin-record.c | 3 ++- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-record.c | 3 ++- tools/perf/util/evlist.c | 6 ++++-- tools/perf/util/evlist.h | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-)
tools/perf/builtin-record.c +2 -1
@@ -475,7 +475,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evsel_list, &opts->target, - argv, opts->pipe_output); + argv, opts->pipe_output, + true);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +1 -1
@@ -462,7 +462,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evlist, &trace->opts.target, - argv, false); + argv, false, false);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +2 -1
@@ -93,7 +93,8 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts.target, argv, false); + err =perf_evlist__prepare_workload (evlist, &opts.target, argv, + false, false);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +4 -2
@@ -746,7 +746,8 @@ out_err:int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -const char *argv[],bool pipe_output) +const char *argv[],bool pipe_output, +bool want_signal) {int child_ready_pipe[2 ], go_pipe[2 ];char bf;
@@ -796,7 +797,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,execvp (argv[0 ], (char **)argv);perror (argv[0 ]); -kill (getppid (),SIGUSR1 ); +if (want_signal) +kill (getppid (),SIGUSR1 );exit (-1 ); }
tools/perf/util/evlist.h +2 -1
@@ -87,7 +87,8 @@ void perf_evlist__config(struct perf_evlist *evlist,int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -const char *argv[],bool pipe_output); +const char *argv[],bool pipe_output, +bool want_signal);int perf_evlist__start_workload (struct perf_evlist *evlist); int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf evlist: Add want_signal parameter to perf_evlist__prepare_workload()
perf evlist: Add want_signal parameter to perf_evlist__prepare_workload()
Commit-ID: 55e162ea764cb5b38f27ea0b16ee7d31c1a5aedb Gitweb: http://git.kernel.org/tip/55e162ea764cb5b38f27ea0b16ee7d31c1a5aedb Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:17 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:03 -0300
perf evlist: Add want_signal parameter to perf_evlist__prepare_workload()
In case a caller doesn't want to receive SIGUSR1 when the child failed to exec().
--- tools/perf/builtin-record.c | 3 ++- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/perf-record.c | 3 ++- tools/perf/util/evlist.c | 6 ++++-- tools/perf/util/evlist.h | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-)
tools/perf/builtin-record.c +2 -1
@@ -475,7 +475,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evsel_list, &opts->target, - argv, opts->pipe_output); + argv, opts->pipe_output, + true);if (err <0 ) {pr_err ("Couldn't run the workload!\n" ); goto out_delete_session;
tools/perf/builtin-trace.c +1 -1
@@ -462,7 +462,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)if (forks) { err =perf_evlist__prepare_workload (evlist, &trace->opts.target, - argv, false); + argv, false, false);if (err <0 ) {printf ("Couldn't run the workload!\n" ); goto out_delete_evlist;
tools/perf/tests/perf-record.c +2 -1
@@ -93,7 +93,8 @@ int test__PERF_RECORD(void)* so that we have time to open the evlist (calling sys_perf_event_open * on all the fds) and then mmap them. */ - err =perf_evlist__prepare_workload (evlist, &opts.target, argv, false); + err =perf_evlist__prepare_workload (evlist, &opts.target, argv, + false, false);if (err <0 ) {pr_debug ("Couldn't run the workload!\n" ); goto out_delete_maps;
tools/perf/util/evlist.c +4 -2
@@ -746,7 +746,8 @@ out_err:int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -const char *argv[],bool pipe_output) +const char *argv[],bool pipe_output, +bool want_signal) {int child_ready_pipe[2 ], go_pipe[2 ];char bf;
@@ -796,7 +797,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,execvp (argv[0 ], (char **)argv);perror (argv[0 ]); -kill (getppid (),SIGUSR1 ); +if (want_signal) +kill (getppid (),SIGUSR1 );exit (-1 ); }
tools/perf/util/evlist.h +2 -1
@@ -87,7 +87,8 @@ void perf_evlist__config(struct perf_evlist *evlist,int perf_evlist__prepare_workload (struct perf_evlist *evlist,struct perf_target *target, -const char *argv[],bool pipe_output); +const char *argv[],bool pipe_output, +bool want_signal);int perf_evlist__start_workload (struct perf_evlist *evlist); int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
Namhyung Kim
maintainerPATCH 7/7 perf stat: use perf_evlist__prepare/start_workload()
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
The perf stat had an open code to the duplicated work. Use the helper as it now can be called without struct perf_record_opts.
--- tools/perf/builtin-stat.c | 58 ++++++----------------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-)
tools/perf/builtin-stat.c +7 -51
@@ -337,16 +337,14 @@ static void print_interval(void) } } -static int __run_perf_stat (int argc__maybe_unused ,const char **argv) +static int __run_perf_stat (int argc,const char **argv) {char msg[512 ];unsigned long long t0, t1;struct perf_evsel *counter;struct timespec ts;int status =0 ; -int child_ready_pipe[2 ], go_pipe[2 ];const bool forks = (argc >0 ); -char buf;if (interval) { ts.tv_sec = interval /1000 ;
@@ -362,55 +360,12 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)return -1 ; } -if (forks && (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 )) { -perror ("failed to create pipes" ); -return -1 ; - } -if (forks) { -if ((child_pid =fork ()) <0 ) -perror ("failed to fork" ); - -if (!child_pid) { -close (child_ready_pipe[0 ]); -close (go_pipe[1 ]); -fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); - -/* -* Do a dummy execvp to get the PLT entry resolved, -* so we avoid the resolver overhead on the real -* execvp call. -*/ -execvp ("" , (char **)argv); - -/* -* Tell the parent we're ready to go -*/ -close (child_ready_pipe[1 ]); - -/* -* Wait until the parent tells us to go. -*/ -if (read (go_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); - -execvp (argv[0 ], (char **)argv); - -perror (argv[0 ]); -exit (-1 ); +if (perf_evlist__prepare_workload (evsel_list, &target, argv, + false, false) <0 ) { +perror ("failed to prepare workload" ); +return -1 ; } - -if (perf_target__none (&target)) - evsel_list->threads->map[0 ] = child_pid; - -/* -* Wait for the child to be ready to exec. -*/ -close (child_ready_pipe[1 ]); -close (go_pipe[0 ]); -if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); -close (child_ready_pipe[0 ]); }if (group)
@@ -457,7 +412,8 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)clock_gettime (CLOCK_MONOTONIC , &ref_time);if (forks) { -close (go_pipe[1 ]); +perf_evlist__start_workload (evsel_list); +if (interval) {while (!waitpid (child_pid, &status,WNOHANG )) {nanosleep (&ts,NULL );
Signature · 1 line
1.7.11.7
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf stat: Use perf_evlist__prepare/ start_workload()
perf stat: Use perf_evlist__prepare/start_workload()
Commit-ID: acf2892270dcc4288c572b1159474c81f3819749 Gitweb: http://git.kernel.org/tip/acf2892270dcc4288c572b1159474c81f3819749 Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:18 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:04 -0300
perf stat: Use perf_evlist__prepare/start_workload()
The perf stat had an open code to the duplicated work. Use the helper as it now can be called without struct perf_record_opts.
--- tools/perf/builtin-stat.c | 58 ++++++----------------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-)
tools/perf/builtin-stat.c +7 -51
@@ -337,16 +337,14 @@ static void print_interval(void) } } -static int __run_perf_stat (int argc__maybe_unused ,const char **argv) +static int __run_perf_stat (int argc,const char **argv) {char msg[512 ];unsigned long long t0, t1;struct perf_evsel *counter;struct timespec ts;int status =0 ; -int child_ready_pipe[2 ], go_pipe[2 ];const bool forks = (argc >0 ); -char buf;if (interval) { ts.tv_sec = interval /1000 ;
@@ -362,55 +360,12 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)return -1 ; } -if (forks && (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 )) { -perror ("failed to create pipes" ); -return -1 ; - } -if (forks) { -if ((child_pid =fork ()) <0 ) -perror ("failed to fork" ); - -if (!child_pid) { -close (child_ready_pipe[0 ]); -close (go_pipe[1 ]); -fcntl (go_pipe[0 ],F_SETFD ,FD_CLOEXEC ); - -/* -* Do a dummy execvp to get the PLT entry resolved, -* so we avoid the resolver overhead on the real -* execvp call. -*/ -execvp ("" , (char **)argv); - -/* -* Tell the parent we're ready to go -*/ -close (child_ready_pipe[1 ]); - -/* -* Wait until the parent tells us to go. -*/ -if (read (go_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); - -execvp (argv[0 ], (char **)argv); - -perror (argv[0 ]); -exit (-1 ); +if (perf_evlist__prepare_workload (evsel_list, &target, argv, + false, false) <0 ) { +perror ("failed to prepare workload" ); +return -1 ; } - -if (perf_target__none (&target)) - evsel_list->threads->map[0 ] = child_pid; - -/* -* Wait for the child to be ready to exec. -*/ -close (child_ready_pipe[1 ]); -close (go_pipe[0 ]); -if (read (child_ready_pipe[0 ], &buf,1 ) ==-1 ) -perror ("unable to read pipe" ); -close (child_ready_pipe[0 ]); }if (group)
@@ -457,7 +412,8 @@ static int __run_perf_stat(int argc __maybe_unused, const char **argv)clock_gettime (CLOCK_MONOTONIC , &ref_time);if (forks) { -close (go_pipe[1 ]); +perf_evlist__start_workload (evsel_list); +if (interval) {while (!waitpid (child_pid, &status,WNOHANG )) {nanosleep (&ts,NULL );
tip-bot for Namhyung Kim
merge botperf evlist: Remove cpus and threads arguments from perf_evlist__new()
Commit-ID: 334fe7a3c63624eb1bba42f81eb088d5665d9f3e Gitweb: http://git.kernel.org/tip/334fe7a3c63624eb1bba42f81eb088d5665d9f3e Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 11 Mar 2013 16:43:12 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 15 Mar 2013 13:06:01 -0300
perf evlist: Remove cpus and threads arguments from perf_evlist__new()
It's almost always used with NULL for both arguments. Get rid of the arguments from the signature and use perf_evlist__set_maps() if needed.
--- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 ++-- tools/perf/tests/hists_link.c | 2 +- tools/perf/tests/mmap-basic.c | 4 +++- tools/perf/tests/open-syscall-tp-fields.c | 2 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/util/evlist.c | 5 ++--- tools/perf/util/evlist.h | 3 +-- tools/perf/util/header.c | 4 ++-- 13 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/builtin-record.c +1 -1
@@ -964,7 +964,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)struct perf_record *rec = &record;char errbuf[BUFSIZ ]; - evsel_list =perf_evlist__new (NULL ,NULL ); + evsel_list =perf_evlist__new ();if (evsel_list ==NULL )return -ENOMEM ;
tools/perf/builtin-stat.c +1 -1
@@ -1336,7 +1336,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)setlocale (LC_ALL ,"" ); - evsel_list =perf_evlist__new (NULL ,NULL ); + evsel_list =perf_evlist__new ();if (evsel_list ==NULL )return -ENOMEM ;
tools/perf/builtin-top.c +1 -1
@@ -1116,7 +1116,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) NULL }; - top.evlist =perf_evlist__new (NULL ,NULL ); + top.evlist =perf_evlist__new ();if (top.evlist ==NULL )return -ENOMEM ;
tools/perf/builtin-trace.c +1 -1
@@ -419,7 +419,7 @@ out_dump:static int trace__run (struct trace *trace,int argc,const char **argv) { -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;int err =-1 , i;unsigned long before;
tools/perf/tests/evsel-roundtrip-name.c +2 -2
@@ -8,7 +8,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)char name[128 ];int type, op, err =0 , ret =0 , i, idx;struct perf_evsel *evsel; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
@@ -64,7 +64,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names) {int i, err;struct perf_evsel *evsel; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/hists_link.c +1 -1
@@ -436,7 +436,7 @@ int test__hists_link(void)struct machines machines;struct machine *machine =NULL ;struct perf_evsel *evsel, *first; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/mmap-basic.c +3 -1
@@ -53,12 +53,14 @@ int test__basic_mmap(void) goto out_free_cpus; } - evlist =perf_evlist__new (cpus, threads); + evlist =perf_evlist__new ();if (evlist ==NULL ) {pr_debug ("perf_evlist__new\n" ); goto out_free_cpus; } +perf_evlist__set_maps (evlist, cpus, threads); +for (i =0 ; i < nsyscalls; ++i) {char name[64 ];
tools/perf/tests/open-syscall-tp-fields.c +1 -1
@@ -18,7 +18,7 @@ int test__syscall_open_tp_fields(void) };const char *filename ="/etc/passwd" ;int flags =O_RDONLY |O_DIRECTORY ; -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;int err =-1 , i, nr_events =0 , nr_polls =0 ;
tools/perf/tests/parse-events.c +1 -1
@@ -1218,7 +1218,7 @@ static int test_event(struct evlist_test *e)struct perf_evlist *evlist;int ret; - evlist =perf_evlist__new (NULL ,NULL ); + evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ;
tools/perf/tests/perf-record.c +1 -1
@@ -45,7 +45,7 @@ int test__PERF_RECORD(void) };cpu_set_t cpu_mask;size_t cpu_mask_size =sizeof (cpu_mask); -struct perf_evlist *evlist =perf_evlist__new (NULL ,NULL ); +struct perf_evlist *evlist =perf_evlist__new ();struct perf_evsel *evsel;struct perf_sample sample;const char *cmd ="sleep" ;
tools/perf/util/evlist.c +2 -3
@@ -38,13 +38,12 @@ void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, evlist->workload.pid =-1 ; } -struct perf_evlist *perf_evlist__new (struct cpu_map *cpus, -struct thread_map *threads) +struct perf_evlist *perf_evlist__new (void ) {struct perf_evlist *evlist =zalloc (sizeof (*evlist));if (evlist !=NULL ) -perf_evlist__init (evlist, cpus, threads); +perf_evlist__init (evlist,NULL ,NULL );return evlist; }
tools/perf/util/evlist.h +1 -2
@@ -49,8 +49,7 @@ struct perf_evsel_str_handler {void *handler; }; -struct perf_evlist *perf_evlist__new (struct cpu_map *cpus, -struct thread_map *threads); +struct perf_evlist *perf_evlist__new (void );void perf_evlist__init (struct perf_evlist *evlist,struct cpu_map *cpus,struct thread_map *threads);void perf_evlist__exit (struct perf_evlist *evlist);
tools/perf/util/header.c +2 -2
@@ -2789,7 +2789,7 @@ int perf_session__read_header(struct perf_session *session, int fd)u64 f_id;int nr_attrs, nr_ids, i, j; - session->evlist =perf_evlist__new (NULL ,NULL ); + session->evlist =perf_evlist__new ();if (session->evlist ==NULL )return -ENOMEM ;
@@ -2940,7 +2940,7 @@ int perf_event__process_attr(union perf_event *event,struct perf_evlist *evlist = *pevlist;if (evlist ==NULL ) { - *pevlist = evlist =perf_evlist__new (NULL ,NULL ); + *pevlist = evlist =perf_evlist__new ();if (evlist ==NULL )return -ENOMEM ; }