perf record: We should fork only if a program was specified to run
PATCH 1/10 perf record: We should fork only if a program was specified to run
From: Arnaldo Carvalho de Melo <[email protected]>
IOW: Now 'perf record -a' works, this was a bug introduced in:
856e96608a72412d319e498a3a7c557571f811bd "perf record: Properly synchronize child creation"
Also fix the -C usage, i.e. allow for profiling all the tasks in one CPU.
--- tools/perf/builtin-record.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
tools/perf/builtin-record.c +8 -6
@@ -402,7 +402,7 @@ static void atexit_header(void)perf_header__write (&session->header, output, true); } -static int __cmd_record (int argc__used ,const char **argv) +static int __cmd_record (int argc,const char **argv) {int i, counter;struct stat st;
@@ -411,6 +411,7 @@ static int __cmd_record(int argc __used, const char **argv)int err;unsigned long waking =0 ;int child_ready_pipe[2 ], go_pipe[2 ]; +const bool forks = target_pid ==-1 && argc >0 ;char buf; page_size =sysconf (_SC_PAGE_SIZE);
@@ -422,7 +423,7 @@ static int __cmd_record(int argc __used, const char **argv)signal (SIGCHLD , sig_handler);signal (SIGINT , sig_handler); -if (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 ) { +if (forks && (pipe (child_ready_pipe) <0 ||pipe (go_pipe) <0 )) {perror ("failed to create pipes" );exit (-1 ); }
@@ -483,7 +484,7 @@ static int __cmd_record(int argc __used, const char **argv)atexit (atexit_header); -if (target_pid ==-1 ) { +if (forks) { pid =fork ();if (pid <0 ) {perror ("failed to fork" );
@@ -550,7 +551,7 @@ static int __cmd_record(int argc __used, const char **argv)return err; } -if (!system_wide) +if (!system_wide && profile_cpu ==-1 )event__synthesize_thread (pid, process_synthesized_event, session);else
@@ -569,7 +570,8 @@ static int __cmd_record(int argc __used, const char **argv)/* * Let the child rip */ -close (go_pipe[1 ]); +if (forks) +close (go_pipe[1 ]);for (;;) {int hits = samples;
@@ -667,7 +669,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) argc =parse_options (argc, argv, options, record_usage,PARSE_OPT_STOP_AT_NON_OPTION ); -if (!argc && target_pid ==-1 && (!system_wide || profile_cpu ==-1 )) +if (!argc && target_pid ==-1 && !system_wide && profile_cpu ==-1 )usage_with_options (record_usage, options);symbol__init ();
Signature · 1 line
1.6.2.5
PATCH 2/10 perf tools: Add missing header files to LIB_H Makefile variable
From: Arnaldo Carvalho de Melo <[email protected]>
So that changes in them trigger rebuilds, like when we're doing bisects.
--- tools/perf/Makefile | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
tools/perf/Makefile +8 -0
@@ -343,13 +343,18 @@ LIB_H += util/include/linux/string.h LIB_H += util/include/linux/types.h LIB_H += util/include/asm/asm-offsets.h LIB_H += util/include/asm/bitops.h +LIB_H += util/include/asm/bug.h LIB_H += util/include/asm/byteorder.h LIB_H += util/include/asm/swab.h LIB_H += util/include/asm/system.h LIB_H += util/include/asm/uaccess.h LIB_H += perf.h +LIB_H += util/cache.h +LIB_H += util/callchain.h +LIB_H += util/debug.h LIB_H += util/debugfs.h LIB_H += util/event.h +LIB_H += util/exec_cmd.h LIB_H += util/types.h LIB_H += util/levenshtein.h LIB_H += util/parse-options.h
@@ -362,6 +367,7 @@ LIB_H += util/session.h LIB_H += util/strbuf.h LIB_H += util/string.h LIB_H += util/strlist.h +LIB_H += util/svghelper.h LIB_H += util/run-command.h LIB_H += util/sigchain.h LIB_H += util/symbol.h
@@ -370,6 +376,8 @@ LIB_H += util/values.h LIB_H += util/sort.h LIB_H += util/hist.h LIB_H += util/thread.h +LIB_H += util/trace-event.h +LIB_H += util/trace-event-perl.h LIB_H += util/probe-finder.h LIB_H += util/probe-event.h
Signature · 1 line
1.6.2.5
PATCH 3/10 perf session: Move the event processing routines to session.c
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No need for an extra "data_map" file since the routines there operate mainly on a perf_session instance.
--- tools/perf/Makefile | 1 - tools/perf/util/data_map.c | 252 -------------------------------------------- tools/perf/util/session.c | 245 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+), 253 deletions(-) delete mode 100644 tools/perf/util/data_map.c
tools/perf/Makefile +0 -1
@@ -423,7 +423,6 @@ LIB_OBJS += util/trace-event-perl.o LIB_OBJS += util/svghelper.o LIB_OBJS += util/sort.o LIB_OBJS += util/hist.o -LIB_OBJS += util/data_map.o LIB_OBJS += util/probe-event.o BUILTIN_OBJS += builtin-annotate.o
tools/perf/util/data_map.c deleted +0 -252
252 lines not on this page · raw message
tools/perf/util/session.c +245 -0
248 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 4/10 perf tools: Move the map class definition to a separate header
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
And this resulted in the need for adding some missing includes in some places that were getting the definitions needed out of sheer luck.
--- tools/perf/Makefile | 1 + tools/perf/util/debug.c | 1 + tools/perf/util/event.h | 65 ++---------------------------------- tools/perf/util/map.h | 73 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/probe-finder.h | 2 + 5 files changed, 80 insertions(+), 62 deletions(-) create mode 100644 tools/perf/util/map.h
tools/perf/Makefile +1 -0
@@ -357,6 +357,7 @@ LIB_H += util/event.h LIB_H += util/exec_cmd.h LIB_H += util/types.h LIB_H += util/levenshtein.h +LIB_H += util/map.h LIB_H += util/parse-options.h LIB_H += util/parse-events.h LIB_H += util/quote.h
tools/perf/util/debug.c +1 -0
@@ -9,6 +9,7 @@#include "color.h" #include "event.h" #include "debug.h" +#include "util.h" int verbose =0 ;int dump_trace =0 ;
tools/perf/util/event.h +3 -62
80 lines not on this page · raw message
tools/perf/util/map.h new file +73 -0
73 lines not on this page · raw message
tools/perf/util/probe-finder.h +2 -0
@@ -1,6 +1,8 @@#ifndef _PROBE_FINDER_H#define _PROBE_FINDER_H +#include "util.h" +#define MAX_PATH_LEN 256#define MAX_PROBE_BUFFER 1024#define MAX_PROBES 128
Signature · 1 line
1.6.2.5
PATCH 5/10 perf session: Share the common trace sample_check routine as perf_session__has_traces
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-kmem.c | 14 +------------- tools/perf/builtin-sched.c | 14 +------------- tools/perf/builtin-timechart.c | 13 +------------ tools/perf/builtin-trace.c | 14 +------------- tools/perf/util/session.c | 11 +++++++++++ tools/perf/util/session.h | 2 ++ 6 files changed, 17 insertions(+), 51 deletions(-)
tools/perf/builtin-kmem.c +1 -13
@@ -342,22 +342,10 @@ static int process_sample_event(event_t *event, struct perf_session *session)return 0 ; } -static int sample_type_check (struct perf_session *session) -{ -if (!(session->sample_type &PERF_SAMPLE_RAW )) { -fprintf (stderr, -"No trace sample to read. Did you call perf record " -"without -R?" ); -return -1 ; - } - -return 0 ; -} -static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, - .sample_type_check = sample_type_check, + .sample_type_check = perf_session__has_traces, };static double fragmentation (unsigned long n_req,unsigned long n_alloc)
tools/perf/builtin-sched.c +1 -13
@@ -1653,23 +1653,11 @@ static int process_lost_event(event_t *event __used,return 0 ; } -static int sample_type_check (struct perf_session *session__used ) -{ -if (!(session->sample_type &PERF_SAMPLE_RAW )) { -fprintf (stderr, -"No trace sample to read. Did you call perf record " -"without -R?" ); -return -1 ; - } - -return 0 ; -} -static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, .process_lost_event = process_lost_event, - .sample_type_check = sample_type_check, + .sample_type_check = perf_session__has_traces, };static int read_events (void )
tools/perf/builtin-timechart.c +1 -12
@@ -1029,23 +1029,12 @@ static void process_samples(struct perf_session *session) } } -static int sample_type_check (struct perf_session *session) -{ -if (!(session->sample_type &PERF_SAMPLE_RAW )) { -fprintf (stderr,"No trace samples found in the file.\n" -"Have you used 'perf timechart record' to record it?\n" ); -return -1 ; - } - -return 0 ; -} -static struct perf_event_ops event_ops = { .process_comm_event = process_comm_event, .process_fork_event = process_fork_event, .process_exit_event = process_exit_event, .process_sample_event = queue_sample_event, - .sample_type_check = sample_type_check, + .sample_type_check = perf_session__has_traces, };static int __cmd_timechart (void )
tools/perf/builtin-trace.c +1 -13
@@ -103,22 +103,10 @@ static int process_sample_event(event_t *event, struct perf_session *session)return 0 ; } -static int sample_type_check (struct perf_session *session) -{ -if (!(session->sample_type &PERF_SAMPLE_RAW )) { -fprintf (stderr, -"No trace sample to read. Did you call perf record " -"without -R?" ); -return -1 ; - } - -return 0 ; -} -static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, - .sample_type_check = sample_type_check, + .sample_type_check = perf_session__has_traces, };static int __cmd_trace (struct perf_session *session)
tools/perf/util/session.c +11 -0
@@ -393,3 +393,14 @@ done: out_err:return err; } + +int perf_session__has_traces (struct perf_session *self) +{ +if (!(self->sample_type &PERF_SAMPLE_RAW )) { +pr_err ("No trace sample to read. Did you call perf record " +"without -R?" ); +return -1 ; + } + +return 0 ; +}
tools/perf/util/session.h +2 -0
@@ -56,6 +56,8 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,struct ip_callchain *chain, struct symbol **parent); +int perf_session__has_traces (struct perf_session *self); +int perf_header__read_build_ids (int input,u64 offset,u64 file_size);#endif /* __PERF_SESSION_H */
Signature · 1 line
1.6.2.5
PATCH 6/10 perf session: Remove sample_type_check from event_ops
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
This is really something tools need to do before asking for the events to be processed, leaving perf_session__process_events to do just that, process events.
Also add a msg parameter to perf_session__has_traces() so that the right message can be printed, fixing a regression added by me in the previous cset (right timechart message) and also fixing 'perf kmem', that was not asking if 'perf kmem record' was ran.
--- tools/perf/builtin-kmem.c | 6 ++++-- tools/perf/builtin-report.c | 16 +++++++++------- tools/perf/builtin-sched.c | 7 ++++--- tools/perf/builtin-timechart.c | 6 ++++-- tools/perf/builtin-trace.c | 4 +++- tools/perf/util/session.c | 16 ++++++---------- tools/perf/util/session.h | 3 +-- 7 files changed, 31 insertions(+), 27 deletions(-)
tools/perf/builtin-kmem.c +4 -2
@@ -345,7 +345,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, - .sample_type_check = perf_session__has_traces, };static double fragmentation (unsigned long n_req,unsigned long n_alloc)
@@ -492,11 +491,14 @@ static void sort_result(void)static int __cmd_kmem (void ) { -int err; +int err = -EINVAL ;struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 );if (session ==NULL )return -ENOMEM ; +if (!perf_session__has_traces (session,"kmem record" )) + goto out_delete; +setup_pager (); err =perf_session__process_events (session, &event_ops);if (err !=0 )
tools/perf/builtin-report.c +9 -7
@@ -156,14 +156,14 @@ static int process_read_event(event_t *event, struct perf_session *session __usereturn 0 ; } -static int sample_type_check (struct perf_session *session) +static int perf_session__setup_sample_type (struct perf_session *self) { -if (!(session->sample_type &PERF_SAMPLE_CALLCHAIN )) { +if (!(self->sample_type &PERF_SAMPLE_CALLCHAIN )) {if (sort__has_parent) {fprintf (stderr,"selected --sort parent, but no" " callchain data. Did you call" " perf record without -g?\n" ); -return -1 ; +return -EINVAL ; }if (symbol_conf.use_callchain) { fprintf(stderr, "selected -g but no callchain data."
@@ -176,7 +176,7 @@ static int sample_type_check(struct perf_session *session)if (register_callchain_param (&callchain_param) <0 ) {fprintf (stderr,"Can't register callchain" " params\n" ); -return -1 ; +return -EINVAL ; } }
@@ -191,13 +191,11 @@ static struct perf_event_ops event_ops = { .process_fork_event = event__process_task, .process_lost_event = event__process_lost, .process_read_event = process_read_event, - .sample_type_check = sample_type_check, }; -static int __cmd_report (void ) { -int ret; +int ret = -EINVAL ;struct perf_session *session; session =perf_session__new (input_name,O_RDONLY , force);
@@ -207,6 +205,10 @@ static int __cmd_report(void)if (show_threads)perf_read_values_init (&show_threads_values); + ret =perf_session__setup_sample_type (session); +if (ret) + goto out_delete; + ret =perf_session__process_events (session, &event_ops);if (ret) goto out_delete;
tools/perf/builtin-sched.c +4 -3
@@ -1657,17 +1657,18 @@ static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, .process_lost_event = process_lost_event, - .sample_type_check = perf_session__has_traces, };static int read_events (void ) { -int err; +int err = -EINVAL ;struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 );if (session ==NULL )return -ENOMEM ; - err =perf_session__process_events (session, &event_ops); +if (perf_session__has_traces (session,"record -R" )) + err =perf_session__process_events (session, &event_ops); +perf_session__delete (session);return err; }
tools/perf/builtin-timechart.c +4 -2
@@ -1034,17 +1034,19 @@ static struct perf_event_ops event_ops = { .process_fork_event = process_fork_event, .process_exit_event = process_exit_event, .process_sample_event = queue_sample_event, - .sample_type_check = perf_session__has_traces, };static int __cmd_timechart (void ) {struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 ); -int ret; +int ret = -EINVAL ;if (session ==NULL )return -ENOMEM ; +if (!perf_session__has_traces (session,"timechart record" )) + goto out_delete; + ret =perf_session__process_events (session, &event_ops);if (ret) goto out_delete;
tools/perf/builtin-trace.c +3 -1
@@ -106,7 +106,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)static struct perf_event_ops event_ops = { .process_sample_event = process_sample_event, .process_comm_event = event__process_comm, - .sample_type_check = perf_session__has_traces, };static int __cmd_trace (struct perf_session *session)
@@ -580,6 +579,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)if (session ==NULL )return -ENOMEM ; +if (!perf_session__has_traces (session,"record -R" )) +return -EINVAL ; +if (generate_script_lang) {struct stat perf_stat;
tools/perf/util/session.c +6 -10
@@ -73,6 +73,8 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forcif (mode ==O_RDONLY &&perf_session__open (self, force) <0 ) goto out_delete; + + self->sample_type =perf_header__sample_type (&self->header); out:return self; out_free:
@@ -302,11 +304,6 @@ int perf_session__process_events(struct perf_session *self, page_size =getpagesize (); head = self->header.data_offset; - self->sample_type =perf_header__sample_type (&self->header); - - err = -EINVAL ; -if (ops->sample_type_check && ops->sample_type_check (self) <0 ) - goto out_err;if (!ops->full_paths) {char bf[PATH_MAX ];
@@ -394,13 +391,12 @@ out_err:return err; } -int perf_session__has_traces (struct perf_session *self) +bool perf_session__has_traces (struct perf_session *self,const char *msg) {if (!(self->sample_type &PERF_SAMPLE_RAW )) { -pr_err ("No trace sample to read. Did you call perf record " -"without -R?" ); -return -1 ; +pr_err ("No trace sample to read. Did you call 'perf %s'?\n" , msg); +return false; } -return 0 ; +return true; }
tools/perf/util/session.h +1 -2
@@ -40,7 +40,6 @@ struct perf_event_ops {event_op process_read_event;event_op process_throttle_event;event_op process_unthrottle_event; -int (*sample_type_check)(struct perf_session *session);unsigned long total_unknown;bool full_paths; };
@@ -56,7 +55,7 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,struct ip_callchain *chain, struct symbol **parent); -int perf_session__has_traces (struct perf_session *self); +bool perf_session__has_traces (struct perf_session *self,const char *msg);int perf_header__read_build_ids (int input,u64 offset,u64 file_size);
Signature · 1 line
1.6.2.5
PATCH 7/10 perf session: Move total_unknown to perf_session->unknown events
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
As this is a session property, not belonging to perf_event_ops, that can be shared by many perf_session instances.
--- tools/perf/util/session.c | 3 ++- tools/perf/util/session.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/session.c +2 -1
@@ -66,6 +66,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc self->mmap_window =32 ; self->cwd =NULL ; self->cwdlen =0 ; + self->unknown_events =0 ;map_groups__init (&self->kmaps);if (perf_session__create_kernel_maps (self) <0 )
@@ -239,7 +240,7 @@ static int perf_session__process_event(struct perf_session *self,case PERF_RECORD_UNTHROTTLE :return ops->process_unthrottle_event (event, self);default : - ops->total_unknown++; + self->unknown_events++;return -1 ; } }
tools/perf/util/session.h +1 -1
@@ -20,6 +20,7 @@ struct perf_session {struct thread *last_match;struct events_stats events_stats;unsigned long event_total[PERF_RECORD_MAX ]; +unsigned long unknown_events;struct rb_root hists;u64 sample_type;int fd;
@@ -40,7 +41,6 @@ struct perf_event_ops {event_op process_read_event;event_op process_throttle_event;event_op process_unthrottle_event; -unsigned long total_unknown;bool full_paths; };
Signature · 1 line
1.6.2.5
PATCH 8/10 perf session: Move full_paths config to symbol_conf
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Now perf_event_ops has just that, event handlers.
--- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/session.h | 1 - tools/perf/util/symbol.h | 3 ++- 5 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-diff.c +1 -1
@@ -204,7 +204,7 @@ static const struct option options[] = {OPT_BOOLEAN ('f' ,"force" , &force,"don't complain, do it" ),OPT_BOOLEAN ('m' ,"modules" , &symbol_conf.use_modules,"load module symbols - WARNING: use only with -k and LIVE kernel" ), -OPT_BOOLEAN ('P' ,"full-paths" , &event_ops.full_paths, +OPT_BOOLEAN ('P' ,"full-paths" , &symbol_conf.full_paths,"Don't shorten the pathnames taking into account the cwd" ),OPT_STRING ('d' ,"dsos" , &symbol_conf.dso_list_str,"dso[,dso...]" , "only consider symbols in these dsos"),
tools/perf/builtin-report.c +1 -1
@@ -321,7 +321,7 @@ static const struct option options[] = { "pretty printing style key: normal raw"),OPT_STRING ('s' ,"sort" , &sort_order,"key[,key2...]" ,"sort by key(s): pid, comm, dso, symbol, parent" ), -OPT_BOOLEAN ('P' ,"full-paths" , &event_ops.full_paths, +OPT_BOOLEAN ('P' ,"full-paths" , &symbol_conf.full_paths,"Don't shorten the pathnames taking into account the cwd" ),OPT_STRING ('p' ,"parent" , &parent_pattern,"regex" , "regex filter to identify parent, see: '--sort parent'"),
tools/perf/util/session.c +1 -1
@@ -306,7 +306,7 @@ int perf_session__process_events(struct perf_session *self, head = self->header.data_offset; -if (!ops->full_paths) { +if (!symbol_conf.full_paths) {char bf[PATH_MAX ];if (getcwd (bf,sizeof (bf)) ==NULL ) {
tools/perf/util/session.h +0 -1
@@ -41,7 +41,6 @@ struct perf_event_ops {event_op process_read_event;event_op process_throttle_event;event_op process_unthrottle_event; -bool full_paths; };struct perf_session *perf_session__new (const char *filename,int mode,bool force);
tools/perf/util/symbol.h +2 -1
@@ -58,7 +58,8 @@ struct symbol_conf { sort_by_name, show_nr_samples, use_callchain, - exclude_other; + exclude_other, + full_paths;const char *vmlinux_name, *field_sep; char *dso_list_str,
Signature · 1 line
1.6.2.5
PATCH 9/10 perf session: Remove redundant prefix & suffix from perf_event_ops
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Since now all that we have are perf event handlers, leave just the name of the event.
--- tools/perf/builtin-annotate.c | 8 +++--- tools/perf/builtin-diff.c | 12 ++++---- tools/perf/builtin-kmem.c | 4 +- tools/perf/builtin-report.c | 14 +++++----- tools/perf/builtin-sched.c | 6 ++-- tools/perf/builtin-timechart.c | 8 +++--- tools/perf/builtin-trace.c | 4 +- tools/perf/util/session.c | 54 ++++++++++++++++++++-------------------- tools/perf/util/session.h | 18 ++++++------ 9 files changed, 64 insertions(+), 64 deletions(-)
tools/perf/builtin-annotate.c +4 -4
@@ -451,10 +451,10 @@ static void perf_session__find_annotations(struct perf_session *self) }static struct perf_event_ops event_ops = { - .process_sample_event = process_sample_event, - .process_mmap_event = event__process_mmap, - .process_comm_event = event__process_comm, - .process_fork_event = event__process_task, + .sample = process_sample_event, + .mmap = event__process_mmap, + .comm = event__process_comm, + .fork = event__process_task, };static int __cmd_annotate (void )
tools/perf/builtin-diff.c +6 -6
@@ -66,12 +66,12 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi }static struct perf_event_ops event_ops = { - .process_sample_event = diff__process_sample_event, - .process_mmap_event = event__process_mmap, - .process_comm_event = event__process_comm, - .process_exit_event = event__process_task, - .process_fork_event = event__process_task, - .process_lost_event = event__process_lost, + .sample = diff__process_sample_event, + .mmap = event__process_mmap, + .comm = event__process_comm, + .exit = event__process_task, + .fork = event__process_task, + .lost = event__process_lost, }; static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
tools/perf/builtin-kmem.c +2 -2
@@ -343,8 +343,8 @@ static int process_sample_event(event_t *event, struct perf_session *session) }static struct perf_event_ops event_ops = { - .process_sample_event = process_sample_event, - .process_comm_event = event__process_comm, + .sample = process_sample_event, + .comm = event__process_comm, };static double fragmentation (unsigned long n_req,unsigned long n_alloc)
tools/perf/builtin-report.c +7 -7
@@ -184,13 +184,13 @@ static int perf_session__setup_sample_type(struct perf_session *self) }static struct perf_event_ops event_ops = { - .process_sample_event = process_sample_event, - .process_mmap_event = event__process_mmap, - .process_comm_event = event__process_comm, - .process_exit_event = event__process_task, - .process_fork_event = event__process_task, - .process_lost_event = event__process_lost, - .process_read_event = process_read_event, + .sample = process_sample_event, + .mmap = event__process_mmap, + .comm = event__process_comm, + .exit = event__process_task, + .fork = event__process_task, + .lost = event__process_lost, + .read = process_read_event, };static int __cmd_report (void )
tools/perf/builtin-sched.c +3 -3
@@ -1654,9 +1654,9 @@ static int process_lost_event(event_t *event __used, }static struct perf_event_ops event_ops = { - .process_sample_event = process_sample_event, - .process_comm_event = event__process_comm, - .process_lost_event = process_lost_event, + .sample = process_sample_event, + .comm = event__process_comm, + .lost = process_lost_event, };static int read_events (void )
tools/perf/builtin-timechart.c +4 -4
@@ -1030,10 +1030,10 @@ static void process_samples(struct perf_session *session) }static struct perf_event_ops event_ops = { - .process_comm_event = process_comm_event, - .process_fork_event = process_fork_event, - .process_exit_event = process_exit_event, - .process_sample_event = queue_sample_event, + .comm = process_comm_event, + .fork = process_fork_event, + .exit = process_exit_event, + .sample = queue_sample_event, };static int __cmd_timechart (void )
tools/perf/builtin-trace.c +2 -2
@@ -104,8 +104,8 @@ static int process_sample_event(event_t *event, struct perf_session *session) }static struct perf_event_ops event_ops = { - .process_sample_event = process_sample_event, - .process_comm_event = event__process_comm, + .sample = process_sample_event, + .comm = event__process_comm, };static int __cmd_trace (struct perf_session *session)
tools/perf/util/session.c +27 -27
74 lines not on this page · raw message
tools/perf/util/session.h +9 -9
@@ -32,15 +32,15 @@ struct perf_session {typedef int (*event_op )(event_t *self,struct perf_session *session);struct perf_event_ops { -event_op process_sample_event; -event_op process_mmap_event; -event_op process_comm_event; -event_op process_fork_event; -event_op process_exit_event; -event_op process_lost_event; -event_op process_read_event; -event_op process_throttle_event; -event_op process_unthrottle_event; +event_op sample, + mmap, + comm, + fork, + exit, + lost, + read, + throttle, + unthrottle; };struct perf_session *perf_session__new (const char *filename,int mode,bool force);
Signature · 1 line
1.6.2.5
PATCH 10/10 perf record: Introduce a symtab cache
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Now a cache will be created in a ~/.debug debuginfo like hierarchy, so that at the end of a 'perf record' session all the binaries (with build-ids) involved get collected and indexed by their build-ids, so that perf record can find them.
This is interesting when developing software where you want to do a 'perf diff' with the previous build and opens avenues for lots more interesting tools, like a 'perf diff --graph' that takes more than two binaries into account.
Tunables for collecting just the symtabs can be added if one doesn't want to have the full binary, but having the full binary allows things like 'perf rerecord' or other tools that can re-run the tests by having access to the exact binary in some perf.data file, so it may well be interesting to keep the full binary there.
Space consumption is minimised by trying to use hard links, a 'perf cache' tool to manage the space used, a la ccache is required to purge older entries.
With this in place it will be possible also to introduce new commands, 'perf archive' and 'perf restore' (or some more suitable and future proof names) to create a cpio/tar file with the perf data and the files in the cache that _had_ perf hits of interest.
There are more aspects to polish, like finding the right vmlinux file to cache, etc, but this is enough for a first step.
--- tools/perf/Makefile | 1 + tools/perf/util/header.c | 82 +++++++++++++++++++++++++++++++++++++++++++--- tools/perf/util/symbol.c | 17 +++++++-- tools/perf/util/symbol.h | 2 + tools/perf/util/util.c | 69 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/util.h | 3 ++ 6 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 tools/perf/util/util.c
tools/perf/Makefile +1 -0
@@ -425,6 +425,7 @@ LIB_OBJS += util/svghelper.o LIB_OBJS += util/sort.o LIB_OBJS += util/hist.o LIB_OBJS += util/probe-event.o +LIB_OBJS += util/util.o BUILTIN_OBJS += builtin-annotate.o
tools/perf/util/header.c +77 -5
109 lines not on this page · raw message
tools/perf/util/symbol.c +13 -4
@@ -22,6 +22,7 @@enum dso_origin {DSO__ORIG_KERNEL =0 ,DSO__ORIG_JAVA_JIT , +DSO__ORIG_BUILD_ID_CACHE ,DSO__ORIG_FEDORA ,DSO__ORIG_UBUNTU ,DSO__ORIG_BUILDID ,
@@ -1191,6 +1192,7 @@ char dso__symtab_origin(const struct dso *self)static const char origin[] = { [DSO__ORIG_KERNEL ] ='k' , [DSO__ORIG_JAVA_JIT ] ='j' , + [DSO__ORIG_BUILD_ID_CACHE ] ='B' , [DSO__ORIG_FEDORA ] ='f' , [DSO__ORIG_UBUNTU ] ='u' , [DSO__ORIG_BUILDID ] ='b' ,
@@ -1209,6 +1211,7 @@ int dso__load(struct dso *self, struct map *map, struct perf_session *session,int size =PATH_MAX ;char *name;u8 build_id[BUILD_ID_SIZE ]; +char build_id_hex[BUILD_ID_SIZE *2 +1 ];int ret =-1 ;int fd;
@@ -1230,8 +1233,16 @@ int dso__load(struct dso *self, struct map *map, struct perf_session *session,return ret; } - self->origin =DSO__ORIG_FEDORA -1 ; + self->origin =DSO__ORIG_BUILD_ID_CACHE ; +if (self->has_build_id) { +build_id__sprintf (self->build_id,sizeof (self->build_id), + build_id_hex); +snprintf (name, size,"%s/%s/.build-id/%.2s/%s" , +getenv ("HOME" ),DEBUG_CACHE_DIR , + build_id_hex, build_id_hex +2 ); + goto open_file; + } more: do { self->origin++;
@@ -1247,8 +1258,6 @@ more:case DSO__ORIG_BUILDID :if (filename__read_build_id (self->long_name, build_id,sizeof (build_id))) { -char build_id_hex[BUILD_ID_SIZE *2 +1 ]; -build_id__sprintf (build_id,sizeof (build_id), build_id_hex); snprintf(name, size,
@@ -1276,7 +1285,7 @@ compare_build_id:if (!dso__build_id_equal (self, build_id)) goto more; } - +open_file: fd =open (name,O_RDONLY ); }while (fd <0 );
tools/perf/util/symbol.h +2 -0
@@ -8,6 +8,8 @@#include <linux/rbtree.h> #include "event.h" +#define DEBUG_CACHE_DIR ".debug" +#ifdef HAVE_CPLUS_DEMANGLE extern char *cplus_demangle (const char *,int );
tools/perf/util/util.c new file +69 -0
69 lines not on this page · raw message
tools/perf/util/util.h +3 -0
@@ -403,4 +403,7 @@ void git_qsort(void *base, size_t nmemb, size_t size,#endif #endif +int mkdir_p (char *path,mode_t mode); +int copyfile (const char *from,const char *to); +#endif
Signature · 1 line
1.6.2.5
Re: [PATCH 10/10] perf record: Introduce a symtab cache
Em Sun, Dec 27, 2009 at 09:37:06PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 6 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Now a cache will be created in a ~/.debug debuginfo like hierarchy, so that at the end of a 'perf record' session all the binaries (with build-ids) involved get collected and indexed by their build-ids, so that perf record can find them.
Gack, 'so that perf report' (and new tools, hopefully) can find them, of course :-\ If you notice this, please fix it up.
- Arnaldo
Re: [PATCH 10/10] perf record: Introduce a symtab cache
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Sun, Dec 27, 2009 at 09:37:06PM -0200, Arnaldo Carvalho de Melo escreveu:
Quoted 6 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Now a cache will be created in a ~/.debug debuginfo like hierarchy, so that at the end of a 'perf record' session all the binaries (with build-ids) involved get collected and indexed by their build-ids, so that perf record can find them.
Gack, 'so that perf report' (and new tools, hopefully) can find them, of course :-\ If you notice this, please fix it up.
I fixed the log message - thanks Arnaldo.
Ingo
Note, i moved the first two patches into perf/urgent (as they are fixes), the others into perf/core.
Ingo