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 | |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 23 | #include "util/color.h" |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 24 | #include "util/session.h" |
| 25 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 26 | #include "util/thread.h" |
Ingo Molnar | 148be2c | 2009-04-27 08:02:14 +0200 | [diff] [blame] | 27 | #include "util/util.h" |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 28 | #include <linux/rbtree.h> |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 29 | #include "util/parse-options.h" |
| 30 | #include "util/parse-events.h" |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 31 | #include "util/cpumap.h" |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 32 | |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 33 | #include "util/debug.h" |
| 34 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 35 | #include <assert.h> |
| 36 | #include <fcntl.h> |
Ingo Molnar | 0e9b20b | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 37 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 38 | #include <stdio.h> |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 39 | #include <termios.h> |
| 40 | #include <unistd.h> |
Ingo Molnar | 0e9b20b | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 41 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 42 | #include <errno.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 43 | #include <time.h> |
| 44 | #include <sched.h> |
| 45 | #include <pthread.h> |
| 46 | |
| 47 | #include <sys/syscall.h> |
| 48 | #include <sys/ioctl.h> |
| 49 | #include <sys/poll.h> |
| 50 | #include <sys/prctl.h> |
| 51 | #include <sys/wait.h> |
| 52 | #include <sys/uio.h> |
| 53 | #include <sys/mman.h> |
| 54 | |
| 55 | #include <linux/unistd.h> |
| 56 | #include <linux/types.h> |
| 57 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 58 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 59 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 60 | static bool system_wide = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 61 | |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 62 | static int default_interval = 0; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 63 | |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 64 | static int count_filter = 5; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 65 | static int print_entries; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 66 | |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 67 | static int target_pid = -1; |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 68 | static int target_tid = -1; |
| 69 | static pid_t *all_tids = NULL; |
| 70 | static int thread_num = 0; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 71 | static bool inherit = false; |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 72 | static int profile_cpu = -1; |
| 73 | static int nr_cpus = 0; |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 74 | static int realtime_prio = 0; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 75 | static bool group = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 76 | static unsigned int page_size; |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 77 | static unsigned int mmap_pages = 16; |
| 78 | static int freq = 1000; /* 1 KHz */ |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 79 | |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 80 | static int delay_secs = 2; |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 81 | static bool zero = false; |
| 82 | static bool dump_symtab = false; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 83 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 84 | static bool hide_kernel_symbols = false; |
| 85 | static bool hide_user_symbols = false; |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 86 | static struct winsize winsize; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 87 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 88 | /* |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 89 | * Source |
| 90 | */ |
| 91 | |
| 92 | struct source_line { |
| 93 | u64 eip; |
| 94 | unsigned long count[MAX_COUNTERS]; |
| 95 | char *line; |
| 96 | struct source_line *next; |
| 97 | }; |
| 98 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 99 | static const char *sym_filter = NULL; |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 100 | struct sym_entry *sym_filter_entry = NULL; |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 101 | struct sym_entry *sym_filter_entry_sched = NULL; |
Ingo Molnar | 42e59d7 | 2009-10-06 15:14:21 +0200 | [diff] [blame] | 102 | static int sym_pcnt_filter = 5; |
| 103 | static int sym_counter = 0; |
| 104 | static int display_weighted = -1; |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 105 | static const char *cpu_list; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 106 | |
| 107 | /* |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 108 | * Symbols |
| 109 | */ |
| 110 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 111 | struct sym_entry_source { |
| 112 | struct source_line *source; |
| 113 | struct source_line *lines; |
| 114 | struct source_line **lines_tail; |
| 115 | pthread_mutex_t lock; |
| 116 | }; |
| 117 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 118 | struct sym_entry { |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 119 | struct rb_node rb_node; |
| 120 | struct list_head node; |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 121 | unsigned long snap_count; |
| 122 | double weight; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 123 | int skip; |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 124 | u16 name_len; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 125 | u8 origin; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 126 | struct map *map; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 127 | struct sym_entry_source *src; |
Arnaldo Carvalho de Melo | 5a8e5a3 | 2009-11-17 18:38:01 -0200 | [diff] [blame] | 128 | unsigned long count[0]; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 131 | /* |
| 132 | * Source functions |
| 133 | */ |
| 134 | |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 135 | static inline struct symbol *sym_entry__symbol(struct sym_entry *self) |
| 136 | { |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 137 | return ((void *)self) + symbol_conf.priv_size; |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 138 | } |
| 139 | |
Arnaldo Carvalho de Melo | 895f0ed | 2010-03-11 20:12:41 -0300 | [diff] [blame] | 140 | void get_term_dimensions(struct winsize *ws) |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 141 | { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 142 | char *s = getenv("LINES"); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 143 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 144 | if (s != NULL) { |
| 145 | ws->ws_row = atoi(s); |
| 146 | s = getenv("COLUMNS"); |
| 147 | if (s != NULL) { |
| 148 | ws->ws_col = atoi(s); |
| 149 | if (ws->ws_row && ws->ws_col) |
| 150 | return; |
| 151 | } |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 152 | } |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 153 | #ifdef TIOCGWINSZ |
| 154 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && |
| 155 | ws->ws_row && ws->ws_col) |
| 156 | return; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 157 | #endif |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 158 | ws->ws_row = 25; |
| 159 | ws->ws_col = 80; |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 160 | } |
| 161 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 162 | static void update_print_entries(struct winsize *ws) |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 163 | { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 164 | print_entries = ws->ws_row; |
| 165 | |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 166 | if (print_entries > 9) |
| 167 | print_entries -= 9; |
| 168 | } |
| 169 | |
| 170 | static void sig_winch_handler(int sig __used) |
| 171 | { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 172 | get_term_dimensions(&winsize); |
| 173 | update_print_entries(&winsize); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 174 | } |
| 175 | |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 176 | static int parse_source(struct sym_entry *syme) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 177 | { |
| 178 | struct symbol *sym; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 179 | struct sym_entry_source *source; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 180 | struct map *map; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 181 | FILE *file; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 182 | char command[PATH_MAX*2]; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 183 | const char *path; |
| 184 | u64 len; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 185 | |
| 186 | if (!syme) |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 187 | return -1; |
| 188 | |
| 189 | sym = sym_entry__symbol(syme); |
| 190 | map = syme->map; |
| 191 | |
| 192 | /* |
| 193 | * We can't annotate with just /proc/kallsyms |
| 194 | */ |
| 195 | if (map->dso->origin == DSO__ORIG_KERNEL) |
| 196 | return -1; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 197 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 198 | if (syme->src == NULL) { |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 199 | syme->src = zalloc(sizeof(*source)); |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 200 | if (syme->src == NULL) |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 201 | return -1; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 202 | pthread_mutex_init(&syme->src->lock, NULL); |
| 203 | } |
| 204 | |
| 205 | source = syme->src; |
| 206 | |
| 207 | if (source->lines) { |
| 208 | pthread_mutex_lock(&source->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 209 | goto out_assign; |
| 210 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 211 | path = map->dso->long_name; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 212 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 213 | len = sym->end - sym->start; |
| 214 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 215 | sprintf(command, |
Arnaldo Carvalho de Melo | 5f48536 | 2010-02-07 11:46:16 -0200 | [diff] [blame] | 216 | "objdump --start-address=%#0*Lx --stop-address=%#0*Lx -dS %s", |
| 217 | BITS_PER_LONG / 4, map__rip_2objdump(map, sym->start), |
| 218 | BITS_PER_LONG / 4, map__rip_2objdump(map, sym->end), path); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 219 | |
| 220 | file = popen(command, "r"); |
| 221 | if (!file) |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 222 | return -1; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 223 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 224 | pthread_mutex_lock(&source->lock); |
| 225 | source->lines_tail = &source->lines; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 226 | while (!feof(file)) { |
| 227 | struct source_line *src; |
| 228 | size_t dummy = 0; |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 229 | char *c, *sep; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 230 | |
| 231 | src = malloc(sizeof(struct source_line)); |
| 232 | assert(src != NULL); |
| 233 | memset(src, 0, sizeof(struct source_line)); |
| 234 | |
| 235 | if (getline(&src->line, &dummy, file) < 0) |
| 236 | break; |
| 237 | if (!src->line) |
| 238 | break; |
| 239 | |
| 240 | c = strchr(src->line, '\n'); |
| 241 | if (c) |
| 242 | *c = 0; |
| 243 | |
| 244 | src->next = NULL; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 245 | *source->lines_tail = src; |
| 246 | source->lines_tail = &src->next; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 247 | |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 248 | src->eip = strtoull(src->line, &sep, 16); |
| 249 | if (*sep == ':') |
| 250 | src->eip = map__objdump_2ip(map, src->eip); |
| 251 | else /* this line has no ip info (e.g. source line) */ |
| 252 | src->eip = 0; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 253 | } |
| 254 | pclose(file); |
| 255 | out_assign: |
| 256 | sym_filter_entry = syme; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 257 | pthread_mutex_unlock(&source->lock); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 258 | return 0; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static void __zero_source_counters(struct sym_entry *syme) |
| 262 | { |
| 263 | int i; |
| 264 | struct source_line *line; |
| 265 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 266 | line = syme->src->lines; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 267 | while (line) { |
| 268 | for (i = 0; i < nr_counters; i++) |
| 269 | line->count[i] = 0; |
| 270 | line = line->next; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | static void record_precise_ip(struct sym_entry *syme, int counter, u64 ip) |
| 275 | { |
| 276 | struct source_line *line; |
| 277 | |
| 278 | if (syme != sym_filter_entry) |
| 279 | return; |
| 280 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 281 | if (pthread_mutex_trylock(&syme->src->lock)) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 282 | return; |
| 283 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 284 | if (syme->src == NULL || syme->src->source == NULL) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 285 | goto out_unlock; |
| 286 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 287 | for (line = syme->src->lines; line; line = line->next) { |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 288 | /* skip lines without IP info */ |
| 289 | if (line->eip == 0) |
| 290 | continue; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 291 | if (line->eip == ip) { |
| 292 | line->count[counter]++; |
| 293 | break; |
| 294 | } |
| 295 | if (line->eip > ip) |
| 296 | break; |
| 297 | } |
| 298 | out_unlock: |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 299 | pthread_mutex_unlock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Arnaldo Carvalho de Melo | c7ad21a | 2010-02-22 16:14:22 -0300 | [diff] [blame] | 302 | #define PATTERN_LEN (BITS_PER_LONG / 4 + 2) |
| 303 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 304 | static void lookup_sym_source(struct sym_entry *syme) |
| 305 | { |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 306 | struct symbol *symbol = sym_entry__symbol(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 307 | struct source_line *line; |
Arnaldo Carvalho de Melo | c7ad21a | 2010-02-22 16:14:22 -0300 | [diff] [blame] | 308 | char pattern[PATTERN_LEN + 1]; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 309 | |
Arnaldo Carvalho de Melo | 5f48536 | 2010-02-07 11:46:16 -0200 | [diff] [blame] | 310 | sprintf(pattern, "%0*Lx <", BITS_PER_LONG / 4, |
| 311 | map__rip_2objdump(syme->map, symbol->start)); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 312 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 313 | pthread_mutex_lock(&syme->src->lock); |
| 314 | for (line = syme->src->lines; line; line = line->next) { |
Arnaldo Carvalho de Melo | c7ad21a | 2010-02-22 16:14:22 -0300 | [diff] [blame] | 315 | if (memcmp(line->line, pattern, PATTERN_LEN) == 0) { |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 316 | syme->src->source = line; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | } |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 320 | pthread_mutex_unlock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void show_lines(struct source_line *queue, int count, int total) |
| 324 | { |
| 325 | int i; |
| 326 | struct source_line *line; |
| 327 | |
| 328 | line = queue; |
| 329 | for (i = 0; i < count; i++) { |
| 330 | float pcnt = 100.0*(float)line->count[sym_counter]/(float)total; |
| 331 | |
| 332 | printf("%8li %4.1f%%\t%s\n", line->count[sym_counter], pcnt, line->line); |
| 333 | line = line->next; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | #define TRACE_COUNT 3 |
| 338 | |
| 339 | static void show_details(struct sym_entry *syme) |
| 340 | { |
| 341 | struct symbol *symbol; |
| 342 | struct source_line *line; |
| 343 | struct source_line *line_queue = NULL; |
| 344 | int displayed = 0; |
| 345 | int line_queue_count = 0, total = 0, more = 0; |
| 346 | |
| 347 | if (!syme) |
| 348 | return; |
| 349 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 350 | if (!syme->src->source) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 351 | lookup_sym_source(syme); |
| 352 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 353 | if (!syme->src->source) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 354 | return; |
| 355 | |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 356 | symbol = sym_entry__symbol(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 357 | printf("Showing %s for %s\n", event_name(sym_counter), symbol->name); |
| 358 | printf(" Events Pcnt (>=%d%%)\n", sym_pcnt_filter); |
| 359 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 360 | pthread_mutex_lock(&syme->src->lock); |
| 361 | line = syme->src->source; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 362 | while (line) { |
| 363 | total += line->count[sym_counter]; |
| 364 | line = line->next; |
| 365 | } |
| 366 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 367 | line = syme->src->source; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 368 | while (line) { |
| 369 | float pcnt = 0.0; |
| 370 | |
| 371 | if (!line_queue_count) |
| 372 | line_queue = line; |
| 373 | line_queue_count++; |
| 374 | |
| 375 | if (line->count[sym_counter]) |
| 376 | pcnt = 100.0 * line->count[sym_counter] / (float)total; |
| 377 | if (pcnt >= (float)sym_pcnt_filter) { |
| 378 | if (displayed <= print_entries) |
| 379 | show_lines(line_queue, line_queue_count, total); |
| 380 | else more++; |
| 381 | displayed += line_queue_count; |
| 382 | line_queue_count = 0; |
| 383 | line_queue = NULL; |
| 384 | } else if (line_queue_count > TRACE_COUNT) { |
| 385 | line_queue = line_queue->next; |
| 386 | line_queue_count--; |
| 387 | } |
| 388 | |
| 389 | line->count[sym_counter] = zero ? 0 : line->count[sym_counter] * 7 / 8; |
| 390 | line = line->next; |
| 391 | } |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 392 | pthread_mutex_unlock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 393 | if (more) |
| 394 | printf("%d lines not displayed, maybe increase display entries [e]\n", more); |
| 395 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 396 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 397 | /* |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 398 | * Symbols will be added here in event__process_sample and will get out |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 399 | * after decayed. |
| 400 | */ |
| 401 | static LIST_HEAD(active_symbols); |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 402 | static pthread_mutex_t active_symbols_lock = PTHREAD_MUTEX_INITIALIZER; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 403 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 404 | /* |
| 405 | * Ordering weight: count-1 * count-2 * ... / count-n |
| 406 | */ |
| 407 | static double sym_weight(const struct sym_entry *sym) |
| 408 | { |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 409 | double weight = sym->snap_count; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 410 | int counter; |
| 411 | |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 412 | if (!display_weighted) |
| 413 | return weight; |
| 414 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 415 | for (counter = 1; counter < nr_counters-1; counter++) |
| 416 | weight *= sym->count[counter]; |
| 417 | |
| 418 | weight /= (sym->count[counter] + 1); |
| 419 | |
| 420 | return weight; |
| 421 | } |
| 422 | |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 423 | static long samples; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 424 | static long kernel_samples, us_samples; |
Peter Zijlstra | 1676b8a | 2010-03-04 14:19:36 +0100 | [diff] [blame] | 425 | static long exact_samples; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 426 | static long guest_us_samples, guest_kernel_samples; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 427 | static const char CONSOLE_CLEAR[] = "[H[2J"; |
| 428 | |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 429 | static void __list_insert_active_sym(struct sym_entry *syme) |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 430 | { |
| 431 | list_add(&syme->node, &active_symbols); |
| 432 | } |
| 433 | |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 434 | static void list_remove_active_sym(struct sym_entry *syme) |
| 435 | { |
| 436 | pthread_mutex_lock(&active_symbols_lock); |
| 437 | list_del_init(&syme->node); |
| 438 | pthread_mutex_unlock(&active_symbols_lock); |
| 439 | } |
| 440 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 441 | static void rb_insert_active_sym(struct rb_root *tree, struct sym_entry *se) |
| 442 | { |
| 443 | struct rb_node **p = &tree->rb_node; |
| 444 | struct rb_node *parent = NULL; |
| 445 | struct sym_entry *iter; |
| 446 | |
| 447 | while (*p != NULL) { |
| 448 | parent = *p; |
| 449 | iter = rb_entry(parent, struct sym_entry, rb_node); |
| 450 | |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 451 | if (se->weight > iter->weight) |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 452 | p = &(*p)->rb_left; |
| 453 | else |
| 454 | p = &(*p)->rb_right; |
| 455 | } |
| 456 | |
| 457 | rb_link_node(&se->rb_node, parent, p); |
| 458 | rb_insert_color(&se->rb_node, tree); |
| 459 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 460 | |
| 461 | static void print_sym_table(void) |
| 462 | { |
Ingo Molnar | 233f0b9 | 2009-06-03 21:48:40 +0200 | [diff] [blame] | 463 | int printed = 0, j; |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 464 | int counter, snap = !display_weighted ? sym_counter : 0; |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 465 | float samples_per_sec = samples/delay_secs; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 466 | float ksamples_per_sec = kernel_samples/delay_secs; |
| 467 | float us_samples_per_sec = (us_samples)/delay_secs; |
| 468 | float guest_kernel_samples_per_sec = (guest_kernel_samples)/delay_secs; |
| 469 | float guest_us_samples_per_sec = (guest_us_samples)/delay_secs; |
Peter Zijlstra | 1676b8a | 2010-03-04 14:19:36 +0100 | [diff] [blame] | 470 | float esamples_percent = (100.0*exact_samples)/samples; |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 471 | float sum_ksamples = 0.0; |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 472 | struct sym_entry *syme, *n; |
| 473 | struct rb_root tmp = RB_ROOT; |
| 474 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 00909e9 | 2010-03-16 18:28:46 -0300 | [diff] [blame] | 475 | int sym_width = 0, dso_width = 0, dso_short_width = 0; |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 476 | const int win_width = winsize.ws_col - 1; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 477 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 478 | samples = us_samples = kernel_samples = exact_samples = 0; |
| 479 | guest_kernel_samples = guest_us_samples = 0; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 480 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 481 | /* Sort the active symbols */ |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 482 | pthread_mutex_lock(&active_symbols_lock); |
| 483 | syme = list_entry(active_symbols.next, struct sym_entry, node); |
| 484 | pthread_mutex_unlock(&active_symbols_lock); |
| 485 | |
| 486 | list_for_each_entry_safe_from(syme, n, &active_symbols, node) { |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 487 | syme->snap_count = syme->count[snap]; |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 488 | if (syme->snap_count != 0) { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 489 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 490 | if ((hide_user_symbols && |
| 491 | syme->origin == PERF_RECORD_MISC_USER) || |
| 492 | (hide_kernel_symbols && |
| 493 | syme->origin == PERF_RECORD_MISC_KERNEL)) { |
| 494 | list_remove_active_sym(syme); |
| 495 | continue; |
| 496 | } |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 497 | syme->weight = sym_weight(syme); |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 498 | rb_insert_active_sym(&tmp, syme); |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 499 | sum_ksamples += syme->snap_count; |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 500 | |
| 501 | for (j = 0; j < nr_counters; j++) |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 502 | syme->count[j] = zero ? 0 : syme->count[j] * 7 / 8; |
| 503 | } else |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 504 | list_remove_active_sym(syme); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 507 | puts(CONSOLE_CLEAR); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 508 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 509 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 510 | if (!perf_guest) { |
| 511 | printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%%" |
| 512 | " exact: %4.1f%% [", |
| 513 | samples_per_sec, |
| 514 | 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) / |
| 515 | samples_per_sec)), |
| 516 | esamples_percent); |
| 517 | } else { |
| 518 | printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%" |
| 519 | " guest kernel:%4.1f%% guest us:%4.1f%%" |
| 520 | " exact: %4.1f%% [", |
| 521 | samples_per_sec, |
| 522 | 100.0 - (100.0 * ((samples_per_sec-ksamples_per_sec) / |
| 523 | samples_per_sec)), |
| 524 | 100.0 - (100.0 * ((samples_per_sec-us_samples_per_sec) / |
| 525 | samples_per_sec)), |
| 526 | 100.0 - (100.0 * ((samples_per_sec - |
| 527 | guest_kernel_samples_per_sec) / |
| 528 | samples_per_sec)), |
| 529 | 100.0 - (100.0 * ((samples_per_sec - |
| 530 | guest_us_samples_per_sec) / |
| 531 | samples_per_sec)), |
| 532 | esamples_percent); |
| 533 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 534 | |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 535 | if (nr_counters == 1 || !display_weighted) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 536 | printf("%Ld", (u64)attrs[0].sample_period); |
Ingo Molnar | cf1f457 | 2009-06-05 13:27:02 +0200 | [diff] [blame] | 537 | if (freq) |
| 538 | printf("Hz "); |
| 539 | else |
| 540 | printf(" "); |
| 541 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 542 | |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 543 | if (!display_weighted) |
| 544 | printf("%s", event_name(sym_counter)); |
| 545 | else for (counter = 0; counter < nr_counters; counter++) { |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 546 | if (counter) |
| 547 | printf("/"); |
| 548 | |
| 549 | printf("%s", event_name(counter)); |
| 550 | } |
| 551 | |
| 552 | printf( "], "); |
| 553 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 554 | if (target_pid != -1) |
| 555 | printf(" (target_pid: %d", target_pid); |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 556 | else if (target_tid != -1) |
| 557 | printf(" (target_tid: %d", target_tid); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 558 | else |
| 559 | printf(" (all"); |
| 560 | |
| 561 | if (profile_cpu != -1) |
| 562 | printf(", cpu: %d)\n", profile_cpu); |
| 563 | else { |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 564 | if (target_tid != -1) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 565 | printf(")\n"); |
| 566 | else |
| 567 | printf(", %d CPUs)\n", nr_cpus); |
| 568 | } |
| 569 | |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 570 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 571 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 572 | if (sym_filter_entry) { |
| 573 | show_details(sym_filter_entry); |
| 574 | return; |
| 575 | } |
| 576 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 577 | /* |
| 578 | * Find the longest symbol name that will be displayed |
| 579 | */ |
| 580 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { |
| 581 | syme = rb_entry(nd, struct sym_entry, rb_node); |
| 582 | if (++printed > print_entries || |
| 583 | (int)syme->snap_count < count_filter) |
| 584 | continue; |
| 585 | |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 586 | if (syme->map->dso->long_name_len > dso_width) |
| 587 | dso_width = syme->map->dso->long_name_len; |
| 588 | |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 589 | if (syme->map->dso->short_name_len > dso_short_width) |
| 590 | dso_short_width = syme->map->dso->short_name_len; |
| 591 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 592 | if (syme->name_len > sym_width) |
| 593 | sym_width = syme->name_len; |
| 594 | } |
| 595 | |
| 596 | printed = 0; |
| 597 | |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 598 | if (sym_width + dso_width > winsize.ws_col - 29) { |
| 599 | dso_width = dso_short_width; |
| 600 | if (sym_width + dso_width > winsize.ws_col - 29) |
| 601 | sym_width = winsize.ws_col - dso_width - 29; |
| 602 | } |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 603 | putchar('\n'); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 604 | if (nr_counters == 1) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 605 | printf(" samples pcnt"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 606 | else |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 607 | printf(" weight samples pcnt"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 608 | |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 609 | if (verbose) |
| 610 | printf(" RIP "); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 611 | printf(" %-*.*s DSO\n", sym_width, sym_width, "function"); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 612 | printf(" %s _______ _____", |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 613 | nr_counters == 1 ? " " : "______"); |
| 614 | if (verbose) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 615 | printf(" ________________"); |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 616 | printf(" %-*.*s", sym_width, sym_width, graph_line); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 617 | printf(" %-*.*s", dso_width, dso_width, graph_line); |
Arnaldo Carvalho de Melo | 1a105f7 | 2009-11-17 15:40:55 -0200 | [diff] [blame] | 618 | puts("\n"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 619 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 620 | for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 621 | struct symbol *sym; |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 622 | double pcnt; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 623 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 624 | syme = rb_entry(nd, struct sym_entry, rb_node); |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 625 | sym = sym_entry__symbol(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 626 | if (++printed > print_entries || (int)syme->snap_count < count_filter) |
Arnaldo Carvalho de Melo | c44613a | 2009-05-29 17:03:07 -0300 | [diff] [blame] | 627 | continue; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 628 | |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 629 | pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) / |
| 630 | sum_ksamples)); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 631 | |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 632 | if (nr_counters == 1 || !display_weighted) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 633 | printf("%20.2f ", syme->weight); |
Mike Galbraith | d94b943 | 2009-05-25 09:57:56 +0200 | [diff] [blame] | 634 | else |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 635 | printf("%9.1f %10ld ", syme->weight, syme->snap_count); |
Ingo Molnar | 8fc0321 | 2009-06-04 15:19:47 +0200 | [diff] [blame] | 636 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 637 | percent_color_fprintf(stdout, "%4.1f%%", pcnt); |
Arnaldo Carvalho de Melo | 7ced156 | 2009-08-26 11:51:26 -0300 | [diff] [blame] | 638 | if (verbose) |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 639 | printf(" %016llx", sym->start); |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 640 | printf(" %-*.*s", sym_width, sym_width, sym->name); |
Arnaldo Carvalho de Melo | 7cc017e | 2009-11-24 12:05:14 -0200 | [diff] [blame] | 641 | printf(" %-*.*s\n", dso_width, dso_width, |
| 642 | dso_width >= syme->map->dso->long_name_len ? |
| 643 | syme->map->dso->long_name : |
| 644 | syme->map->dso->short_name); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 645 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 646 | } |
| 647 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 648 | static void prompt_integer(int *target, const char *msg) |
| 649 | { |
| 650 | char *buf = malloc(0), *p; |
| 651 | size_t dummy = 0; |
| 652 | int tmp; |
| 653 | |
| 654 | fprintf(stdout, "\n%s: ", msg); |
| 655 | if (getline(&buf, &dummy, stdin) < 0) |
| 656 | return; |
| 657 | |
| 658 | p = strchr(buf, '\n'); |
| 659 | if (p) |
| 660 | *p = 0; |
| 661 | |
| 662 | p = buf; |
| 663 | while(*p) { |
| 664 | if (!isdigit(*p)) |
| 665 | goto out_free; |
| 666 | p++; |
| 667 | } |
| 668 | tmp = strtoul(buf, NULL, 10); |
| 669 | *target = tmp; |
| 670 | out_free: |
| 671 | free(buf); |
| 672 | } |
| 673 | |
| 674 | static void prompt_percent(int *target, const char *msg) |
| 675 | { |
| 676 | int tmp = 0; |
| 677 | |
| 678 | prompt_integer(&tmp, msg); |
| 679 | if (tmp >= 0 && tmp <= 100) |
| 680 | *target = tmp; |
| 681 | } |
| 682 | |
| 683 | static void prompt_symbol(struct sym_entry **target, const char *msg) |
| 684 | { |
| 685 | char *buf = malloc(0), *p; |
| 686 | struct sym_entry *syme = *target, *n, *found = NULL; |
| 687 | size_t dummy = 0; |
| 688 | |
| 689 | /* zero counters of active symbol */ |
| 690 | if (syme) { |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 691 | pthread_mutex_lock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 692 | __zero_source_counters(syme); |
| 693 | *target = NULL; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 694 | pthread_mutex_unlock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | fprintf(stdout, "\n%s: ", msg); |
| 698 | if (getline(&buf, &dummy, stdin) < 0) |
| 699 | goto out_free; |
| 700 | |
| 701 | p = strchr(buf, '\n'); |
| 702 | if (p) |
| 703 | *p = 0; |
| 704 | |
| 705 | pthread_mutex_lock(&active_symbols_lock); |
| 706 | syme = list_entry(active_symbols.next, struct sym_entry, node); |
| 707 | pthread_mutex_unlock(&active_symbols_lock); |
| 708 | |
| 709 | list_for_each_entry_safe_from(syme, n, &active_symbols, node) { |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 710 | struct symbol *sym = sym_entry__symbol(syme); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 711 | |
| 712 | if (!strcmp(buf, sym->name)) { |
| 713 | found = syme; |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | if (!found) { |
Kirill Smelkov | 66aeb6d | 2010-01-13 13:22:19 -0200 | [diff] [blame] | 719 | fprintf(stderr, "Sorry, %s is not active.\n", buf); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 720 | sleep(1); |
| 721 | return; |
| 722 | } else |
| 723 | parse_source(found); |
| 724 | |
| 725 | out_free: |
| 726 | free(buf); |
| 727 | } |
| 728 | |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 729 | static void print_mapped_keys(void) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 730 | { |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 731 | char *name = NULL; |
| 732 | |
| 733 | if (sym_filter_entry) { |
Arnaldo Carvalho de Melo | 51a472d | 2009-11-17 18:38:00 -0200 | [diff] [blame] | 734 | struct symbol *sym = sym_entry__symbol(sym_filter_entry); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 735 | name = sym->name; |
| 736 | } |
| 737 | |
| 738 | fprintf(stdout, "\nMapped keys:\n"); |
| 739 | fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", delay_secs); |
| 740 | fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", print_entries); |
| 741 | |
| 742 | if (nr_counters > 1) |
| 743 | fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(sym_counter)); |
| 744 | |
| 745 | fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter); |
| 746 | |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 747 | fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter); |
| 748 | fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL"); |
| 749 | fprintf(stdout, "\t[S] stop annotation.\n"); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 750 | |
| 751 | if (nr_counters > 1) |
| 752 | fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0); |
| 753 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 754 | fprintf(stdout, |
Kirill Smelkov | 1a72cfa | 2010-02-12 19:20:59 +0300 | [diff] [blame] | 755 | "\t[K] hide kernel_symbols symbols. \t(%s)\n", |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 756 | hide_kernel_symbols ? "yes" : "no"); |
| 757 | fprintf(stdout, |
| 758 | "\t[U] hide user symbols. \t(%s)\n", |
| 759 | hide_user_symbols ? "yes" : "no"); |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 760 | fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", zero ? 1 : 0); |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 761 | fprintf(stdout, "\t[qQ] quit.\n"); |
| 762 | } |
| 763 | |
| 764 | static int key_mapped(int c) |
| 765 | { |
| 766 | switch (c) { |
| 767 | case 'd': |
| 768 | case 'e': |
| 769 | case 'f': |
| 770 | case 'z': |
| 771 | case 'q': |
| 772 | case 'Q': |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 773 | case 'K': |
| 774 | case 'U': |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 775 | case 'F': |
| 776 | case 's': |
| 777 | case 'S': |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 778 | return 1; |
| 779 | case 'E': |
| 780 | case 'w': |
| 781 | return nr_counters > 1 ? 1 : 0; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 782 | default: |
| 783 | break; |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | return 0; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 787 | } |
| 788 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 789 | static void handle_keypress(struct perf_session *session, int c) |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 790 | { |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 791 | if (!key_mapped(c)) { |
| 792 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
| 793 | struct termios tc, save; |
| 794 | |
| 795 | print_mapped_keys(); |
| 796 | fprintf(stdout, "\nEnter selection, or unmapped key to continue: "); |
| 797 | fflush(stdout); |
| 798 | |
| 799 | tcgetattr(0, &save); |
| 800 | tc = save; |
| 801 | tc.c_lflag &= ~(ICANON | ECHO); |
| 802 | tc.c_cc[VMIN] = 0; |
| 803 | tc.c_cc[VTIME] = 0; |
| 804 | tcsetattr(0, TCSANOW, &tc); |
| 805 | |
| 806 | poll(&stdin_poll, 1, -1); |
| 807 | c = getc(stdin); |
| 808 | |
| 809 | tcsetattr(0, TCSAFLUSH, &save); |
| 810 | if (!key_mapped(c)) |
| 811 | return; |
| 812 | } |
| 813 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 814 | switch (c) { |
| 815 | case 'd': |
| 816 | prompt_integer(&delay_secs, "Enter display delay"); |
Tim Blechmann | dc79959 | 2009-10-17 18:08:29 +0200 | [diff] [blame] | 817 | if (delay_secs < 1) |
| 818 | delay_secs = 1; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 819 | break; |
| 820 | case 'e': |
| 821 | prompt_integer(&print_entries, "Enter display entries (lines)"); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 822 | if (print_entries == 0) { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 823 | sig_winch_handler(SIGWINCH); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 824 | signal(SIGWINCH, sig_winch_handler); |
| 825 | } else |
| 826 | signal(SIGWINCH, SIG_DFL); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 827 | break; |
| 828 | case 'E': |
| 829 | if (nr_counters > 1) { |
| 830 | int i; |
| 831 | |
| 832 | fprintf(stderr, "\nAvailable events:"); |
| 833 | for (i = 0; i < nr_counters; i++) |
| 834 | fprintf(stderr, "\n\t%d %s", i, event_name(i)); |
| 835 | |
| 836 | prompt_integer(&sym_counter, "Enter details event counter"); |
| 837 | |
| 838 | if (sym_counter >= nr_counters) { |
| 839 | fprintf(stderr, "Sorry, no such event, using %s.\n", event_name(0)); |
| 840 | sym_counter = 0; |
| 841 | sleep(1); |
| 842 | } |
| 843 | } else sym_counter = 0; |
| 844 | break; |
| 845 | case 'f': |
| 846 | prompt_integer(&count_filter, "Enter display event count filter"); |
| 847 | break; |
| 848 | case 'F': |
| 849 | prompt_percent(&sym_pcnt_filter, "Enter details display event filter (percent)"); |
| 850 | break; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 851 | case 'K': |
| 852 | hide_kernel_symbols = !hide_kernel_symbols; |
| 853 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 854 | case 'q': |
| 855 | case 'Q': |
| 856 | printf("exiting.\n"); |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 857 | if (dump_symtab) |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 858 | perf_session__fprintf_dsos(session, stderr); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 859 | exit(0); |
| 860 | case 's': |
| 861 | prompt_symbol(&sym_filter_entry, "Enter details symbol"); |
| 862 | break; |
| 863 | case 'S': |
| 864 | if (!sym_filter_entry) |
| 865 | break; |
| 866 | else { |
| 867 | struct sym_entry *syme = sym_filter_entry; |
| 868 | |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 869 | pthread_mutex_lock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 870 | sym_filter_entry = NULL; |
| 871 | __zero_source_counters(syme); |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 872 | pthread_mutex_unlock(&syme->src->lock); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 873 | } |
| 874 | break; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 875 | case 'U': |
| 876 | hide_user_symbols = !hide_user_symbols; |
| 877 | break; |
Mike Galbraith | 46ab976 | 2009-07-24 10:09:50 +0200 | [diff] [blame] | 878 | case 'w': |
| 879 | display_weighted = ~display_weighted; |
| 880 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 881 | case 'z': |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 882 | zero = !zero; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 883 | break; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 884 | default: |
| 885 | break; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 889 | static void *display_thread(void *arg __used) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 890 | { |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 891 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 892 | struct termios tc, save; |
| 893 | int delay_msecs, c; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 894 | struct perf_session *session = (struct perf_session *) arg; |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 895 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 896 | tcgetattr(0, &save); |
| 897 | tc = save; |
| 898 | tc.c_lflag &= ~(ICANON | ECHO); |
| 899 | tc.c_cc[VMIN] = 0; |
| 900 | tc.c_cc[VTIME] = 0; |
Mike Galbraith | 091bd2e | 2009-08-04 10:21:23 +0200 | [diff] [blame] | 901 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 902 | repeat: |
| 903 | delay_msecs = delay_secs * 1000; |
| 904 | tcsetattr(0, TCSANOW, &tc); |
| 905 | /* trash return*/ |
| 906 | getc(stdin); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 907 | |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 908 | do { |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 909 | print_sym_table(); |
Frederic Weisbecker | 0f5486b | 2009-06-04 20:48:04 +0200 | [diff] [blame] | 910 | } while (!poll(&stdin_poll, 1, delay_msecs) == 1); |
| 911 | |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 912 | c = getc(stdin); |
| 913 | tcsetattr(0, TCSAFLUSH, &save); |
| 914 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 915 | handle_keypress(session, c); |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 916 | goto repeat; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 917 | |
| 918 | return NULL; |
| 919 | } |
| 920 | |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 921 | /* Tag samples to be skipped. */ |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 922 | static const char *skip_symbols[] = { |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 923 | "default_idle", |
| 924 | "cpu_idle", |
| 925 | "enter_idle", |
| 926 | "exit_idle", |
| 927 | "mwait_idle", |
Arnaldo Carvalho de Melo | 59b9005 | 2009-07-26 19:06:19 -0300 | [diff] [blame] | 928 | "mwait_idle_with_hints", |
Arnaldo Carvalho de Melo | 8357275 | 2009-09-25 15:02:39 -0700 | [diff] [blame] | 929 | "poll_idle", |
Anton Blanchard | 3a3393e | 2009-07-01 09:00:47 +1000 | [diff] [blame] | 930 | "ppc64_runlatch_off", |
| 931 | "pseries_dedicated_idle_sleep", |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 932 | NULL |
| 933 | }; |
| 934 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 935 | static int symbol_filter(struct map *map, struct symbol *sym) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 936 | { |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 937 | struct sym_entry *syme; |
| 938 | const char *name = sym->name; |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 939 | int i; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 940 | |
Anton Blanchard | 3a3393e | 2009-07-01 09:00:47 +1000 | [diff] [blame] | 941 | /* |
| 942 | * ppc64 uses function descriptors and appends a '.' to the |
| 943 | * start of every instruction address. Remove it. |
| 944 | */ |
| 945 | if (name[0] == '.') |
| 946 | name++; |
| 947 | |
Arnaldo Carvalho de Melo | de04687 | 2009-05-28 14:55:41 -0300 | [diff] [blame] | 948 | if (!strcmp(name, "_text") || |
| 949 | !strcmp(name, "_etext") || |
| 950 | !strcmp(name, "_sinittext") || |
| 951 | !strncmp("init_module", name, 11) || |
| 952 | !strncmp("cleanup_module", name, 14) || |
| 953 | strstr(name, "_text_start") || |
| 954 | strstr(name, "_text_end")) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 955 | return 1; |
| 956 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 957 | syme = symbol__priv(sym); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 958 | syme->map = map; |
Arnaldo Carvalho de Melo | b269876 | 2009-11-17 18:38:02 -0200 | [diff] [blame] | 959 | syme->src = NULL; |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 960 | |
| 961 | if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter)) { |
| 962 | /* schedule initial sym_filter_entry setup */ |
| 963 | sym_filter_entry_sched = syme; |
| 964 | sym_filter = NULL; |
| 965 | } |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 966 | |
Anton Blanchard | 2ab5208 | 2009-07-01 09:00:46 +1000 | [diff] [blame] | 967 | for (i = 0; skip_symbols[i]; i++) { |
| 968 | if (!strcmp(skip_symbols[i], name)) { |
| 969 | syme->skip = 1; |
| 970 | break; |
| 971 | } |
| 972 | } |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 973 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 974 | if (!syme->skip) |
| 975 | syme->name_len = strlen(sym->name); |
| 976 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 977 | return 0; |
| 978 | } |
| 979 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 980 | static void event__process_sample(const event_t *self, |
| 981 | struct perf_session *session, int counter) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 982 | { |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 983 | u64 ip = self->ip.ip; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 984 | struct sym_entry *syme; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 985 | struct addr_location al; |
Arnaldo Carvalho de Melo | 41a37e2 | 2010-06-04 08:02:07 -0300 | [diff] [blame] | 986 | struct sample_data data; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 987 | struct machine *machine; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 988 | u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 989 | |
Arnaldo Carvalho de Melo | 24bfef0 | 2010-01-21 13:04:43 -0200 | [diff] [blame] | 990 | ++samples; |
| 991 | |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 992 | switch (origin) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 993 | case PERF_RECORD_MISC_USER: |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 994 | ++us_samples; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 995 | if (hide_user_symbols) |
| 996 | return; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 997 | machine = perf_session__find_host_machine(session); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 998 | break; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 999 | case PERF_RECORD_MISC_KERNEL: |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1000 | ++kernel_samples; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 1001 | if (hide_kernel_symbols) |
| 1002 | return; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1003 | machine = perf_session__find_host_machine(session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1004 | break; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1005 | case PERF_RECORD_MISC_GUEST_KERNEL: |
| 1006 | ++guest_kernel_samples; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1007 | machine = perf_session__find_machine(session, self->ip.pid); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1008 | break; |
| 1009 | case PERF_RECORD_MISC_GUEST_USER: |
| 1010 | ++guest_us_samples; |
| 1011 | /* |
| 1012 | * TODO: we don't process guest user from host side |
| 1013 | * except simple counting. |
| 1014 | */ |
| 1015 | return; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1016 | default: |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1017 | return; |
| 1018 | } |
| 1019 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1020 | if (!machine && perf_guest) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1021 | pr_err("Can't find guest [%d]'s kernel information\n", |
| 1022 | self->ip.pid); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1026 | if (self->header.misc & PERF_RECORD_MISC_EXACT_IP) |
Peter Zijlstra | 1676b8a | 2010-03-04 14:19:36 +0100 | [diff] [blame] | 1027 | exact_samples++; |
| 1028 | |
Arnaldo Carvalho de Melo | 41a37e2 | 2010-06-04 08:02:07 -0300 | [diff] [blame] | 1029 | if (event__preprocess_sample(self, session, &al, &data, |
| 1030 | symbol_filter) < 0 || |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 1031 | al.filtered) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 1032 | return; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1033 | |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 1034 | if (al.sym == NULL) { |
| 1035 | /* |
| 1036 | * As we do lazy loading of symtabs we only will know if the |
| 1037 | * specified vmlinux file is invalid when we actually have a |
| 1038 | * hit in kernel space and then try to load it. So if we get |
| 1039 | * here and there are _no_ symbols in the DSO backing the |
| 1040 | * kernel map, bail out. |
| 1041 | * |
| 1042 | * We may never get here, for instance, if we use -K/ |
| 1043 | * --hide-kernel-symbols, even if the user specifies an |
| 1044 | * invalid --vmlinux ;-) |
| 1045 | */ |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1046 | if (al.map == machine->vmlinux_maps[MAP__FUNCTION] && |
Arnaldo Carvalho de Melo | 72b8fa1 | 2010-01-27 21:05:49 -0200 | [diff] [blame] | 1047 | RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) { |
| 1048 | pr_err("The %s file can't be used\n", |
| 1049 | symbol_conf.vmlinux_name); |
| 1050 | exit(1); |
| 1051 | } |
| 1052 | |
| 1053 | return; |
| 1054 | } |
| 1055 | |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 1056 | /* let's see, whether we need to install initial sym_filter_entry */ |
| 1057 | if (sym_filter_entry_sched) { |
| 1058 | sym_filter_entry = sym_filter_entry_sched; |
| 1059 | sym_filter_entry_sched = NULL; |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 1060 | if (parse_source(sym_filter_entry) < 0) { |
| 1061 | struct symbol *sym = sym_entry__symbol(sym_filter_entry); |
| 1062 | |
| 1063 | pr_err("Can't annotate %s", sym->name); |
| 1064 | if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) { |
| 1065 | 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] | 1066 | machine__fprintf_vmlinux_path(machine, stderr); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 1067 | } else |
| 1068 | pr_err(".\n"); |
| 1069 | exit(1); |
| 1070 | } |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 1071 | } |
| 1072 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 1073 | syme = symbol__priv(al.sym); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1074 | if (!syme->skip) { |
| 1075 | syme->count[counter]++; |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 1076 | syme->origin = origin; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1077 | record_precise_ip(syme, counter, ip); |
| 1078 | pthread_mutex_lock(&active_symbols_lock); |
| 1079 | if (list_empty(&syme->node) || !syme->node.next) |
| 1080 | __list_insert_active_sym(syme); |
| 1081 | pthread_mutex_unlock(&active_symbols_lock); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1085 | struct mmap_data { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1086 | int counter; |
| 1087 | void *base; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1088 | int mask; |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1089 | unsigned int prev; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1090 | }; |
| 1091 | |
| 1092 | static unsigned int mmap_read_head(struct mmap_data *md) |
| 1093 | { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 1094 | struct perf_event_mmap_page *pc = md->base; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1095 | int head; |
| 1096 | |
| 1097 | head = pc->data_head; |
| 1098 | rmb(); |
| 1099 | |
| 1100 | return head; |
| 1101 | } |
| 1102 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1103 | static void perf_session__mmap_read_counter(struct perf_session *self, |
| 1104 | struct mmap_data *md) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1105 | { |
| 1106 | unsigned int head = mmap_read_head(md); |
| 1107 | unsigned int old = md->prev; |
| 1108 | unsigned char *data = md->base + page_size; |
| 1109 | int diff; |
| 1110 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1111 | /* |
| 1112 | * If we're further behind than half the buffer, there's a chance |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 1113 | * the writer will bite our tail and mess up the samples under us. |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1114 | * |
| 1115 | * If we somehow ended up ahead of the head, we got messed up. |
| 1116 | * |
| 1117 | * In either case, truncate and restart at head. |
| 1118 | */ |
| 1119 | diff = head - old; |
| 1120 | if (diff > md->mask / 2 || diff < 0) { |
Mike Galbraith | f4f0b41 | 2009-10-13 14:57:20 +0200 | [diff] [blame] | 1121 | fprintf(stderr, "WARNING: failed to keep up with mmap data.\n"); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1122 | |
| 1123 | /* |
| 1124 | * head points to a known good entry, start there. |
| 1125 | */ |
| 1126 | old = head; |
| 1127 | } |
| 1128 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1129 | for (; old != head;) { |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1130 | event_t *event = (event_t *)&data[old & md->mask]; |
| 1131 | |
| 1132 | event_t event_copy; |
| 1133 | |
Ingo Molnar | 6f06ccb | 2009-04-20 15:22:22 +0200 | [diff] [blame] | 1134 | size_t size = event->header.size; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1135 | |
| 1136 | /* |
| 1137 | * Event straddles the mmap boundary -- header should always |
| 1138 | * be inside due to u64 alignment of output. |
| 1139 | */ |
| 1140 | if ((old & md->mask) + size != ((old + size) & md->mask)) { |
| 1141 | unsigned int offset = old; |
| 1142 | unsigned int len = min(sizeof(*event), size), cpy; |
| 1143 | void *dst = &event_copy; |
| 1144 | |
| 1145 | do { |
| 1146 | cpy = min(md->mask + 1 - (offset & md->mask), len); |
| 1147 | memcpy(dst, &data[offset & md->mask], cpy); |
| 1148 | offset += cpy; |
| 1149 | dst += cpy; |
| 1150 | len -= cpy; |
| 1151 | } while (len); |
| 1152 | |
| 1153 | event = &event_copy; |
| 1154 | } |
| 1155 | |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1156 | if (event->header.type == PERF_RECORD_SAMPLE) |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 1157 | event__process_sample(event, self, md->counter); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1158 | else |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1159 | event__process(event, self); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1160 | old += size; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | md->prev = old; |
| 1164 | } |
| 1165 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1166 | static struct pollfd *event_array; |
| 1167 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
Mike Galbraith | c2990a2 | 2009-05-24 08:35:49 +0200 | [diff] [blame] | 1168 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1169 | static void perf_session__mmap_read(struct perf_session *self) |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1170 | { |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1171 | int i, counter, thread_index; |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1172 | |
| 1173 | for (i = 0; i < nr_cpus; i++) { |
| 1174 | for (counter = 0; counter < nr_counters; counter++) |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1175 | for (thread_index = 0; |
| 1176 | thread_index < thread_num; |
| 1177 | thread_index++) { |
| 1178 | perf_session__mmap_read_counter(self, |
| 1179 | &mmap_array[i][counter][thread_index]); |
| 1180 | } |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1184 | int nr_poll; |
| 1185 | int group_fd; |
| 1186 | |
| 1187 | static void start_counter(int i, int counter) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1188 | { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 1189 | struct perf_event_attr *attr; |
Mike Galbraith | 0fdc7e6 | 2009-07-21 10:30:36 +0200 | [diff] [blame] | 1190 | int cpu; |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1191 | int thread_index; |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1192 | |
| 1193 | cpu = profile_cpu; |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1194 | if (target_tid == -1 && profile_cpu == -1) |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 1195 | cpu = cpumap[i]; |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1196 | |
| 1197 | attr = attrs + counter; |
| 1198 | |
| 1199 | attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 1200 | |
| 1201 | if (freq) { |
| 1202 | attr->sample_type |= PERF_SAMPLE_PERIOD; |
| 1203 | attr->freq = 1; |
| 1204 | attr->sample_freq = freq; |
| 1205 | } |
| 1206 | |
Mike Galbraith | 0fdc7e6 | 2009-07-21 10:30:36 +0200 | [diff] [blame] | 1207 | attr->inherit = (cpu < 0) && inherit; |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1208 | attr->mmap = 1; |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1209 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1210 | for (thread_index = 0; thread_index < thread_num; thread_index++) { |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1211 | try_again: |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1212 | fd[i][counter][thread_index] = sys_perf_event_open(attr, |
| 1213 | all_tids[thread_index], cpu, group_fd, 0); |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1214 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1215 | if (fd[i][counter][thread_index] < 0) { |
| 1216 | int err = errno; |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1217 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1218 | if (err == EPERM || err == EACCES) |
| 1219 | die("No permission - are you root?\n"); |
| 1220 | /* |
| 1221 | * If it's cycles then fall back to hrtimer |
| 1222 | * based cpu-clock-tick sw counter, which |
| 1223 | * is always available even if no PMU support: |
| 1224 | */ |
| 1225 | if (attr->type == PERF_TYPE_HARDWARE |
| 1226 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1227 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1228 | if (verbose) |
| 1229 | warning(" ... trying to fall back to cpu-clock-ticks\n"); |
Ingo Molnar | 3da297a | 2009-06-07 17:39:02 +0200 | [diff] [blame] | 1230 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1231 | attr->type = PERF_TYPE_SOFTWARE; |
| 1232 | attr->config = PERF_COUNT_SW_CPU_CLOCK; |
| 1233 | goto try_again; |
| 1234 | } |
| 1235 | printf("\n"); |
| 1236 | error("perfcounter syscall returned with %d (%s)\n", |
| 1237 | fd[i][counter][thread_index], strerror(err)); |
| 1238 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
| 1239 | exit(-1); |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1240 | } |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1241 | assert(fd[i][counter][thread_index] >= 0); |
| 1242 | fcntl(fd[i][counter][thread_index], F_SETFL, O_NONBLOCK); |
| 1243 | |
| 1244 | /* |
| 1245 | * First counter acts as the group leader: |
| 1246 | */ |
| 1247 | if (group && group_fd == -1) |
| 1248 | group_fd = fd[i][counter][thread_index]; |
| 1249 | |
| 1250 | event_array[nr_poll].fd = fd[i][counter][thread_index]; |
| 1251 | event_array[nr_poll].events = POLLIN; |
| 1252 | nr_poll++; |
| 1253 | |
| 1254 | mmap_array[i][counter][thread_index].counter = counter; |
| 1255 | mmap_array[i][counter][thread_index].prev = 0; |
| 1256 | mmap_array[i][counter][thread_index].mask = mmap_pages*page_size - 1; |
| 1257 | mmap_array[i][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, |
| 1258 | PROT_READ, MAP_SHARED, fd[i][counter][thread_index], 0); |
| 1259 | if (mmap_array[i][counter][thread_index].base == MAP_FAILED) |
| 1260 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1261 | } |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static int __cmd_top(void) |
| 1265 | { |
| 1266 | pthread_t thread; |
| 1267 | int i, counter; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1268 | int ret; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1269 | /* |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 1270 | * FIXME: perf_session__new should allow passing a O_MMAP, so that all this |
| 1271 | * 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] | 1272 | */ |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 1273 | struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false); |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 1274 | if (session == NULL) |
| 1275 | return -ENOMEM; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1276 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1277 | if (target_tid != -1) |
| 1278 | event__synthesize_thread(target_tid, event__process, session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1279 | else |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1280 | event__synthesize_threads(event__process, session); |
Arnaldo Carvalho de Melo | 5b2bb75 | 2009-10-26 19:23:19 -0200 | [diff] [blame] | 1281 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1282 | for (i = 0; i < nr_cpus; i++) { |
| 1283 | group_fd = -1; |
Ingo Molnar | 716c69f | 2009-06-07 17:31:52 +0200 | [diff] [blame] | 1284 | for (counter = 0; counter < nr_counters; counter++) |
| 1285 | start_counter(i, counter); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1286 | } |
| 1287 | |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1288 | /* Wait for a minimal set of events before starting the snapshot */ |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1289 | poll(&event_array[0], nr_poll, 100); |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1290 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1291 | perf_session__mmap_read(session); |
Frederic Weisbecker | 2f01190 | 2009-06-06 23:10:43 +0200 | [diff] [blame] | 1292 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1293 | if (pthread_create(&thread, NULL, display_thread, session)) { |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1294 | printf("Could not create display thread.\n"); |
| 1295 | exit(-1); |
| 1296 | } |
| 1297 | |
| 1298 | if (realtime_prio) { |
| 1299 | struct sched_param param; |
| 1300 | |
| 1301 | param.sched_priority = realtime_prio; |
| 1302 | if (sched_setscheduler(0, SCHED_FIFO, ¶m)) { |
| 1303 | printf("Could not set realtime priority.\n"); |
| 1304 | exit(-1); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | while (1) { |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 1309 | int hits = samples; |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1310 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 1311 | perf_session__mmap_read(session); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1312 | |
Ingo Molnar | 2debbc8 | 2009-06-05 14:29:10 +0200 | [diff] [blame] | 1313 | if (hits == samples) |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1314 | ret = poll(event_array, nr_poll, 100); |
| 1315 | } |
| 1316 | |
| 1317 | return 0; |
| 1318 | } |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1319 | |
| 1320 | static const char * const top_usage[] = { |
| 1321 | "perf top [<options>]", |
| 1322 | NULL |
| 1323 | }; |
| 1324 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1325 | static const struct option options[] = { |
| 1326 | OPT_CALLBACK('e', "event", NULL, "event", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1327 | "event selector. use 'perf list' to list available events", |
| 1328 | parse_events), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1329 | OPT_INTEGER('c', "count", &default_interval, |
| 1330 | "event period to sample"), |
| 1331 | OPT_INTEGER('p', "pid", &target_pid, |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1332 | "profile events on existing process id"), |
| 1333 | OPT_INTEGER('t', "tid", &target_tid, |
| 1334 | "profile events on existing thread id"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1335 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
| 1336 | "system-wide collection from all CPUs"), |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 1337 | OPT_STRING('C', "cpu", &cpu_list, "cpu", |
| 1338 | "list of cpus to monitor"), |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 1339 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 1340 | "file", "vmlinux pathname"), |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 1341 | OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols, |
| 1342 | "hide kernel symbols"), |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 1343 | OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1344 | OPT_INTEGER('r', "realtime", &realtime_prio, |
| 1345 | "collect data with this RT SCHED_FIFO priority"), |
Mike Galbraith | db20c00 | 2009-05-26 15:25:34 +0200 | [diff] [blame] | 1346 | OPT_INTEGER('d', "delay", &delay_secs, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1347 | "number of seconds to delay between refreshes"), |
| 1348 | OPT_BOOLEAN('D', "dump-symtab", &dump_symtab, |
| 1349 | "dump the symbol table used for profiling"), |
Ingo Molnar | 6e53cdf | 2009-06-04 08:53:05 +0200 | [diff] [blame] | 1350 | OPT_INTEGER('f', "count-filter", &count_filter, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1351 | "only display functions with more events than this"), |
| 1352 | OPT_BOOLEAN('g', "group", &group, |
| 1353 | "put the counters into a counter group"), |
Mike Galbraith | 0fdc7e6 | 2009-07-21 10:30:36 +0200 | [diff] [blame] | 1354 | OPT_BOOLEAN('i', "inherit", &inherit, |
| 1355 | "child tasks inherit counters"), |
Mike Galbraith | 923c42c | 2009-07-22 20:36:03 +0200 | [diff] [blame] | 1356 | OPT_STRING('s', "sym-annotate", &sym_filter, "symbol name", |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 1357 | "symbol to annotate"), |
Anton Blanchard | 1f208ea | 2009-07-01 09:00:44 +1000 | [diff] [blame] | 1358 | OPT_BOOLEAN('z', "zero", &zero, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1359 | "zero history across updates"), |
Ingo Molnar | 6e53cdf | 2009-06-04 08:53:05 +0200 | [diff] [blame] | 1360 | OPT_INTEGER('F', "freq", &freq, |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1361 | "profile at this frequency"), |
Ingo Molnar | 6e53cdf | 2009-06-04 08:53:05 +0200 | [diff] [blame] | 1362 | OPT_INTEGER('E', "entries", &print_entries, |
| 1363 | "display this many functions"), |
Arnaldo Carvalho de Melo | 8ffcda1 | 2009-11-16 21:45:24 -0200 | [diff] [blame] | 1364 | OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols, |
| 1365 | "hide user symbols"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1366 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | 3da297a | 2009-06-07 17:39:02 +0200 | [diff] [blame] | 1367 | "be more verbose (show counter open errors, etc)"), |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1368 | OPT_END() |
| 1369 | }; |
| 1370 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 1371 | int cmd_top(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1372 | { |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 1373 | int counter; |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1374 | int i,j; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1375 | |
| 1376 | page_size = sysconf(_SC_PAGE_SIZE); |
| 1377 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1378 | argc = parse_options(argc, argv, options, top_usage, 0); |
| 1379 | if (argc) |
| 1380 | usage_with_options(top_usage, options); |
| 1381 | |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1382 | if (target_pid != -1) { |
| 1383 | target_tid = target_pid; |
| 1384 | thread_num = find_all_tid(target_pid, &all_tids); |
| 1385 | if (thread_num <= 0) { |
| 1386 | fprintf(stderr, "Can't find all threads of pid %d\n", |
| 1387 | target_pid); |
| 1388 | usage_with_options(top_usage, options); |
| 1389 | } |
| 1390 | } else { |
| 1391 | all_tids=malloc(sizeof(pid_t)); |
| 1392 | if (!all_tids) |
| 1393 | return -ENOMEM; |
| 1394 | |
| 1395 | all_tids[0] = target_tid; |
| 1396 | thread_num = 1; |
| 1397 | } |
| 1398 | |
| 1399 | for (i = 0; i < MAX_NR_CPUS; i++) { |
| 1400 | for (j = 0; j < MAX_COUNTERS; j++) { |
| 1401 | fd[i][j] = malloc(sizeof(int)*thread_num); |
Zhang, Yanmin | 5a10317 | 2010-03-25 19:59:01 -0300 | [diff] [blame] | 1402 | mmap_array[i][j] = zalloc( |
Zhang, Yanmin | d6d901c | 2010-03-18 11:36:05 -0300 | [diff] [blame] | 1403 | sizeof(struct mmap_data)*thread_num); |
| 1404 | if (!fd[i][j] || !mmap_array[i][j]) |
| 1405 | return -ENOMEM; |
| 1406 | } |
| 1407 | } |
| 1408 | event_array = malloc( |
| 1409 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); |
| 1410 | if (!event_array) |
| 1411 | return -ENOMEM; |
| 1412 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1413 | /* CPU and PID are mutually exclusive */ |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 1414 | if (target_tid > 0 && cpu_list) { |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1415 | printf("WARNING: PID switch overriding CPU\n"); |
| 1416 | sleep(1); |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 1417 | cpu_list = NULL; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1420 | if (!nr_counters) |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1421 | nr_counters = 1; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1422 | |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 1423 | symbol_conf.priv_size = (sizeof(struct sym_entry) + |
| 1424 | (nr_counters + 1) * sizeof(unsigned long)); |
Kirill Smelkov | 6cff0e8 | 2010-02-03 16:52:08 -0200 | [diff] [blame] | 1425 | |
| 1426 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 1427 | if (symbol__init() < 0) |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 1428 | return -1; |
Arnaldo Carvalho de Melo | 5a8e5a3 | 2009-11-17 18:38:01 -0200 | [diff] [blame] | 1429 | |
Frederic Weisbecker | 2f335a0 | 2009-06-05 19:31:01 +0200 | [diff] [blame] | 1430 | if (delay_secs < 1) |
| 1431 | delay_secs = 1; |
| 1432 | |
Mike Galbraith | 7e4ff9e | 2009-10-12 07:56:03 +0200 | [diff] [blame] | 1433 | /* |
| 1434 | * User specified count overrides default frequency. |
| 1435 | */ |
| 1436 | if (default_interval) |
| 1437 | freq = 0; |
| 1438 | else if (freq) { |
| 1439 | default_interval = freq; |
| 1440 | } else { |
| 1441 | fprintf(stderr, "frequency and count are zero, aborting\n"); |
| 1442 | exit(EXIT_FAILURE); |
| 1443 | } |
| 1444 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1445 | /* |
| 1446 | * Fill in the ones not specifically initialized via -c: |
| 1447 | */ |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1448 | for (counter = 0; counter < nr_counters; counter++) { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1449 | if (attrs[counter].sample_period) |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1450 | continue; |
| 1451 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 1452 | attrs[counter].sample_period = default_interval; |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1453 | } |
| 1454 | |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 1455 | if (target_tid != -1) |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1456 | nr_cpus = 1; |
Paul Mackerras | a12b51c | 2010-03-10 20:36:09 +1100 | [diff] [blame] | 1457 | else |
Stephane Eranian | c45c6ea | 2010-05-28 12:00:01 +0200 | [diff] [blame] | 1458 | nr_cpus = read_cpu_map(cpu_list); |
| 1459 | |
| 1460 | if (nr_cpus < 1) |
| 1461 | usage_with_options(top_usage, options); |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1462 | |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 1463 | get_term_dimensions(&winsize); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 1464 | if (print_entries == 0) { |
Arnaldo Carvalho de Melo | 13cc507 | 2009-11-17 15:40:54 -0200 | [diff] [blame] | 1465 | update_print_entries(&winsize); |
Arnaldo Carvalho de Melo | 3b6ed98 | 2009-11-16 19:30:27 -0200 | [diff] [blame] | 1466 | signal(SIGWINCH, sig_winch_handler); |
| 1467 | } |
| 1468 | |
Ingo Molnar | b456bae | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 1469 | return __cmd_top(); |
| 1470 | } |