perf fixes
Linus,
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus
This should finally solve the window resizing problem of the TUI:
perf report and perf top will resize properly with xterm size changes.
Thanks,
Ingo
------------------>
Arnaldo Carvalho de Melo (16):
perf evlist: Fix grouping of multiple events
perf ui progress: Reimplement using slang
perf ui: Improve handling sigwinch a bit
perf ui: Reimplement ui_helpline using libslang
perf ui: Reimplement ui__popup_menu using ui__browser
perf ui: Reimplement the popup windows using libslang
perf ui: Rename ui__warning_paranoid to ui__error_paranoid perf hists browser: Use K_TIMER
perf ui browser: No need to switch char sets that often perf ui browser: Handle K_RESIZE in dialog windows
perf header: Fix build on old systems
perf hists: Fix recalculation of total_period when sorting entries perf hists browser: Warn about lost events
perf report: Add progress bar when processing time ordered events perf top tui: Don't recalc column widths considering just the first page perf top: Fix live annotation in the --stdio interface
Masami Hiramatsu (1):
perf tools: Fix a typo of command name as trace-cmd
tools/perf/builtin-record.c | 13 ++- tools/perf/builtin-stat.c | 20 +++- tools/perf/builtin-test.c | 6 +- tools/perf/builtin-top.c | 54 +++++++--- tools/perf/util/annotate.c | 9 +- tools/perf/util/debug.c | 7 +- tools/perf/util/debug.h | 17 +-- tools/perf/util/evlist.c | 30 +++++ tools/perf/util/evlist.h | 2 + tools/perf/util/evsel.c | 43 ++++++-- tools/perf/util/evsel.h | 10 ++- tools/perf/util/header.c | 2 +- tools/perf/util/hist.c | 3 +- tools/perf/util/hist.h | 1 + tools/perf/util/python.c | 31 +++++- tools/perf/util/session.c | 46 ++++++-- tools/perf/util/session.h | 1 + tools/perf/util/top.h | 1 - tools/perf/util/trace-event-info.c | 2 +- tools/perf/util/ui/browser.c | 151 ++++++++++++++++++--------- tools/perf/util/ui/browser.h | 9 ++ tools/perf/util/ui/browsers/annotate.c | 14 +-- tools/perf/util/ui/browsers/hists.c | 74 ++++++++++--- tools/perf/util/ui/helpline.c | 16 ++- tools/perf/util/ui/helpline.h | 2 + tools/perf/util/ui/progress.c | 65 +++--------- tools/perf/util/ui/progress.h | 7 +- tools/perf/util/ui/setup.c | 83 ++++++++++++++- tools/perf/util/ui/ui.h | 3 + tools/perf/util/ui/util.c | 182 +++++++++++++++++++------------- tools/perf/util/ui/util.h | 8 +- 31 files changed, 624 insertions(+), 288 deletions(-)
tools/perf/builtin-record.c +10 -3
@@ -262,13 +262,16 @@ static bool perf_evlist__equal(struct perf_evlist *evlist,static void open_counters (struct perf_evlist *evlist) { -struct perf_evsel *pos; +struct perf_evsel *pos, *first;if (evlist->cpus->map[0 ] <0 ) no_inherit = true; + first = list_entry(evlist->entries.next, struct perf_evsel, node); +list_for_each_entry (pos, &evlist->entries, node) {struct perf_event_attr *attr = &pos->attr; +struct xyarray *group_fd =NULL ;/* * Check if parse_single_tracepoint_event has already asked for * PERF_SAMPLE_TIME.
@@ -283,15 +286,19 @@ static void open_counters(struct perf_evlist *evlist)*/ bool time_needed = attr->sample_type &PERF_SAMPLE_TIME ; +if (group && pos != first) + group_fd = first->fd; +config_attr (pos, evlist); retry_sample_id: attr->sample_id_all = sample_id_all_avail ?1 :0 ; try_again: -if (perf_evsel__open (pos, evlist->cpus, evlist->threads, group) <0 ) { +if (perf_evsel__open (pos, evlist->cpus, evlist->threads, group, + group_fd) <0 ) {int err = errno;if (err ==EPERM || err ==EACCES ) { -ui__warning_paranoid (); +ui__error_paranoid ();exit (EXIT_FAILURE ); }else if (err ==ENODEV && cpu_list) { die("No such device - did you specify"
tools/perf/builtin-stat.c +14 -6
@@ -278,9 +278,14 @@ struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS ];struct stats walltime_nsecs_stats; -static int create_perf_stat_counter (struct perf_evsel *evsel) +static int create_perf_stat_counter (struct perf_evsel *evsel, +struct perf_evsel *first) {struct perf_event_attr *attr = &evsel->attr; +struct xyarray *group_fd =NULL ; + +if (group && evsel != first) + group_fd = first->fd;if (scale) attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -289,14 +294,15 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->inherit = !no_inherit;if (system_wide) -return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, group); - +return perf_evsel__open_per_cpu (evsel, evsel_list->cpus, + group, group_fd);if (target_pid ==-1 && target_tid ==-1 ) { attr->disabled =1 ; attr->enable_on_exec =1 ; } -return perf_evsel__open_per_thread (evsel, evsel_list->threads, group); +return perf_evsel__open_per_thread (evsel, evsel_list->threads, + group, group_fd); }/*
@@ -396,7 +402,7 @@ static int read_counter(struct perf_evsel *counter)static int run_perf_stat (int argc__used ,const char **argv) {unsigned long long t0, t1; -struct perf_evsel *counter; +struct perf_evsel *counter, *first;int status =0 ;int child_ready_pipe[2 ], go_pipe[2 ];const bool forks = (argc >0 );
@@ -453,8 +459,10 @@ static int run_perf_stat(int argc __used, const char **argv)close (child_ready_pipe[0 ]); } + first = list_entry(evsel_list->entries.next, struct perf_evsel, node); +list_for_each_entry (counter, &evsel_list->entries, node) { -if (create_perf_stat_counter (counter) <0 ) { +if (create_perf_stat_counter (counter, first) <0 ) {if (errno ==EINVAL || errno ==ENOSYS || errno ==ENOENT ) {if (verbose) ui__warning("%s event is not supported by the kernel.\n",
tools/perf/builtin-test.c +3 -3
@@ -291,7 +291,7 @@ static int test__open_syscall_event(void) goto out_thread_map_delete; } -if (perf_evsel__open_per_thread (evsel, threads, false) <0 ) { +if (perf_evsel__open_per_thread (evsel, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
@@ -366,7 +366,7 @@ static int test__open_syscall_event_on_all_cpus(void) goto out_thread_map_delete; } -if (perf_evsel__open (evsel, cpus, threads, false) <0 ) { +if (perf_evsel__open (evsel, cpus, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
@@ -531,7 +531,7 @@ static int test__basic_mmap(void)perf_evlist__add (evlist, evsels[i]); -if (perf_evsel__open (evsels[i], cpus, threads, false) <0 ) { +if (perf_evsel__open (evsels[i], cpus, threads, false,NULL ) <0 ) {pr_debug ("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n" ,strerror (errno));
tools/perf/builtin-top.c +38 -16
127 lines not on this page · raw message
tools/perf/util/annotate.c +6 -3
@@ -310,9 +310,12 @@ fallback: } err = -ENOENT ; dso->annotate_warned =1 ; -pr_err ("Can't annotate %s: No vmlinux file%s was found in the " -"path.\nPlease use 'perf buildid-cache -av vmlinux' or " -"--vmlinux vmlinux.\n" , +pr_err ("Can't annotate %s:\n\n" +"No vmlinux file%s\nwas found in the path.\n\n" +"Please use:\n\n" +" perf buildid-cache -av vmlinux\n\n" +"or:\n\n" +" --vmlinux vmlinux" , sym->name, build_id_msg ?:"" ); goto out_free_filename; }
tools/perf/util/debug.c +4 -3
@@ -47,19 +47,20 @@ int dump_printf(const char *fmt, ...) }#ifdef NO_NEWT_SUPPORT -void ui__warning (const char *format, ...) +int ui__warning (const char *format, ...) {va_list args;va_start (args, format);vfprintf (stderr, format, args);va_end (args); +return 0 ; }#endif -void ui__warning_paranoid (void ) +int ui__error_paranoid (void ) { -ui__warning ("Permission error - are you root?\n" +return ui__error ("Permission error - are you root?\n" "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" " -1 - Not paranoid at all\n" " 0 - Disallow raw tracepoint access for unpriv\n"
tools/perf/util/debug.h +6 -11
@@ -19,23 +19,18 @@ static inline int ui_helpline__show_help(const char *format __used, va_list ap _return 0 ; } -static inline struct ui_progress *ui_progress__new (const char *title__used , -u64 total__used ) -{ -return (struct ui_progress *)1 ; -} - -static inline void ui_progress__update (struct ui_progress *self__used , -u64 curr__used ) {} +static inline void ui_progress__update (u64 curr__used ,u64 total__used , +const char *title__used ) {} -static inline void ui_progress__delete (struct ui_progress *self__used ) {} +#define ui__error(format, arg...) ui__warning(format, ##arg)#else extern char ui_helpline__last_msg[];int ui_helpline__show_help (const char *format,va_list ap);#include "ui/progress.h" +int ui__error (const char *format, ...) __attribute__((format (printf,1 ,2 )));#endif -void ui__warning (const char *format, ...) __attribute__((format (printf,1 ,2 ))); -void ui__warning_paranoid (void ); +int ui__warning (const char *format, ...) __attribute__((format (printf,1 ,2 ))); +int ui__error_paranoid (void );#endif /* __PERF_DEBUG_H */
tools/perf/util/evlist.c +30 -0
@@ -539,3 +539,33 @@ void perf_evlist__set_selected(struct perf_evlist *evlist, { evlist->selected = evsel; } + +int perf_evlist__open (struct perf_evlist *evlist,bool group) +{ +struct perf_evsel *evsel, *first; +int err, ncpus, nthreads; + + first = list_entry(evlist->entries.next, struct perf_evsel, node); + +list_for_each_entry (evsel, &evlist->entries, node) { +struct xyarray *group_fd =NULL ; + +if (group && evsel != first) + group_fd = first->fd; + + err =perf_evsel__open (evsel, evlist->cpus, evlist->threads, + group, group_fd); +if (err <0 ) + goto out_err; + } + +return 0 ; +out_err: + ncpus = evlist->cpus ? evlist->cpus->nr :1 ; + nthreads = evlist->threads ? evlist->threads->nr :1 ; + +list_for_each_entry_reverse (evsel, &evlist->entries, node) +perf_evsel__close (evsel, ncpus, nthreads); + +return err; +}
tools/perf/util/evlist.h +2 -0
@@ -50,6 +50,8 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);union perf_event *perf_evlist__mmap_read (struct perf_evlist *self,int idx); +int perf_evlist__open (struct perf_evlist *evlist,bool group); +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);
tools/perf/util/evsel.c +31 -12
100 lines not on this page · raw message
tools/perf/util/evsel.h +7 -3
@@ -82,11 +82,15 @@ void perf_evsel__free_id(struct perf_evsel *evsel);void perf_evsel__close_fd (struct perf_evsel *evsel,int ncpus,int nthreads);int perf_evsel__open_per_cpu (struct perf_evsel *evsel, -struct cpu_map *cpus,bool group); +struct cpu_map *cpus,bool group, +struct xyarray *group_fds);int perf_evsel__open_per_thread (struct perf_evsel *evsel, -struct thread_map *threads,bool group); +struct thread_map *threads,bool group, +struct xyarray *group_fds);int perf_evsel__open (struct perf_evsel *evsel,struct cpu_map *cpus, -struct thread_map *threads,bool group); +struct thread_map *threads,bool group, +struct xyarray *group_fds); +void perf_evsel__close (struct perf_evsel *evsel,int ncpus,int nthreads);#define perf_evsel__match (evsel, t, c) \ (evsel->attr.type == PERF_TYPE_##t && \
tools/perf/util/header.c +1 -1
@@ -1,5 +1,6 @@#define _FILE_OFFSET_BITS 64 +#include "util.h" #include <sys/types.h> #include <byteswap.h> #include <unistd.h>
@@ -11,7 +12,6 @@#include "evlist.h" #include "evsel.h" -#include "util.h" #include "header.h" #include "../perf.h" #include "trace-event.h"
tools/perf/util/hist.c +1 -2
@@ -365,7 +365,6 @@ static void __hists__collapse_resort(struct hists *hists, bool threaded) root =hists__get_rotate_entries_in (hists); next =rb_first (root); - hists->stats.total_period =0 ;while (next) { n = rb_entry(next, struct hist_entry, rb_node_in);
@@ -379,7 +378,6 @@ static void __hists__collapse_resort(struct hists *hists, bool threaded)* been set by, say, the hist_browser. */ hists__apply_filters (hists, n); -hists__inc_nr_entries (hists, n); } } }
@@ -442,6 +440,7 @@ static void __hists__output_resort(struct hists *hists, bool threaded) hists->entries =RB_ROOT ; hists->nr_entries =0 ; + hists->stats.total_period =0 ;hists__reset_col_len (hists);while (next) {
tools/perf/util/hist.h +1 -0
@@ -28,6 +28,7 @@ struct events_stats {u64 total_lost;u64 total_invalid_chains;u32 nr_events[PERF_RECORD_HEADER_MAX ]; +u32 nr_lost_warned;u32 nr_unknown_events;u32 nr_invalid_chains;u32 nr_unknown_id;
tools/perf/util/python.c +30 -1
@@ -623,7 +623,11 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel, cpus = ((struct pyrf_cpu_map *)pcpus)->cpus; evsel->attr.inherit = inherit; -if (perf_evsel__open (evsel, cpus, threads, group) <0 ) { +/* +* This will group just the fds for this single evsel, to group +* multiple events, use evlist.open(). +*/ +if (perf_evsel__open (evsel, cpus, threads, group,NULL ) <0 ) {PyErr_SetFromErrno (PyExc_OSError);return NULL ; }
@@ -814,6 +818,25 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,return Py_None; } +static PyObject *pyrf_evlist__open (struct pyrf_evlist *pevlist, +PyObject *args,PyObject *kwargs) +{ +struct perf_evlist *evlist = &pevlist->evlist; +int group =0 ; +static char *kwlist[] = {"group" ,NULL }; + +if (!PyArg_ParseTupleAndKeywords (args, kwargs,"|OOii" , kwlist, &group)) +return NULL ; + +if (perf_evlist__open (evlist, group) <0 ) { +PyErr_SetFromErrno (PyExc_OSError); +return NULL ; + } + +Py_INCREF (Py_None); +return Py_None; +} +static PyMethodDef pyrf_evlist__methods[] = { { .ml_name ="mmap" ,
@@ -822,6 +845,12 @@ static PyMethodDef pyrf_evlist__methods[] = { .ml_doc = PyDoc_STR("mmap the file descriptor table.") }, { + .ml_name = "open", + .ml_meth = (PyCFunction)pyrf_evlist__open, + .ml_flags = METH_VARARGS | METH_KEYWORDS, + .ml_doc =PyDoc_STR ("open the file descriptors." ) + }, + { .ml_name = "poll", .ml_meth = (PyCFunction)pyrf_evlist__poll, .ml_flags = METH_VARARGS | METH_KEYWORDS,
tools/perf/util/session.c +34 -12
109 lines not on this page · raw message
tools/perf/util/session.h +1 -0
@@ -23,6 +23,7 @@ struct ordered_samples {struct sample_queue *sample_buffer;struct sample_queue *last_sample;int sample_buffer_idx; +unsigned int nr_samples; };struct perf_session {
tools/perf/util/top.h +0 -1
@@ -19,7 +19,6 @@ struct perf_top {u64 kernel_samples, us_samples;u64 exact_samples;u64 guest_us_samples, guest_kernel_samples; -u64 total_lost_warned;int print_entries, count_filter, delay_secs;int freq;pid_t target_pid, target_tid;
tools/perf/util/trace-event-info.c +1 -1
@@ -80,7 +80,7 @@ static void die(const char *fmt, ...)int ret = errno;if (errno) -perror ("trace-cmd" ); +perror ("perf" );else ret =-1 ;
tools/perf/util/ui/browser.c +101 -50
195 lines not on this page · raw message
tools/perf/util/ui/browser.h +9 -0
@@ -43,6 +43,15 @@ void ui_browser__hide(struct ui_browser *self);int ui_browser__refresh (struct ui_browser *self);int ui_browser__run (struct ui_browser *browser,int delay_secs);void ui_browser__update_nr_entries (struct ui_browser *browser,u32 nr_entries); +void ui_browser__handle_resize (struct ui_browser *browser); + +int ui_browser__warning (struct ui_browser *browser,int timeout, +const char *format, ...); +int ui_browser__help_window (struct ui_browser *browser,const char *text); +bool ui_browser__dialog_yesno (struct ui_browser *browser,const char *text); + +void ui_browser__argv_seek (struct ui_browser *browser,off_t offset,int whence); +unsigned int ui_browser__argv_refresh (struct ui_browser *browser);void ui_browser__rb_tree_seek (struct ui_browser *self,off_t offset,int whence);unsigned int ui_browser__rb_tree_refresh (struct ui_browser *self);
tools/perf/util/ui/browsers/annotate.c +4 -10
@@ -1,6 +1,9 @@ +#include "../../util.h" #include "../browser.h" #include "../helpline.h" #include "../libslang.h" +#include "../ui.h" +#include "../util.h" #include "../../annotate.h" #include "../../hist.h" #include "../../sort.h"
@@ -8,15 +11,6 @@#include <pthread.h> #include <newt.h> -static void ui__error_window (const char *fmt, ...) -{ -va_list ap; - -va_start (ap, fmt); -newtWinMessagev ((char *)"Error" , (char *)"Ok" , (char *)fmt, ap); -va_end (ap); -} -struct annotate_browser {struct ui_browser b;struct rb_root entries;
@@ -400,7 +394,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,return -1 ;if (symbol__annotate (sym, map,sizeof (struct objdump_line_rb_node )) <0 ) { -ui__error_window (ui_helpline__last_msg); +ui__error ("%s" , ui_helpline__last_msg);return -1 ; }
tools/perf/util/ui/browsers/hists.c +59 -15
167 lines not on this page · raw message
tools/perf/util/ui/helpline.c +12 -4
@@ -1,20 +1,28 @@#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> -#include <newt.h> +#include <string.h> #include "../debug.h" #include "helpline.h" #include "ui.h" +#include "libslang.h" void ui_helpline__pop (void ) { -newtPopHelpLine (); } +char ui_helpline__current[512 ]; +void ui_helpline__push (const char *msg) { -newtPushHelpLine (msg); +const size_t sz =sizeof (ui_helpline__current); + +SLsmg_gotorc (SLtt_Screen_Rows -1 ,0 ); +SLsmg_set_color (0 ); +SLsmg_write_nstring ((char *)msg, SLtt_Screen_Cols); +SLsmg_refresh (); +strncpy (ui_helpline__current, msg, sz)[sz -1 ] ='\0' ; }void ui_helpline__vpush (const char *fmt,va_list ap)
@@ -63,7 +71,7 @@ int ui_helpline__show_help(const char *format, va_list ap)if (ui_helpline__last_msg[backlog -1 ] =='\n' ) {ui_helpline__puts (ui_helpline__last_msg); -newtRefresh (); +SLsmg_refresh (); backlog =0 ; }pthread_mutex_unlock (&ui__lock);
tools/perf/util/ui/helpline.h +2 -0
@@ -11,4 +11,6 @@ void ui_helpline__vpush(const char *fmt, va_list ap);void ui_helpline__fpush (const char *fmt, ...);void ui_helpline__puts (const char *msg); +extern char ui_helpline__current[]; +#endif /* _PERF_UI_HELPLINE_H_ */
tools/perf/util/ui/progress.c +17 -48
77 lines not on this page · raw message
tools/perf/util/ui/progress.h +2 -5
@@ -1,11 +1,8 @@#ifndef _PERF_UI_PROGRESS_H_#define _PERF_UI_PROGRESS_H_ 1 -struct ui_progress ; +#include <../types.h> -struct ui_progress *ui_progress__new (const char *title,u64 total); -void ui_progress__delete (struct ui_progress *self); - -void ui_progress__update (struct ui_progress *self,u64 curr); +void ui_progress__update (u64 curr,u64 total,const char *title);#endif
tools/perf/util/ui/setup.c +79 -4
99 lines not on this page · raw message
tools/perf/util/ui/ui.h +3 -0
@@ -2,7 +2,10 @@#define _PERF_UI_H_ 1#include <pthread.h> +#include <stdbool.h> extern pthread_mutex_t ui__lock; +void ui__refresh_dimensions (bool force); +#endif /* _PERF_UI_H_ */
tools/perf/util/ui/util.c +110 -72
229 lines not on this page · raw message
tools/perf/util/ui/util.h +6 -2
@@ -1,10 +1,14 @@#ifndef _PERF_UI_UTIL_H_#define _PERF_UI_UTIL_H_ 1 -#include <stdbool.h> +#include <stdarg.h> +int ui__getch (int delay_secs);int ui__popup_menu (int argc,char *const argv[]);int ui__help_window (const char *text); -bool ui__dialog_yesno (const char *msg); +int ui__dialog_yesno (const char *msg); +int ui__question_window (const char *title,const char *text, +const char *exit_msg,int delay_secs); +int __ui__warning (const char *title,const char *format,va_list args);#endif /* _PERF_UI_UTIL_H_ */
Quoted 4 lines · Ingo Molnar
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitperf-urgent-for-linus
I think you forgot to push. Or gave me the wrong branch name.
Linus
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Ingo Molnar
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitperf-urgent-for-linusI think you forgot to push. Or gave me the wrong branch name.
Oops, indeed, i forgot to push it properly. It's fixed now.
Thanks,
Ingo