Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1 | /* |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 2 | * builtin-top.c |
| 3 | * |
| 4 | * Builtin top command: Display a continuously updated profile of |
| 5 | * any workload, CPU or specific PID. |
| 6 | * |
| 7 | * Copyright (C) 2008, Red Hat Inc, Ingo Molnar <mingo@redhat.com> |
| 8 | * |
| 9 | * Improvements and fixes by: |
| 10 | * |
| 11 | * Arjan van de Ven <arjan@linux.intel.com> |
| 12 | * Yanmin Zhang <yanmin.zhang@intel.com> |
| 13 | * Wu Fengguang <fengguang.wu@intel.com> |
| 14 | * Mike Galbraith <efault@gmx.de> |
| 15 | * Paul Mackerras <paulus@samba.org> |
| 16 | * |
| 17 | * Released under the GPL v2. (and only v2, not any later version) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 18 | */ |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 19 | #include "builtin.h" |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 20 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 21 | #include "perf.h" |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 23 | #include "util/annotate.h" |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 24 | #include "util/cache.h" |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 25 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 26 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 27 | #include "util/evsel.h" |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 28 | #include "util/session.h" |
| 29 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 30 | #include "util/thread.h" |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 31 | #include "util/thread_map.h" |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 32 | #include "util/top.h" |
Ingo Molnar | 148be2c | 2009-04-27 08:02:14 +0200 | [diff] [blame] | 33 | #include "util/util.h" |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 34 | #include <linux/rbtree.h> |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 35 | #include "util/parse-options.h" |
| 36 | #include "util/parse-events.h" |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 37 | #include "util/cpumap.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 38 | #include "util/xyarray.h" |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 39 | |
Frederic Weisbecker | 8f28827a | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 40 | #include "util/debug.h" |
| 41 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 42 | #include <assert.h> |
| 43 | #include <fcntl.h> |
Ingo Molnar | 0e9b20b | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 44 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 45 | #include <stdio.h> |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 46 | #include <termios.h> |
| 47 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 48 | #include <inttypes.h> |
Ingo Molnar | 0e9b20b | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 49 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 50 | #include <errno.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 51 | #include <time.h> |
| 52 | #include <sched.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 53 | |
| 54 | #include <sys/syscall.h> |
| 55 | #include <sys/ioctl.h> |
| 56 | #include <sys/poll.h> |
| 57 | #include <sys/prctl.h> |
| 58 | #include <sys/wait.h> |
| 59 | #include <sys/uio.h> |
| 60 | #include <sys/mman.h> |
| 61 | |
| 62 | #include <linux/unistd.h> |
| 63 | #include <linux/types.h> |
| 64 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 65 | static struct perf_top top = { |
| 66 | .count_filter = 5, |
| 67 | .delay_secs = 2, |
| 68 | .display_weighted = -1, |
| 69 | .target_pid = -1, |
| 70 | .target_tid = -1, |
| 71 | .active_symbols = LIST_HEAD_INIT(top.active_symbols), |
| 72 | .active_symbols_lock = PTHREAD_MUTEX_INITIALIZER, |
Arnaldo Carvalho de Melo | 5807806 | 2011-03-01 10:43:03 -0300 | [diff] [blame] | 73 | .active_symbols_cond = PTHREAD_COND_INITIALIZER, |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 74 | .freq = 1000, /* 1 KHz */ |
| 75 | }; |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 76 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 77 | static bool system_wide = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 78 | |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 79 | static bool use_tui, use_stdio; |
| 80 | |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 81 | static int default_interval = 0; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 82 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 83 | static bool inherit = false; |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 84 | static int realtime_prio = 0; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 85 | static bool group = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 86 | static unsigned int page_size; |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 87 | static unsigned int mmap_pages = 128; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 88 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 89 | static bool dump_symtab = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 90 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 91 | static struct winsize winsize; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 92 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 93 | static const char *sym_filter = NULL; |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 94 | struct sym_entry *sym_filter_entry_sched = NULL; |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 95 | static int sym_pcnt_filter = 5; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 96 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 97 | /* |
| 98 | * Source functions |
| 99 | */ |
| 100 | |
Arnaldo Carvalho de Melo | 895f0ed | 2010-03-11 20:12:41 -0300 | [diff] [blame] | 101 | void get_term_dimensions(struct winsize *ws) |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 102 | { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 103 | char *s = getenv("LINES"); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 104 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 105 | if (s != NULL) { |
| 106 | ws->ws_row = atoi(s); |
| 107 | s = getenv("COLUMNS"); |
| 108 | if (s != NULL) { |
| 109 | ws->ws_col = atoi(s); |
| 110 | if (ws->ws_row && ws->ws_col) |
| 111 | return; |
| 112 | } |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 113 | } |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 114 | #ifdef TIOCGWINSZ |
| 115 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && |
| 116 | ws->ws_row && ws->ws_col) |
| 117 | return; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 118 | #endif |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 119 | ws->ws_row = 25; |
| 120 | ws->ws_col = 80; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 121 | } |
| 122 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 123 | static void update_print_entries(struct winsize *ws) |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 124 | { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 125 | top.print_entries = ws->ws_row; |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 126 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 127 | if (top.print_entries > 9) |
| 128 | top.print_entries -= 9; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void sig_winch_handler(int sig __used) |
| 132 | { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 133 | get_term_dimensions(&winsize); |
| 134 | update_print_entries(&winsize); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 135 | } |
| 136 | |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 137 | static int parse_source(struct sym_entry *syme) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 138 | { |
| 139 | struct symbol *sym; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 140 | struct annotation *notes; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 141 | struct map *map; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 142 | int err = -1; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 143 | |
| 144 | if (!syme) |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 145 | return -1; |
| 146 | |
| 147 | sym = sym_entry__symbol(syme); |
| 148 | map = syme->map; |
| 149 | |
| 150 | /* |
| 151 | * We can't annotate with just /proc/kallsyms |
| 152 | */ |
Arnaldo Carvalho de Melo | 878b439 | 2011-03-11 13:13:36 -0300 | [diff] [blame] | 153 | if (map->dso->symtab_type == SYMTAB__KALLSYMS) { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 154 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
| 155 | "path\n", sym->name); |
| 156 | sleep(1); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 157 | return -1; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 158 | } |
| 159 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 160 | notes = symbol__annotation(sym); |
| 161 | if (notes->src != NULL) { |
| 162 | pthread_mutex_lock(¬es->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 163 | goto out_assign; |
| 164 | } |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 165 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 166 | pthread_mutex_lock(¬es->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 167 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 168 | if (symbol__alloc_hist(sym, top.evlist->nr_entries) < 0) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 169 | pthread_mutex_unlock(¬es->lock); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 170 | pr_err("Not enough memory for annotating '%s' symbol!\n", |
| 171 | sym->name); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 172 | sleep(1); |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 173 | return err; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 174 | } |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 175 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 176 | err = symbol__annotate(sym, syme->map, 0); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 177 | if (err == 0) { |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 178 | out_assign: |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 179 | top.sym_filter_entry = syme; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 180 | } |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 181 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 182 | pthread_mutex_unlock(¬es->lock); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 183 | return err; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void __zero_source_counters(struct sym_entry *syme) |
| 187 | { |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 188 | struct symbol *sym = sym_entry__symbol(syme); |
| 189 | symbol__annotate_zero_histograms(sym); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void record_precise_ip(struct sym_entry *syme, int counter, u64 ip) |
| 193 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 194 | struct annotation *notes; |
| 195 | struct symbol *sym; |
| 196 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 197 | if (syme != top.sym_filter_entry) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 198 | return; |
| 199 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 200 | sym = sym_entry__symbol(syme); |
| 201 | notes = symbol__annotation(sym); |
| 202 | |
| 203 | if (pthread_mutex_trylock(¬es->lock)) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 204 | return; |
| 205 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 206 | ip = syme->map->map_ip(syme->map, ip); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 207 | symbol__inc_addr_samples(sym, syme->map, counter, ip); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 208 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 209 | pthread_mutex_unlock(¬es->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 212 | static void show_details(struct sym_entry *syme) |
| 213 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 214 | struct annotation *notes; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 215 | struct symbol *symbol; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 216 | int more; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 217 | |
| 218 | if (!syme) |
| 219 | return; |
| 220 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 221 | symbol = sym_entry__symbol(syme); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 222 | notes = symbol__annotation(symbol); |
| 223 | |
| 224 | pthread_mutex_lock(¬es->lock); |
| 225 | |
| 226 | if (notes->src == NULL) |
| 227 | goto out_unlock; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 228 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 229 | printf("Showing %s for %s\n", event_name(top.sym_evsel), symbol->name); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 230 | printf(" Events Pcnt (>=%d%%)\n", sym_pcnt_filter); |
| 231 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 232 | more = symbol__annotate_printf(symbol, syme->map, top.sym_evsel->idx, |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 233 | 0, sym_pcnt_filter, top.print_entries, 4); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 234 | if (top.zero) |
| 235 | symbol__annotate_zero_histogram(symbol, top.sym_evsel->idx); |
| 236 | else |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 237 | symbol__annotate_decay_histogram(symbol, top.sym_evsel->idx); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 238 | if (more != 0) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 239 | printf("%d lines not displayed, maybe increase display entries [e]\n", more); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 240 | out_unlock: |
| 241 | pthread_mutex_unlock(¬es->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 242 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 243 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 244 | static const char CONSOLE_CLEAR[] = "[H[2J"; |
| 245 | |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 246 | static void __list_insert_active_sym(struct sym_entry *syme) |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 247 | { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 248 | list_add(&syme->node, &top.active_symbols); |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 249 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 250 | |
Arnaldo Carvalho de Melo | 93fc64f | 2011-01-29 12:08:00 -0200 | [diff] [blame] | 251 | static void print_sym_table(struct perf_session *session) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 252 | { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 253 | char bf[160]; |
| 254 | int printed = 0; |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 255 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 256 | struct sym_entry *syme; |
| 257 | struct rb_root tmp = RB_ROOT; |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 258 | const int win_width = winsize.ws_col - 1; |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 259 | int sym_width, dso_width, dso_short_width; |
| 260 | float sum_ksamples = perf_top__decay_samples(&top, &tmp); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 261 | |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 262 | puts(CONSOLE_CLEAR); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 263 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 264 | perf_top__header_snprintf(&top, bf, sizeof(bf)); |
| 265 | printf("%s\n", bf); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 266 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 267 | perf_top__reset_sample_counters(&top); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 268 | |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 269 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 270 | |
Arnaldo Carvalho de Melo | 93fc64f | 2011-01-29 12:08:00 -0200 | [diff] [blame] | 271 | if (session->hists.stats.total_lost != 0) { |
| 272 | color_fprintf(stdout, PERF_COLOR_RED, "WARNING:"); |
| 273 | printf(" LOST %" PRIu64 " events, Check IO/CPU overload\n", |
| 274 | session->hists.stats.total_lost); |
| 275 | } |
| 276 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 277 | if (top.sym_filter_entry) { |
| 278 | show_details(top.sym_filter_entry); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 279 | return; |
| 280 | } |
| 281 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 282 | perf_top__find_widths(&top, &tmp, &dso_width, &dso_short_width, |
| 283 | &sym_width); |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 284 | |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 285 | if (sym_width + dso_width > winsize.ws_col - 29) { |
| 286 | dso_width = dso_short_width; |
| 287 | if (sym_width + dso_width > winsize.ws_col - 29) |
| 288 | sym_width = winsize.ws_col - dso_width - 29; |
| 289 | } |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 290 | putchar('\n'); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 291 | if (top.evlist->nr_entries == 1) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 292 | printf(" samples pcnt"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 293 | else |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 294 | printf(" weight samples pcnt"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 295 | |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 296 | if (verbose) |
| 297 | printf(" RIP "); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 298 | printf(" %-*.*s DSO\n", sym_width, sym_width, "function"); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 299 | printf(" %s _______ _____", |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 300 | top.evlist->nr_entries == 1 ? " " : "______"); |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 301 | if (verbose) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 302 | printf(" ________________"); |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 303 | printf(" %-*.*s", sym_width, sym_width, graph_line); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 304 | printf(" %-*.*s", dso_width, dso_width, graph_line); |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 305 | puts("\n"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 306 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 307 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 308 | struct symbol *sym; |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 309 | double pcnt; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 310 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 311 | syme = rb_entry(nd, struct sym_entry, rb_node); |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 312 | sym = sym_entry__symbol(syme); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 313 | if (++printed > top.print_entries || |
| 314 | (int)syme->snap_count < top.count_filter) |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 315 | continue; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 316 | |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 317 | pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) / |
| 318 | sum_ksamples)); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 319 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 320 | if (top.evlist->nr_entries == 1 || !top.display_weighted) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 321 | printf("%20.2f ", syme->weight); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 322 | else |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 323 | printf("%9.1f %10ld ", syme->weight, syme->snap_count); |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 324 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 325 | percent_color_fprintf(stdout, "%4.1f%%", pcnt); |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 326 | if (verbose) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 327 | printf(" %016" PRIx64, sym->start); |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 328 | printf(" %-*.*s", sym_width, sym_width, sym->name); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 329 | printf(" %-*.*s\n", dso_width, dso_width, |
| 330 | dso_width >= syme->map->dso->long_name_len ? |
| 331 | syme->map->dso->long_name : |
| 332 | syme->map->dso->short_name); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 333 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 336 | static void prompt_integer(int *target, const char *msg) |
| 337 | { |
| 338 | char *buf = malloc(0), *p; |
| 339 | size_t dummy = 0; |
| 340 | int tmp; |
| 341 | |
| 342 | fprintf(stdout, "\n%s: ", msg); |
| 343 | if (getline(&buf, &dummy, stdin) < 0) |
| 344 | return; |
| 345 | |
| 346 | p = strchr(buf, '\n'); |
| 347 | if (p) |
| 348 | *p = 0; |
| 349 | |
| 350 | p = buf; |
| 351 | while(*p) { |
| 352 | if (!isdigit(*p)) |
| 353 | goto out_free; |
| 354 | p++; |
| 355 | } |
| 356 | tmp = strtoul(buf, NULL, 10); |
| 357 | *target = tmp; |
| 358 | out_free: |
| 359 | free(buf); |
| 360 | } |
| 361 | |
| 362 | static void prompt_percent(int *target, const char *msg) |
| 363 | { |
| 364 | int tmp = 0; |
| 365 | |
| 366 | prompt_integer(&tmp, msg); |
| 367 | if (tmp >= 0 && tmp <= 100) |
| 368 | *target = tmp; |
| 369 | } |
| 370 | |
| 371 | static void prompt_symbol(struct sym_entry **target, const char *msg) |
| 372 | { |
| 373 | char *buf = malloc(0), *p; |
| 374 | struct sym_entry *syme = *target, *n, *found = NULL; |
| 375 | size_t dummy = 0; |
| 376 | |
| 377 | /* zero counters of active symbol */ |
| 378 | if (syme) { |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 379 | __zero_source_counters(syme); |
| 380 | *target = NULL; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | fprintf(stdout, "\n%s: ", msg); |
| 384 | if (getline(&buf, &dummy, stdin) < 0) |
| 385 | goto out_free; |
| 386 | |
| 387 | p = strchr(buf, '\n'); |
| 388 | if (p) |
| 389 | *p = 0; |
| 390 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 391 | pthread_mutex_lock(&top.active_symbols_lock); |
| 392 | syme = list_entry(top.active_symbols.next, struct sym_entry, node); |
| 393 | pthread_mutex_unlock(&top.active_symbols_lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 394 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 395 | list_for_each_entry_safe_from(syme, n, &top.active_symbols, node) { |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 396 | struct symbol *sym = sym_entry__symbol(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 397 | |
| 398 | if (!strcmp(buf, sym->name)) { |
| 399 | found = syme; |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | if (!found) { |
Kirill Smelkov | 66aeb6d | 2010-01-13 13:22:19 -0200 | [diff] [blame] | 405 | fprintf(stderr, "Sorry, %s is not active.\n", buf); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 406 | sleep(1); |
| 407 | return; |
| 408 | } else |
| 409 | parse_source(found); |
| 410 | |
| 411 | out_free: |
| 412 | free(buf); |
| 413 | } |
| 414 | |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 415 | static void print_mapped_keys(void) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 416 | { |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 417 | char *name = NULL; |
| 418 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 419 | if (top.sym_filter_entry) { |
| 420 | struct symbol *sym = sym_entry__symbol(top.sym_filter_entry); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 421 | name = sym->name; |
| 422 | } |
| 423 | |
| 424 | fprintf(stdout, "\nMapped keys:\n"); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 425 | fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", top.delay_secs); |
| 426 | fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", top.print_entries); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 427 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 428 | if (top.evlist->nr_entries > 1) |
| 429 | fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(top.sym_evsel)); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 430 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 431 | fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", top.count_filter); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 432 | |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 433 | fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter); |
| 434 | fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL"); |
| 435 | fprintf(stdout, "\t[S] stop annotation.\n"); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 436 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 437 | if (top.evlist->nr_entries > 1) |
| 438 | fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", top.display_weighted ? 1 : 0); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 439 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 440 | fprintf(stdout, |
Kirill Smelkov | 1a72cfa | 2010-02-12 19:20:59 +0300 | [diff] [blame] | 441 | "\t[K] hide kernel_symbols symbols. \t(%s)\n", |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 442 | top.hide_kernel_symbols ? "yes" : "no"); |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 443 | fprintf(stdout, |
| 444 | "\t[U] hide user symbols. \t(%s)\n", |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 445 | top.hide_user_symbols ? "yes" : "no"); |
| 446 | fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", top.zero ? 1 : 0); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 447 | fprintf(stdout, "\t[qQ] quit.\n"); |
| 448 | } |
| 449 | |
| 450 | static int key_mapped(int c) |
| 451 | { |
| 452 | switch (c) { |
| 453 | case 'd': |
| 454 | case 'e': |
| 455 | case 'f': |
| 456 | case 'z': |
| 457 | case 'q': |
| 458 | case 'Q': |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 459 | case 'K': |
| 460 | case 'U': |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 461 | case 'F': |
| 462 | case 's': |
| 463 | case 'S': |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 464 | return 1; |
| 465 | case 'E': |
| 466 | case 'w': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 467 | return top.evlist->nr_entries > 1 ? 1 : 0; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 468 | default: |
| 469 | break; |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | return 0; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 475 | static void handle_keypress(struct perf_session *session, int c) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 476 | { |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 477 | if (!key_mapped(c)) { |
| 478 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
| 479 | struct termios tc, save; |
| 480 | |
| 481 | print_mapped_keys(); |
| 482 | fprintf(stdout, "\nEnter selection, or unmapped key to continue: "); |
| 483 | fflush(stdout); |
| 484 | |
| 485 | tcgetattr(0, &save); |
| 486 | tc = save; |
| 487 | tc.c_lflag &= ~(ICANON | ECHO); |
| 488 | tc.c_cc[VMIN] = 0; |
| 489 | tc.c_cc[VTIME] = 0; |
| 490 | tcsetattr(0, TCSANOW, &tc); |
| 491 | |
| 492 | poll(&stdin_poll, 1, -1); |
| 493 | c = getc(stdin); |
| 494 | |
| 495 | tcsetattr(0, TCSAFLUSH, &save); |
| 496 | if (!key_mapped(c)) |
| 497 | return; |
| 498 | } |
| 499 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 500 | switch (c) { |
| 501 | case 'd': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 502 | prompt_integer(&top.delay_secs, "Enter display delay"); |
| 503 | if (top.delay_secs < 1) |
| 504 | top.delay_secs = 1; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 505 | break; |
| 506 | case 'e': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 507 | prompt_integer(&top.print_entries, "Enter display entries (lines)"); |
| 508 | if (top.print_entries == 0) { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 509 | sig_winch_handler(SIGWINCH); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 510 | signal(SIGWINCH, sig_winch_handler); |
| 511 | } else |
| 512 | signal(SIGWINCH, SIG_DFL); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 513 | break; |
| 514 | case 'E': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 515 | if (top.evlist->nr_entries > 1) { |
Akihiro Nagai | ce2d17c | 2011-03-23 16:29:39 +0900 | [diff] [blame] | 516 | /* Select 0 as the default event: */ |
| 517 | int counter = 0; |
| 518 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 519 | fprintf(stderr, "\nAvailable events:"); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 520 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 521 | list_for_each_entry(top.sym_evsel, &top.evlist->entries, node) |
| 522 | fprintf(stderr, "\n\t%d %s", top.sym_evsel->idx, event_name(top.sym_evsel)); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 523 | |
Arnaldo Carvalho de Melo | ec52d97 | 2011-03-11 10:11:48 -0300 | [diff] [blame] | 524 | prompt_integer(&counter, "Enter details event counter"); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 525 | |
Arnaldo Carvalho de Melo | ec52d97 | 2011-03-11 10:11:48 -0300 | [diff] [blame] | 526 | if (counter >= top.evlist->nr_entries) { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 527 | top.sym_evsel = list_entry(top.evlist->entries.next, struct perf_evsel, node); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 528 | fprintf(stderr, "Sorry, no such event, using %s.\n", event_name(top.sym_evsel)); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 529 | sleep(1); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 530 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 531 | } |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 532 | list_for_each_entry(top.sym_evsel, &top.evlist->entries, node) |
Arnaldo Carvalho de Melo | ec52d97 | 2011-03-11 10:11:48 -0300 | [diff] [blame] | 533 | if (top.sym_evsel->idx == counter) |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 534 | break; |
Arnaldo Carvalho de Melo | ec52d97 | 2011-03-11 10:11:48 -0300 | [diff] [blame] | 535 | } else |
| 536 | top.sym_evsel = list_entry(top.evlist->entries.next, struct perf_evsel, node); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 537 | break; |
| 538 | case 'f': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 539 | prompt_integer(&top.count_filter, "Enter display event count filter"); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 540 | break; |
| 541 | case 'F': |
| 542 | prompt_percent(&sym_pcnt_filter, "Enter details display event filter (percent)"); |
| 543 | break; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 544 | case 'K': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 545 | top.hide_kernel_symbols = !top.hide_kernel_symbols; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 546 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 547 | case 'q': |
| 548 | case 'Q': |
| 549 | printf("exiting.\n"); |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 550 | if (dump_symtab) |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 551 | perf_session__fprintf_dsos(session, stderr); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 552 | exit(0); |
| 553 | case 's': |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 554 | prompt_symbol(&top.sym_filter_entry, "Enter details symbol"); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 555 | break; |
| 556 | case 'S': |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 557 | if (!top.sym_filter_entry) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 558 | break; |
| 559 | else { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 560 | struct sym_entry *syme = top.sym_filter_entry; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 561 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 562 | top.sym_filter_entry = NULL; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 563 | __zero_source_counters(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 564 | } |
| 565 | break; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 566 | case 'U': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 567 | top.hide_user_symbols = !top.hide_user_symbols; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 568 | break; |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 569 | case 'w': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 570 | top.display_weighted = ~top.display_weighted; |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 571 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 572 | case 'z': |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 573 | top.zero = !top.zero; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 574 | break; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 575 | default: |
| 576 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 580 | static void *display_thread_tui(void *arg __used) |
| 581 | { |
Arnaldo Carvalho de Melo | 5807806 | 2011-03-01 10:43:03 -0300 | [diff] [blame] | 582 | int err = 0; |
| 583 | pthread_mutex_lock(&top.active_symbols_lock); |
| 584 | while (list_empty(&top.active_symbols)) { |
| 585 | err = pthread_cond_wait(&top.active_symbols_cond, |
| 586 | &top.active_symbols_lock); |
| 587 | if (err) |
| 588 | break; |
| 589 | } |
| 590 | pthread_mutex_unlock(&top.active_symbols_lock); |
| 591 | if (!err) |
| 592 | perf_top__tui_browser(&top); |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 593 | exit_browser(0); |
| 594 | exit(0); |
| 595 | return NULL; |
| 596 | } |
| 597 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 598 | static void *display_thread(void *arg __used) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 599 | { |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 600 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 601 | struct termios tc, save; |
| 602 | int delay_msecs, c; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 603 | struct perf_session *session = (struct perf_session *) arg; |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 604 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 605 | tcgetattr(0, &save); |
| 606 | tc = save; |
| 607 | tc.c_lflag &= ~(ICANON | ECHO); |
| 608 | tc.c_cc[VMIN] = 0; |
| 609 | tc.c_cc[VTIME] = 0; |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 610 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 611 | repeat: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 612 | delay_msecs = top.delay_secs * 1000; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 613 | tcsetattr(0, TCSANOW, &tc); |
| 614 | /* trash return*/ |
| 615 | getc(stdin); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 616 | |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 617 | do { |
Arnaldo Carvalho de Melo | 93fc64f | 2011-01-29 12:08:00 -0200 | [diff] [blame] | 618 | print_sym_table(session); |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 619 | } while (!poll(&stdin_poll, 1, delay_msecs) == 1); |
| 620 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 621 | c = getc(stdin); |
| 622 | tcsetattr(0, TCSAFLUSH, &save); |
| 623 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 624 | handle_keypress(session, c); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 625 | goto repeat; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 626 | |
| 627 | return NULL; |
| 628 | } |
| 629 | |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 630 | /* Tag samples to be skipped. */ |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 631 | static const char *skip_symbols[] = { |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 632 | "default_idle", |
Arnaldo Carvalho de Melo | b0e8572 | 2011-01-16 17:39:15 -0200 | [diff] [blame] | 633 | "native_safe_halt", |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 634 | "cpu_idle", |
| 635 | "enter_idle", |
| 636 | "exit_idle", |
| 637 | "mwait_idle", |
Arnaldo Carvalho de Melo | 59b9005 | 2009-07-26 19:06:19 -0300 | [diff] [blame] | 638 | "mwait_idle_with_hints", |
Arnaldo Carvalho de Melo | 8357275 | 2009-09-25 15:02:39 -0700 | [diff] [blame] | 639 | "poll_idle", |
Anton Blanchard | 3a3393e | 2009-07-01 09:00:47 +1000 | [diff] [blame] | 640 | "ppc64_runlatch_off", |
| 641 | "pseries_dedicated_idle_sleep", |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 642 | NULL |
| 643 | }; |
| 644 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 645 | static int symbol_filter(struct map *map, struct symbol *sym) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 646 | { |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 647 | struct sym_entry *syme; |
| 648 | const char *name = sym->name; |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 649 | int i; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 650 | |
Anton Blanchard | 3a3393e | 2009-07-01 09:00:47 +1000 | [diff] [blame] | 651 | /* |
| 652 | * ppc64 uses function descriptors and appends a '.' to the |
| 653 | * start of every instruction address. Remove it. |
| 654 | */ |
| 655 | if (name[0] == '.') |
| 656 | name++; |
| 657 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 658 | if (!strcmp(name, "_text") || |
| 659 | !strcmp(name, "_etext") || |
| 660 | !strcmp(name, "_sinittext") || |
| 661 | !strncmp("init_module", name, 11) || |
| 662 | !strncmp("cleanup_module", name, 14) || |
| 663 | strstr(name, "_text_start") || |
| 664 | strstr(name, "_text_end")) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 665 | return 1; |
| 666 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 667 | syme = symbol__priv(sym); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 668 | syme->map = map; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 669 | symbol__annotate_init(map, sym); |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 670 | |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 671 | if (!top.sym_filter_entry && sym_filter && !strcmp(name, sym_filter)) { |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 672 | /* schedule initial sym_filter_entry setup */ |
| 673 | sym_filter_entry_sched = syme; |
| 674 | sym_filter = NULL; |
| 675 | } |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 676 | |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 677 | for (i = 0; skip_symbols[i]; i++) { |
| 678 | if (!strcmp(skip_symbols[i], name)) { |
Arnaldo Carvalho de Melo | 171b3be | 2011-03-11 13:36:01 -0300 | [diff] [blame] | 679 | sym->ignore = true; |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 680 | break; |
| 681 | } |
| 682 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 683 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 687 | static void perf_event__process_sample(const union perf_event *event, |
| 688 | struct perf_sample *sample, |
| 689 | struct perf_session *session) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 690 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 691 | u64 ip = event->ip.ip; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 692 | struct sym_entry *syme; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 693 | struct addr_location al; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 694 | struct machine *machine; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 695 | u8 origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 696 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 697 | ++top.samples; |
Arnaldo Carvalho de Melo | 24bfef0 | 2010-01-21 13:04:43 -0200 | [diff] [blame] | 698 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 699 | switch (origin) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 700 | case PERF_RECORD_MISC_USER: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 701 | ++top.us_samples; |
| 702 | if (top.hide_user_symbols) |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 703 | return; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 704 | machine = perf_session__find_host_machine(session); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 705 | break; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 706 | case PERF_RECORD_MISC_KERNEL: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 707 | ++top.kernel_samples; |
| 708 | if (top.hide_kernel_symbols) |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 709 | return; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 710 | machine = perf_session__find_host_machine(session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 711 | break; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 712 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 713 | ++top.guest_kernel_samples; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 714 | machine = perf_session__find_machine(session, event->ip.pid); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 715 | break; |
| 716 | case PERF_RECORD_MISC_GUEST_USER: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 717 | ++top.guest_us_samples; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 718 | /* |
| 719 | * TODO: we don't process guest user from host side |
| 720 | * except simple counting. |
| 721 | */ |
| 722 | return; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 723 | default: |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 727 | if (!machine && perf_guest) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 728 | pr_err("Can't find guest [%d]'s kernel information\n", |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 729 | event->ip.pid); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 730 | return; |
| 731 | } |
| 732 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 733 | if (event->header.misc & PERF_RECORD_MISC_EXACT_IP) |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 734 | top.exact_samples++; |
Peter Zijlstra | 1676b8a | 2010-03-04 14:19:36 +0100 | [diff] [blame] | 735 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 736 | if (perf_event__preprocess_sample(event, session, &al, sample, |
| 737 | symbol_filter) < 0 || |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 738 | al.filtered) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 739 | return; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 740 | |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 741 | if (al.sym == NULL) { |
| 742 | /* |
| 743 | * As we do lazy loading of symtabs we only will know if the |
| 744 | * specified vmlinux file is invalid when we actually have a |
| 745 | * hit in kernel space and then try to load it. So if we get |
| 746 | * here and there are _no_ symbols in the DSO backing the |
| 747 | * kernel map, bail out. |
| 748 | * |
| 749 | * We may never get here, for instance, if we use -K/ |
| 750 | * --hide-kernel-symbols, even if the user specifies an |
| 751 | * invalid --vmlinux ;-) |
| 752 | */ |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 753 | if (al.map == machine->vmlinux_maps[MAP__FUNCTION] && |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 754 | RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) { |
Arnaldo Carvalho de Melo | 374cfe5 | 2011-03-01 10:27:27 -0300 | [diff] [blame] | 755 | ui__warning("The %s file can't be used\n", |
| 756 | symbol_conf.vmlinux_name); |
| 757 | exit_browser(0); |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 758 | exit(1); |
| 759 | } |
| 760 | |
| 761 | return; |
| 762 | } |
| 763 | |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 764 | /* let's see, whether we need to install initial sym_filter_entry */ |
| 765 | if (sym_filter_entry_sched) { |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 766 | top.sym_filter_entry = sym_filter_entry_sched; |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 767 | sym_filter_entry_sched = NULL; |
Arnaldo Carvalho de Melo | c97cf42 | 2011-02-22 12:02:07 -0300 | [diff] [blame] | 768 | if (parse_source(top.sym_filter_entry) < 0) { |
| 769 | struct symbol *sym = sym_entry__symbol(top.sym_filter_entry); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 770 | |
| 771 | pr_err("Can't annotate %s", sym->name); |
Arnaldo Carvalho de Melo | 878b439 | 2011-03-11 13:13:36 -0300 | [diff] [blame] | 772 | if (top.sym_filter_entry->map->dso->symtab_type == SYMTAB__KALLSYMS) { |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 773 | pr_err(": No vmlinux file was found in the path:\n"); |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 774 | machine__fprintf_vmlinux_path(machine, stderr); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 775 | } else |
| 776 | pr_err(".\n"); |
| 777 | exit(1); |
| 778 | } |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 779 | } |
| 780 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 781 | syme = symbol__priv(al.sym); |
Arnaldo Carvalho de Melo | 171b3be | 2011-03-11 13:36:01 -0300 | [diff] [blame] | 782 | if (!al.sym->ignore) { |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 783 | struct perf_evsel *evsel; |
| 784 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 785 | evsel = perf_evlist__id2evsel(top.evlist, sample->id); |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 786 | assert(evsel != NULL); |
| 787 | syme->count[evsel->idx]++; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 788 | record_precise_ip(syme, evsel->idx, ip); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 789 | pthread_mutex_lock(&top.active_symbols_lock); |
Arnaldo Carvalho de Melo | 5807806 | 2011-03-01 10:43:03 -0300 | [diff] [blame] | 790 | if (list_empty(&syme->node) || !syme->node.next) { |
| 791 | static bool first = true; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 792 | __list_insert_active_sym(syme); |
Arnaldo Carvalho de Melo | 5807806 | 2011-03-01 10:43:03 -0300 | [diff] [blame] | 793 | if (first) { |
| 794 | pthread_cond_broadcast(&top.active_symbols_cond); |
| 795 | first = false; |
| 796 | } |
| 797 | } |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 798 | pthread_mutex_unlock(&top.active_symbols_lock); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
Arnaldo Carvalho de Melo | aece948 | 2011-05-15 09:39:00 -0300 | [diff] [blame] | 802 | static void perf_session__mmap_read_idx(struct perf_session *self, int idx) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 803 | { |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 804 | struct perf_sample sample; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 805 | union perf_event *event; |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 806 | int ret; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 807 | |
Arnaldo Carvalho de Melo | aece948 | 2011-05-15 09:39:00 -0300 | [diff] [blame] | 808 | while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) { |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 809 | ret = perf_session__parse_sample(self, event, &sample); |
| 810 | if (ret) { |
| 811 | pr_err("Can't parse sample, err = %d\n", ret); |
| 812 | continue; |
| 813 | } |
Arnaldo Carvalho de Melo | 04391de | 2011-01-15 10:40:59 -0200 | [diff] [blame] | 814 | |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 815 | if (event->header.type == PERF_RECORD_SAMPLE) |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 816 | perf_event__process_sample(event, &sample, self); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 817 | else |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 818 | perf_event__process(event, &sample, self); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 819 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 820 | } |
| 821 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 822 | static void perf_session__mmap_read(struct perf_session *self) |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 823 | { |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 824 | int i; |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 825 | |
Arnaldo Carvalho de Melo | aece948 | 2011-05-15 09:39:00 -0300 | [diff] [blame] | 826 | for (i = 0; i < top.evlist->nr_mmaps; i++) |
| 827 | perf_session__mmap_read_idx(self, i); |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 828 | } |
| 829 | |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 830 | static void start_counters(struct perf_evlist *evlist) |
| 831 | { |
| 832 | struct perf_evsel *counter; |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 833 | |
| 834 | list_for_each_entry(counter, &evlist->entries, node) { |
| 835 | struct perf_event_attr *attr = &counter->attr; |
| 836 | |
| 837 | attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; |
| 838 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 839 | if (top.freq) { |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 840 | attr->sample_type |= PERF_SAMPLE_PERIOD; |
| 841 | attr->freq = 1; |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 842 | attr->sample_freq = top.freq; |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 843 | } |
| 844 | |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 845 | if (evlist->nr_entries > 1) { |
| 846 | attr->sample_type |= PERF_SAMPLE_ID; |
| 847 | attr->read_format |= PERF_FORMAT_ID; |
| 848 | } |
| 849 | |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 850 | attr->mmap = 1; |
Arnaldo Carvalho de Melo | 5d2cd90 | 2011-04-14 11:20:14 -0300 | [diff] [blame] | 851 | attr->inherit = inherit; |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 852 | try_again: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 853 | if (perf_evsel__open(counter, top.evlist->cpus, |
Arnaldo Carvalho de Melo | 5d2cd90 | 2011-04-14 11:20:14 -0300 | [diff] [blame] | 854 | top.evlist->threads, group) < 0) { |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 855 | int err = errno; |
| 856 | |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 857 | if (err == EPERM || err == EACCES) { |
| 858 | ui__warning_paranoid(); |
| 859 | goto out_err; |
| 860 | } |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 861 | /* |
| 862 | * If it's cycles then fall back to hrtimer |
| 863 | * based cpu-clock-tick sw counter, which |
| 864 | * is always available even if no PMU support: |
| 865 | */ |
| 866 | if (attr->type == PERF_TYPE_HARDWARE && |
| 867 | attr->config == PERF_COUNT_HW_CPU_CYCLES) { |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 868 | if (verbose) |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 869 | ui__warning("Cycles event not supported,\n" |
| 870 | "trying to fall back to cpu-clock-ticks\n"); |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 871 | |
| 872 | attr->type = PERF_TYPE_SOFTWARE; |
| 873 | attr->config = PERF_COUNT_SW_CPU_CLOCK; |
| 874 | goto try_again; |
| 875 | } |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 876 | |
David Ahern | ca6a425 | 2011-03-25 13:11:11 -0600 | [diff] [blame] | 877 | if (err == ENOENT) { |
| 878 | ui__warning("The %s event is not supported.\n", |
| 879 | event_name(counter)); |
| 880 | goto out_err; |
| 881 | } |
| 882 | |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 883 | ui__warning("The sys_perf_event_open() syscall " |
| 884 | "returned with %d (%s). /bin/dmesg " |
| 885 | "may provide additional information.\n" |
| 886 | "No CONFIG_PERF_EVENTS=y kernel support " |
| 887 | "configured?\n", err, strerror(err)); |
| 888 | goto out_err; |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 889 | } |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 890 | } |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 891 | |
Arnaldo Carvalho de Melo | c286c41 | 2011-03-28 09:50:11 -0300 | [diff] [blame] | 892 | if (perf_evlist__mmap(evlist, mmap_pages, false) < 0) { |
| 893 | ui__warning("Failed to mmap with %d (%s)\n", |
| 894 | errno, strerror(errno)); |
| 895 | goto out_err; |
| 896 | } |
| 897 | |
| 898 | return; |
| 899 | |
| 900 | out_err: |
| 901 | exit_browser(0); |
| 902 | exit(0); |
Arnaldo Carvalho de Melo | 72cb701 | 2011-01-12 10:52:47 -0200 | [diff] [blame] | 903 | } |
| 904 | |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 905 | static int __cmd_top(void) |
| 906 | { |
| 907 | pthread_t thread; |
Kyle McMartin | fb7d0b3 | 2011-01-24 11:13:04 -0500 | [diff] [blame] | 908 | int ret __used; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 909 | /* |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 910 | * FIXME: perf_session__new should allow passing a O_MMAP, so that all this |
| 911 | * mmap reading, etc is encapsulated in it. Use O_WRONLY for now. |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 912 | */ |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 913 | struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false, NULL); |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 914 | if (session == NULL) |
| 915 | return -ENOMEM; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 916 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 917 | if (top.target_tid != -1) |
Arnaldo Carvalho de Melo | 7c940c1 | 2011-02-11 11:45:54 -0200 | [diff] [blame] | 918 | perf_event__synthesize_thread_map(top.evlist->threads, |
| 919 | perf_event__process, session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 920 | else |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 921 | perf_event__synthesize_threads(perf_event__process, session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 922 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 923 | start_counters(top.evlist); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 924 | session->evlist = top.evlist; |
| 925 | perf_session__update_sample_type(session); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 926 | |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 927 | /* Wait for a minimal set of events before starting the snapshot */ |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 928 | poll(top.evlist->pollfd, top.evlist->nr_fds, 100); |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 929 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 930 | perf_session__mmap_read(session); |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 931 | |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 932 | if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui : |
| 933 | display_thread), session)) { |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 934 | printf("Could not create display thread.\n"); |
| 935 | exit(-1); |
| 936 | } |
| 937 | |
| 938 | if (realtime_prio) { |
| 939 | struct sched_param param; |
| 940 | |
| 941 | param.sched_priority = realtime_prio; |
| 942 | if (sched_setscheduler(0, SCHED_FIFO, ¶m)) { |
| 943 | printf("Could not set realtime priority.\n"); |
| 944 | exit(-1); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | while (1) { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 949 | u64 hits = top.samples; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 950 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 951 | perf_session__mmap_read(session); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 952 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 953 | if (hits == top.samples) |
| 954 | ret = poll(top.evlist->pollfd, top.evlist->nr_fds, 100); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | return 0; |
| 958 | } |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 959 | |
| 960 | static const char * const top_usage[] = { |
| 961 | "perf top [<options>]", |
| 962 | NULL |
| 963 | }; |
| 964 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 965 | static const struct option options[] = { |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 966 | OPT_CALLBACK('e', "event", &top.evlist, "event", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 967 | "event selector. use 'perf list' to list available events", |
| 968 | parse_events), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 969 | OPT_INTEGER('c', "count", &default_interval, |
| 970 | "event period to sample"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 971 | OPT_INTEGER('p', "pid", &top.target_pid, |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 972 | "profile events on existing process id"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 973 | OPT_INTEGER('t', "tid", &top.target_tid, |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 974 | "profile events on existing thread id"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 975 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
| 976 | "system-wide collection from all CPUs"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 977 | OPT_STRING('C', "cpu", &top.cpu_list, "cpu", |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 978 | "list of cpus to monitor"), |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 979 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 980 | "file", "vmlinux pathname"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 981 | OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols, |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 982 | "hide kernel symbols"), |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 983 | OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 984 | OPT_INTEGER('r', "realtime", &realtime_prio, |
| 985 | "collect data with this RT SCHED_FIFO priority"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 986 | OPT_INTEGER('d', "delay", &top.delay_secs, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 987 | "number of seconds to delay between refreshes"), |
| 988 | OPT_BOOLEAN('D', "dump-symtab", &dump_symtab, |
| 989 | "dump the symbol table used for profiling"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 990 | OPT_INTEGER('f', "count-filter", &top.count_filter, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 991 | "only display functions with more events than this"), |
| 992 | OPT_BOOLEAN('g', "group", &group, |
| 993 | "put the counters into a counter group"), |
Mike Galbraith | 0fdc7e6 | 2009-07-21 10:30:36 +0200 | [diff] [blame] | 994 | OPT_BOOLEAN('i', "inherit", &inherit, |
| 995 | "child tasks inherit counters"), |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 996 | OPT_STRING('s', "sym-annotate", &sym_filter, "symbol name", |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 997 | "symbol to annotate"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 998 | OPT_BOOLEAN('z', "zero", &top.zero, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 999 | "zero history across updates"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1000 | OPT_INTEGER('F', "freq", &top.freq, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1001 | "profile at this frequency"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1002 | OPT_INTEGER('E', "entries", &top.print_entries, |
Ingo Molnar | 6e53cdf | 2009-06-04 08:53:05 +0200 | [diff] [blame] | 1003 | "display this many functions"), |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1004 | OPT_BOOLEAN('U', "hide_user_symbols", &top.hide_user_symbols, |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 1005 | "hide user symbols"), |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 1006 | OPT_BOOLEAN(0, "tui", &use_tui, "Use the TUI interface"), |
| 1007 | OPT_BOOLEAN(0, "stdio", &use_stdio, "Use the stdio interface"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1008 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | 3da297a | 2009-06-07 17:39:02 +0200 | [diff] [blame] | 1009 | "be more verbose (show counter open errors, etc)"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1010 | OPT_END() |
| 1011 | }; |
| 1012 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1013 | int cmd_top(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1014 | { |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1015 | struct perf_evsel *pos; |
| 1016 | int status = -ENOMEM; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1017 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1018 | top.evlist = perf_evlist__new(NULL, NULL); |
| 1019 | if (top.evlist == NULL) |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 1020 | return -ENOMEM; |
| 1021 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1022 | page_size = sysconf(_SC_PAGE_SIZE); |
| 1023 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1024 | argc = parse_options(argc, argv, options, top_usage, 0); |
| 1025 | if (argc) |
| 1026 | usage_with_options(top_usage, options); |
| 1027 | |
Arnaldo Carvalho de Melo | c0443df | 2011-01-31 18:19:33 -0200 | [diff] [blame] | 1028 | /* |
| 1029 | * XXX For now start disabled, only using TUI if explicitely asked for. |
| 1030 | * Change that when handle_keys equivalent gets written, live annotation |
| 1031 | * done, etc. |
| 1032 | */ |
| 1033 | use_browser = 0; |
| 1034 | |
| 1035 | if (use_stdio) |
| 1036 | use_browser = 0; |
| 1037 | else if (use_tui) |
| 1038 | use_browser = 1; |
| 1039 | |
| 1040 | setup_browser(false); |
| 1041 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1042 | /* CPU and PID are mutually exclusive */ |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1043 | if (top.target_tid > 0 && top.cpu_list) { |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1044 | printf("WARNING: PID switch overriding CPU\n"); |
| 1045 | sleep(1); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1046 | top.cpu_list = NULL; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1049 | if (top.target_pid != -1) |
| 1050 | top.target_tid = top.target_pid; |
Arnaldo Carvalho de Melo | 7e2ed09 | 2011-01-30 11:59:43 -0200 | [diff] [blame] | 1051 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1052 | if (perf_evlist__create_maps(top.evlist, top.target_pid, |
| 1053 | top.target_tid, top.cpu_list) < 0) |
Arnaldo Carvalho de Melo | 7e2ed09 | 2011-01-30 11:59:43 -0200 | [diff] [blame] | 1054 | usage_with_options(top_usage, options); |
| 1055 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1056 | if (!top.evlist->nr_entries && |
| 1057 | perf_evlist__add_default(top.evlist) < 0) { |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1058 | pr_err("Not enough memory for event selector list\n"); |
| 1059 | return -ENOMEM; |
| 1060 | } |
Arnaldo Carvalho de Melo | 5a8e5a3 | 2009-11-17 18:38:01 -0200 | [diff] [blame] | 1061 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1062 | if (top.delay_secs < 1) |
| 1063 | top.delay_secs = 1; |
Frederic Weisbecker | 2f335a0 | 2009-06-05 19:31:01 +0200 | [diff] [blame] | 1064 | |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 1065 | /* |
| 1066 | * User specified count overrides default frequency. |
| 1067 | */ |
| 1068 | if (default_interval) |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1069 | top.freq = 0; |
| 1070 | else if (top.freq) { |
| 1071 | default_interval = top.freq; |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 1072 | } else { |
| 1073 | fprintf(stderr, "frequency and count are zero, aborting\n"); |
| 1074 | exit(EXIT_FAILURE); |
| 1075 | } |
| 1076 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1077 | list_for_each_entry(pos, &top.evlist->entries, node) { |
| 1078 | if (perf_evsel__alloc_fd(pos, top.evlist->cpus->nr, |
| 1079 | top.evlist->threads->nr) < 0) |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1080 | goto out_free_fd; |
| 1081 | /* |
| 1082 | * Fill in the ones not specifically initialized via -c: |
| 1083 | */ |
| 1084 | if (pos->attr.sample_period) |
| 1085 | continue; |
| 1086 | |
| 1087 | pos->attr.sample_period = default_interval; |
| 1088 | } |
| 1089 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1090 | if (perf_evlist__alloc_pollfd(top.evlist) < 0 || |
| 1091 | perf_evlist__alloc_mmap(top.evlist) < 0) |
Arnaldo Carvalho de Melo | 5c58104 | 2011-01-11 22:30:02 -0200 | [diff] [blame] | 1092 | goto out_free_fd; |
| 1093 | |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1094 | top.sym_evsel = list_entry(top.evlist->entries.next, struct perf_evsel, node); |
Arnaldo Carvalho de Melo | cc84158 | 2011-01-11 15:16:52 -0200 | [diff] [blame] | 1095 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1096 | symbol_conf.priv_size = (sizeof(struct sym_entry) + sizeof(struct annotation) + |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1097 | (top.evlist->nr_entries + 1) * sizeof(unsigned long)); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1098 | |
| 1099 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); |
| 1100 | if (symbol__init() < 0) |
| 1101 | return -1; |
| 1102 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 1103 | get_term_dimensions(&winsize); |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1104 | if (top.print_entries == 0) { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 1105 | update_print_entries(&winsize); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 1106 | signal(SIGWINCH, sig_winch_handler); |
| 1107 | } |
| 1108 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1109 | status = __cmd_top(); |
| 1110 | out_free_fd: |
Arnaldo Carvalho de Melo | 8c3e10e | 2011-01-31 14:50:39 -0200 | [diff] [blame] | 1111 | perf_evlist__delete(top.evlist); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1112 | |
| 1113 | return status; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1114 | } |