Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "perf.h" |
| 3 | |
| 4 | #include "util/util.h" |
| 5 | #include "util/cache.h" |
| 6 | #include "util/symbol.h" |
| 7 | #include "util/thread.h" |
| 8 | #include "util/header.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 9 | #include "util/session.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 10 | |
| 11 | #include "util/parse-options.h" |
| 12 | #include "util/trace-event.h" |
| 13 | |
| 14 | #include "util/debug.h" |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 15 | |
| 16 | #include <linux/rbtree.h> |
| 17 | |
| 18 | struct alloc_stat; |
| 19 | typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); |
| 20 | |
| 21 | static char const *input_name = "perf.data"; |
| 22 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 23 | static u64 sample_type; |
| 24 | |
| 25 | static int alloc_flag; |
| 26 | static int caller_flag; |
| 27 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 28 | static int alloc_lines = -1; |
| 29 | static int caller_lines = -1; |
| 30 | |
Li Zefan | 7707b6b | 2009-11-24 13:25:48 +0800 | [diff] [blame] | 31 | static bool raw_ip; |
| 32 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 33 | static char default_sort_order[] = "frag,hit,bytes"; |
| 34 | |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 35 | static int *cpunode_map; |
| 36 | static int max_cpu_num; |
| 37 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 38 | struct alloc_stat { |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 39 | u64 call_site; |
| 40 | u64 ptr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 41 | u64 bytes_req; |
| 42 | u64 bytes_alloc; |
| 43 | u32 hit; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 44 | u32 pingpong; |
| 45 | |
| 46 | short alloc_cpu; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 47 | |
| 48 | struct rb_node node; |
| 49 | }; |
| 50 | |
| 51 | static struct rb_root root_alloc_stat; |
| 52 | static struct rb_root root_alloc_sorted; |
| 53 | static struct rb_root root_caller_stat; |
| 54 | static struct rb_root root_caller_sorted; |
| 55 | |
| 56 | static unsigned long total_requested, total_allocated; |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 57 | static unsigned long nr_allocs, nr_cross_allocs; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 58 | |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 59 | #define PATH_SYS_NODE "/sys/devices/system/node" |
| 60 | |
| 61 | static void init_cpunode_map(void) |
| 62 | { |
| 63 | FILE *fp; |
| 64 | int i; |
| 65 | |
| 66 | fp = fopen("/sys/devices/system/cpu/kernel_max", "r"); |
| 67 | if (!fp) { |
| 68 | max_cpu_num = 4096; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | if (fscanf(fp, "%d", &max_cpu_num) < 1) |
| 73 | die("Failed to read 'kernel_max' from sysfs"); |
| 74 | max_cpu_num++; |
| 75 | |
| 76 | cpunode_map = calloc(max_cpu_num, sizeof(int)); |
| 77 | if (!cpunode_map) |
| 78 | die("calloc"); |
| 79 | for (i = 0; i < max_cpu_num; i++) |
| 80 | cpunode_map[i] = -1; |
| 81 | fclose(fp); |
| 82 | } |
| 83 | |
| 84 | static void setup_cpunode_map(void) |
| 85 | { |
| 86 | struct dirent *dent1, *dent2; |
| 87 | DIR *dir1, *dir2; |
| 88 | unsigned int cpu, mem; |
| 89 | char buf[PATH_MAX]; |
| 90 | |
| 91 | init_cpunode_map(); |
| 92 | |
| 93 | dir1 = opendir(PATH_SYS_NODE); |
| 94 | if (!dir1) |
| 95 | return; |
| 96 | |
| 97 | while (true) { |
| 98 | dent1 = readdir(dir1); |
| 99 | if (!dent1) |
| 100 | break; |
| 101 | |
| 102 | if (sscanf(dent1->d_name, "node%u", &mem) < 1) |
| 103 | continue; |
| 104 | |
| 105 | snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name); |
| 106 | dir2 = opendir(buf); |
| 107 | if (!dir2) |
| 108 | continue; |
| 109 | while (true) { |
| 110 | dent2 = readdir(dir2); |
| 111 | if (!dent2) |
| 112 | break; |
| 113 | if (sscanf(dent2->d_name, "cpu%u", &cpu) < 1) |
| 114 | continue; |
| 115 | cpunode_map[cpu] = mem; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 120 | static void insert_alloc_stat(unsigned long call_site, unsigned long ptr, |
| 121 | int bytes_req, int bytes_alloc, int cpu) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 122 | { |
| 123 | struct rb_node **node = &root_alloc_stat.rb_node; |
| 124 | struct rb_node *parent = NULL; |
| 125 | struct alloc_stat *data = NULL; |
| 126 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 127 | while (*node) { |
| 128 | parent = *node; |
| 129 | data = rb_entry(*node, struct alloc_stat, node); |
| 130 | |
| 131 | if (ptr > data->ptr) |
| 132 | node = &(*node)->rb_right; |
| 133 | else if (ptr < data->ptr) |
| 134 | node = &(*node)->rb_left; |
| 135 | else |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | if (data && data->ptr == ptr) { |
| 140 | data->hit++; |
| 141 | data->bytes_req += bytes_req; |
| 142 | data->bytes_alloc += bytes_req; |
| 143 | } else { |
| 144 | data = malloc(sizeof(*data)); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 145 | if (!data) |
| 146 | die("malloc"); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 147 | data->ptr = ptr; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 148 | data->pingpong = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 149 | data->hit = 1; |
| 150 | data->bytes_req = bytes_req; |
| 151 | data->bytes_alloc = bytes_alloc; |
| 152 | |
| 153 | rb_link_node(&data->node, parent, node); |
| 154 | rb_insert_color(&data->node, &root_alloc_stat); |
| 155 | } |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 156 | data->call_site = call_site; |
| 157 | data->alloc_cpu = cpu; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void insert_caller_stat(unsigned long call_site, |
| 161 | int bytes_req, int bytes_alloc) |
| 162 | { |
| 163 | struct rb_node **node = &root_caller_stat.rb_node; |
| 164 | struct rb_node *parent = NULL; |
| 165 | struct alloc_stat *data = NULL; |
| 166 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 167 | while (*node) { |
| 168 | parent = *node; |
| 169 | data = rb_entry(*node, struct alloc_stat, node); |
| 170 | |
| 171 | if (call_site > data->call_site) |
| 172 | node = &(*node)->rb_right; |
| 173 | else if (call_site < data->call_site) |
| 174 | node = &(*node)->rb_left; |
| 175 | else |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | if (data && data->call_site == call_site) { |
| 180 | data->hit++; |
| 181 | data->bytes_req += bytes_req; |
| 182 | data->bytes_alloc += bytes_req; |
| 183 | } else { |
| 184 | data = malloc(sizeof(*data)); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 185 | if (!data) |
| 186 | die("malloc"); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 187 | data->call_site = call_site; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 188 | data->pingpong = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 189 | data->hit = 1; |
| 190 | data->bytes_req = bytes_req; |
| 191 | data->bytes_alloc = bytes_alloc; |
| 192 | |
| 193 | rb_link_node(&data->node, parent, node); |
| 194 | rb_insert_color(&data->node, &root_caller_stat); |
| 195 | } |
| 196 | } |
| 197 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 198 | static void process_alloc_event(void *data, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 199 | struct event *event, |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 200 | int cpu, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 201 | u64 timestamp __used, |
| 202 | struct thread *thread __used, |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 203 | int node) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 204 | { |
| 205 | unsigned long call_site; |
| 206 | unsigned long ptr; |
| 207 | int bytes_req; |
| 208 | int bytes_alloc; |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 209 | int node1, node2; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 210 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 211 | ptr = raw_field_value(event, "ptr", data); |
| 212 | call_site = raw_field_value(event, "call_site", data); |
| 213 | bytes_req = raw_field_value(event, "bytes_req", data); |
| 214 | bytes_alloc = raw_field_value(event, "bytes_alloc", data); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 215 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 216 | insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, cpu); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 217 | insert_caller_stat(call_site, bytes_req, bytes_alloc); |
| 218 | |
| 219 | total_requested += bytes_req; |
| 220 | total_allocated += bytes_alloc; |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 221 | |
| 222 | if (node) { |
| 223 | node1 = cpunode_map[cpu]; |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 224 | node2 = raw_field_value(event, "node", data); |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 225 | if (node1 != node2) |
| 226 | nr_cross_allocs++; |
| 227 | } |
| 228 | nr_allocs++; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 231 | static int ptr_cmp(struct alloc_stat *, struct alloc_stat *); |
| 232 | static int callsite_cmp(struct alloc_stat *, struct alloc_stat *); |
| 233 | |
| 234 | static struct alloc_stat *search_alloc_stat(unsigned long ptr, |
| 235 | unsigned long call_site, |
| 236 | struct rb_root *root, |
| 237 | sort_fn_t sort_fn) |
| 238 | { |
| 239 | struct rb_node *node = root->rb_node; |
| 240 | struct alloc_stat key = { .ptr = ptr, .call_site = call_site }; |
| 241 | |
| 242 | while (node) { |
| 243 | struct alloc_stat *data; |
| 244 | int cmp; |
| 245 | |
| 246 | data = rb_entry(node, struct alloc_stat, node); |
| 247 | |
| 248 | cmp = sort_fn(&key, data); |
| 249 | if (cmp < 0) |
| 250 | node = node->rb_left; |
| 251 | else if (cmp > 0) |
| 252 | node = node->rb_right; |
| 253 | else |
| 254 | return data; |
| 255 | } |
| 256 | return NULL; |
| 257 | } |
| 258 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 259 | static void process_free_event(void *data, |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 260 | struct event *event, |
| 261 | int cpu, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 262 | u64 timestamp __used, |
| 263 | struct thread *thread __used) |
| 264 | { |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 265 | unsigned long ptr; |
| 266 | struct alloc_stat *s_alloc, *s_caller; |
| 267 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 268 | ptr = raw_field_value(event, "ptr", data); |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 269 | |
| 270 | s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); |
| 271 | if (!s_alloc) |
| 272 | return; |
| 273 | |
| 274 | if (cpu != s_alloc->alloc_cpu) { |
| 275 | s_alloc->pingpong++; |
| 276 | |
| 277 | s_caller = search_alloc_stat(0, s_alloc->call_site, |
| 278 | &root_caller_stat, callsite_cmp); |
| 279 | assert(s_caller); |
| 280 | s_caller->pingpong++; |
| 281 | } |
| 282 | s_alloc->alloc_cpu = -1; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static void |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 286 | process_raw_event(event_t *raw_event __used, void *data, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 287 | int cpu, u64 timestamp, struct thread *thread) |
| 288 | { |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 289 | struct event *event; |
| 290 | int type; |
| 291 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 292 | type = trace_parse_common_type(data); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 293 | event = trace_find_event(type); |
| 294 | |
| 295 | if (!strcmp(event->name, "kmalloc") || |
| 296 | !strcmp(event->name, "kmem_cache_alloc")) { |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 297 | process_alloc_event(data, event, cpu, timestamp, thread, 0); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | |
| 301 | if (!strcmp(event->name, "kmalloc_node") || |
| 302 | !strcmp(event->name, "kmem_cache_alloc_node")) { |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 303 | process_alloc_event(data, event, cpu, timestamp, thread, 1); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 304 | return; |
| 305 | } |
| 306 | |
| 307 | if (!strcmp(event->name, "kfree") || |
| 308 | !strcmp(event->name, "kmem_cache_free")) { |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 309 | process_free_event(data, event, cpu, timestamp, thread); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | } |
| 313 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame^] | 314 | static int process_sample_event(event_t *event, struct perf_session *session) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 315 | { |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 316 | struct sample_data data; |
| 317 | struct thread *thread; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 318 | |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 319 | memset(&data, 0, sizeof(data)); |
| 320 | data.time = -1; |
| 321 | data.cpu = -1; |
| 322 | data.period = 1; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 323 | |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 324 | event__parse_sample(event, sample_type, &data); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 325 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 326 | dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 327 | event->header.misc, |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 328 | data.pid, data.tid, |
| 329 | (void *)(long)data.ip, |
| 330 | (long long)data.period); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 331 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame^] | 332 | thread = perf_session__findnew(session, event->ip.pid); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 333 | if (thread == NULL) { |
| 334 | pr_debug("problem processing %d event, skipping it.\n", |
| 335 | event->header.type); |
| 336 | return -1; |
| 337 | } |
| 338 | |
| 339 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 340 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 341 | process_raw_event(event, data.raw_data, data.cpu, |
Xiao Guangrong | d8bd9e0 | 2009-12-07 12:06:29 +0800 | [diff] [blame] | 342 | data.time, thread); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int sample_type_check(u64 type) |
| 348 | { |
| 349 | sample_type = type; |
| 350 | |
| 351 | if (!(sample_type & PERF_SAMPLE_RAW)) { |
| 352 | fprintf(stderr, |
| 353 | "No trace sample to read. Did you call perf record " |
| 354 | "without -R?"); |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 361 | static struct perf_event_ops event_ops = { |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 362 | .process_sample_event = process_sample_event, |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 363 | .process_comm_event = event__process_comm, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 364 | .sample_type_check = sample_type_check, |
| 365 | }; |
| 366 | |
| 367 | static int read_events(void) |
| 368 | { |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 369 | int err; |
| 370 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); |
| 371 | |
| 372 | if (session == NULL) |
| 373 | return -ENOMEM; |
| 374 | |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 375 | err = perf_session__process_events(session, &event_ops); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 376 | perf_session__delete(session); |
| 377 | return err; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
| 381 | { |
| 382 | if (n_alloc == 0) |
| 383 | return 0.0; |
| 384 | else |
| 385 | return 100.0 - (100.0 * n_req / n_alloc); |
| 386 | } |
| 387 | |
| 388 | static void __print_result(struct rb_root *root, int n_lines, int is_caller) |
| 389 | { |
| 390 | struct rb_node *next; |
| 391 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 392 | printf("%.102s\n", graph_dotted_line); |
| 393 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); |
| 394 | printf(" Total_alloc/Per | Total_req/Per | Hit | Ping-pong | Frag\n"); |
| 395 | printf("%.102s\n", graph_dotted_line); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 396 | |
| 397 | next = rb_first(root); |
| 398 | |
| 399 | while (next && n_lines--) { |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 400 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, |
| 401 | node); |
| 402 | struct symbol *sym = NULL; |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 403 | char buf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 404 | u64 addr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 405 | |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 406 | if (is_caller) { |
| 407 | addr = data->call_site; |
Li Zefan | 7707b6b | 2009-11-24 13:25:48 +0800 | [diff] [blame] | 408 | if (!raw_ip) |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 409 | sym = map_groups__find_function(kmaps, addr, NULL); |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 410 | } else |
| 411 | addr = data->ptr; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 412 | |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 413 | if (sym != NULL) |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 414 | snprintf(buf, sizeof(buf), "%s+%Lx", sym->name, |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 415 | addr - sym->start); |
| 416 | else |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 417 | snprintf(buf, sizeof(buf), "%#Lx", addr); |
| 418 | printf(" %-34s |", buf); |
Arnaldo Carvalho de Melo | 1b145ae | 2009-11-23 17:51:09 -0200 | [diff] [blame] | 419 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 420 | printf(" %9llu/%-5lu | %9llu/%-5lu | %6lu | %8lu | %6.3f%%\n", |
| 421 | (unsigned long long)data->bytes_alloc, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 422 | (unsigned long)data->bytes_alloc / data->hit, |
| 423 | (unsigned long long)data->bytes_req, |
| 424 | (unsigned long)data->bytes_req / data->hit, |
| 425 | (unsigned long)data->hit, |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 426 | (unsigned long)data->pingpong, |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 427 | fragmentation(data->bytes_req, data->bytes_alloc)); |
| 428 | |
| 429 | next = rb_next(next); |
| 430 | } |
| 431 | |
| 432 | if (n_lines == -1) |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 433 | printf(" ... | ... | ... | ... | ... | ... \n"); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 434 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 435 | printf("%.102s\n", graph_dotted_line); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void print_summary(void) |
| 439 | { |
| 440 | printf("\nSUMMARY\n=======\n"); |
| 441 | printf("Total bytes requested: %lu\n", total_requested); |
| 442 | printf("Total bytes allocated: %lu\n", total_allocated); |
| 443 | printf("Total bytes wasted on internal fragmentation: %lu\n", |
| 444 | total_allocated - total_requested); |
| 445 | printf("Internal fragmentation: %f%%\n", |
| 446 | fragmentation(total_requested, total_allocated)); |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 447 | printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void print_result(void) |
| 451 | { |
| 452 | if (caller_flag) |
| 453 | __print_result(&root_caller_sorted, caller_lines, 1); |
| 454 | if (alloc_flag) |
| 455 | __print_result(&root_alloc_sorted, alloc_lines, 0); |
| 456 | print_summary(); |
| 457 | } |
| 458 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 459 | struct sort_dimension { |
| 460 | const char name[20]; |
| 461 | sort_fn_t cmp; |
| 462 | struct list_head list; |
| 463 | }; |
| 464 | |
| 465 | static LIST_HEAD(caller_sort); |
| 466 | static LIST_HEAD(alloc_sort); |
| 467 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 468 | static void sort_insert(struct rb_root *root, struct alloc_stat *data, |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 469 | struct list_head *sort_list) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 470 | { |
| 471 | struct rb_node **new = &(root->rb_node); |
| 472 | struct rb_node *parent = NULL; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 473 | struct sort_dimension *sort; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 474 | |
| 475 | while (*new) { |
| 476 | struct alloc_stat *this; |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 477 | int cmp = 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 478 | |
| 479 | this = rb_entry(*new, struct alloc_stat, node); |
| 480 | parent = *new; |
| 481 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 482 | list_for_each_entry(sort, sort_list, list) { |
| 483 | cmp = sort->cmp(data, this); |
| 484 | if (cmp) |
| 485 | break; |
| 486 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 487 | |
| 488 | if (cmp > 0) |
| 489 | new = &((*new)->rb_left); |
| 490 | else |
| 491 | new = &((*new)->rb_right); |
| 492 | } |
| 493 | |
| 494 | rb_link_node(&data->node, parent, new); |
| 495 | rb_insert_color(&data->node, root); |
| 496 | } |
| 497 | |
| 498 | static void __sort_result(struct rb_root *root, struct rb_root *root_sorted, |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 499 | struct list_head *sort_list) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 500 | { |
| 501 | struct rb_node *node; |
| 502 | struct alloc_stat *data; |
| 503 | |
| 504 | for (;;) { |
| 505 | node = rb_first(root); |
| 506 | if (!node) |
| 507 | break; |
| 508 | |
| 509 | rb_erase(node, root); |
| 510 | data = rb_entry(node, struct alloc_stat, node); |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 511 | sort_insert(root_sorted, data, sort_list); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | static void sort_result(void) |
| 516 | { |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 517 | __sort_result(&root_alloc_stat, &root_alloc_sorted, &alloc_sort); |
| 518 | __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static int __cmd_kmem(void) |
| 522 | { |
| 523 | setup_pager(); |
| 524 | read_events(); |
| 525 | sort_result(); |
| 526 | print_result(); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static const char * const kmem_usage[] = { |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 532 | "perf kmem [<options>] {record|stat}", |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 533 | NULL |
| 534 | }; |
| 535 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 536 | static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 537 | { |
| 538 | if (l->ptr < r->ptr) |
| 539 | return -1; |
| 540 | else if (l->ptr > r->ptr) |
| 541 | return 1; |
| 542 | return 0; |
| 543 | } |
| 544 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 545 | static struct sort_dimension ptr_sort_dimension = { |
| 546 | .name = "ptr", |
| 547 | .cmp = ptr_cmp, |
| 548 | }; |
| 549 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 550 | static int callsite_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 551 | { |
| 552 | if (l->call_site < r->call_site) |
| 553 | return -1; |
| 554 | else if (l->call_site > r->call_site) |
| 555 | return 1; |
| 556 | return 0; |
| 557 | } |
| 558 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 559 | static struct sort_dimension callsite_sort_dimension = { |
| 560 | .name = "callsite", |
| 561 | .cmp = callsite_cmp, |
| 562 | }; |
| 563 | |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 564 | static int hit_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 565 | { |
| 566 | if (l->hit < r->hit) |
| 567 | return -1; |
| 568 | else if (l->hit > r->hit) |
| 569 | return 1; |
| 570 | return 0; |
| 571 | } |
| 572 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 573 | static struct sort_dimension hit_sort_dimension = { |
| 574 | .name = "hit", |
| 575 | .cmp = hit_cmp, |
| 576 | }; |
| 577 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 578 | static int bytes_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 579 | { |
| 580 | if (l->bytes_alloc < r->bytes_alloc) |
| 581 | return -1; |
| 582 | else if (l->bytes_alloc > r->bytes_alloc) |
| 583 | return 1; |
| 584 | return 0; |
| 585 | } |
| 586 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 587 | static struct sort_dimension bytes_sort_dimension = { |
| 588 | .name = "bytes", |
| 589 | .cmp = bytes_cmp, |
| 590 | }; |
| 591 | |
Pekka Enberg | f3ced7c | 2009-11-22 11:58:00 +0200 | [diff] [blame] | 592 | static int frag_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 593 | { |
| 594 | double x, y; |
| 595 | |
| 596 | x = fragmentation(l->bytes_req, l->bytes_alloc); |
| 597 | y = fragmentation(r->bytes_req, r->bytes_alloc); |
| 598 | |
| 599 | if (x < y) |
| 600 | return -1; |
| 601 | else if (x > y) |
| 602 | return 1; |
| 603 | return 0; |
| 604 | } |
| 605 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 606 | static struct sort_dimension frag_sort_dimension = { |
| 607 | .name = "frag", |
| 608 | .cmp = frag_cmp, |
| 609 | }; |
| 610 | |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 611 | static int pingpong_cmp(struct alloc_stat *l, struct alloc_stat *r) |
| 612 | { |
| 613 | if (l->pingpong < r->pingpong) |
| 614 | return -1; |
| 615 | else if (l->pingpong > r->pingpong) |
| 616 | return 1; |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static struct sort_dimension pingpong_sort_dimension = { |
| 621 | .name = "pingpong", |
| 622 | .cmp = pingpong_cmp, |
| 623 | }; |
| 624 | |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 625 | static struct sort_dimension *avail_sorts[] = { |
| 626 | &ptr_sort_dimension, |
| 627 | &callsite_sort_dimension, |
| 628 | &hit_sort_dimension, |
| 629 | &bytes_sort_dimension, |
| 630 | &frag_sort_dimension, |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 631 | &pingpong_sort_dimension, |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | #define NUM_AVAIL_SORTS \ |
| 635 | (int)(sizeof(avail_sorts) / sizeof(struct sort_dimension *)) |
| 636 | |
| 637 | static int sort_dimension__add(const char *tok, struct list_head *list) |
| 638 | { |
| 639 | struct sort_dimension *sort; |
| 640 | int i; |
| 641 | |
| 642 | for (i = 0; i < NUM_AVAIL_SORTS; i++) { |
| 643 | if (!strcmp(avail_sorts[i]->name, tok)) { |
| 644 | sort = malloc(sizeof(*sort)); |
| 645 | if (!sort) |
| 646 | die("malloc"); |
| 647 | memcpy(sort, avail_sorts[i], sizeof(*sort)); |
| 648 | list_add_tail(&sort->list, list); |
| 649 | return 0; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | return -1; |
| 654 | } |
| 655 | |
| 656 | static int setup_sorting(struct list_head *sort_list, const char *arg) |
| 657 | { |
| 658 | char *tok; |
| 659 | char *str = strdup(arg); |
| 660 | |
| 661 | if (!str) |
| 662 | die("strdup"); |
| 663 | |
| 664 | while (true) { |
| 665 | tok = strsep(&str, ","); |
| 666 | if (!tok) |
| 667 | break; |
| 668 | if (sort_dimension__add(tok, sort_list) < 0) { |
| 669 | error("Unknown --sort key: '%s'", tok); |
| 670 | return -1; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | free(str); |
| 675 | return 0; |
| 676 | } |
| 677 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 678 | static int parse_sort_opt(const struct option *opt __used, |
| 679 | const char *arg, int unset __used) |
| 680 | { |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 681 | if (!arg) |
| 682 | return -1; |
| 683 | |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 684 | if (caller_flag > alloc_flag) |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 685 | return setup_sorting(&caller_sort, arg); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 686 | else |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 687 | return setup_sorting(&alloc_sort, arg); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 692 | static int parse_caller_opt(const struct option *opt __used, |
Ingo Molnar | 7931241 | 2009-12-10 08:43:34 +0100 | [diff] [blame] | 693 | const char *arg __used, int unset __used) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 694 | { |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 695 | caller_flag = (alloc_flag + 1); |
| 696 | return 0; |
| 697 | } |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 698 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 699 | static int parse_alloc_opt(const struct option *opt __used, |
Ingo Molnar | 7931241 | 2009-12-10 08:43:34 +0100 | [diff] [blame] | 700 | const char *arg __used, int unset __used) |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 701 | { |
| 702 | alloc_flag = (caller_flag + 1); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int parse_line_opt(const struct option *opt __used, |
| 707 | const char *arg, int unset __used) |
| 708 | { |
| 709 | int lines; |
| 710 | |
| 711 | if (!arg) |
| 712 | return -1; |
| 713 | |
| 714 | lines = strtoul(arg, NULL, 10); |
| 715 | |
| 716 | if (caller_flag > alloc_flag) |
| 717 | caller_lines = lines; |
| 718 | else |
| 719 | alloc_lines = lines; |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static const struct option kmem_options[] = { |
| 725 | OPT_STRING('i', "input", &input_name, "file", |
| 726 | "input file name"), |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 727 | OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, |
| 728 | "show per-callsite statistics", |
| 729 | parse_caller_opt), |
| 730 | OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL, |
| 731 | "show per-allocation statistics", |
| 732 | parse_alloc_opt), |
Li Zefan | 29b3e15 | 2009-11-24 13:26:10 +0800 | [diff] [blame] | 733 | OPT_CALLBACK('s', "sort", NULL, "key[,key2...]", |
Li Zefan | 079d3f6 | 2009-11-24 13:26:55 +0800 | [diff] [blame] | 734 | "sort by keys: ptr, call_site, bytes, hit, pingpong, frag", |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 735 | parse_sort_opt), |
| 736 | OPT_CALLBACK('l', "line", NULL, "num", |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 737 | "show n lines", |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 738 | parse_line_opt), |
Li Zefan | 7707b6b | 2009-11-24 13:25:48 +0800 | [diff] [blame] | 739 | OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"), |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 740 | OPT_END() |
| 741 | }; |
| 742 | |
| 743 | static const char *record_args[] = { |
| 744 | "record", |
| 745 | "-a", |
| 746 | "-R", |
| 747 | "-M", |
| 748 | "-f", |
| 749 | "-c", "1", |
| 750 | "-e", "kmem:kmalloc", |
| 751 | "-e", "kmem:kmalloc_node", |
| 752 | "-e", "kmem:kfree", |
| 753 | "-e", "kmem:kmem_cache_alloc", |
| 754 | "-e", "kmem:kmem_cache_alloc_node", |
| 755 | "-e", "kmem:kmem_cache_free", |
| 756 | }; |
| 757 | |
| 758 | static int __cmd_record(int argc, const char **argv) |
| 759 | { |
| 760 | unsigned int rec_argc, i, j; |
| 761 | const char **rec_argv; |
| 762 | |
| 763 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
| 764 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 765 | |
| 766 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 767 | rec_argv[i] = strdup(record_args[i]); |
| 768 | |
| 769 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 770 | rec_argv[i] = argv[j]; |
| 771 | |
| 772 | return cmd_record(i, rec_argv, NULL); |
| 773 | } |
| 774 | |
| 775 | int cmd_kmem(int argc, const char **argv, const char *prefix __used) |
| 776 | { |
| 777 | symbol__init(0); |
| 778 | |
| 779 | argc = parse_options(argc, argv, kmem_options, kmem_usage, 0); |
| 780 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 781 | if (!argc) |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 782 | usage_with_options(kmem_usage, kmem_options); |
| 783 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 784 | if (!strncmp(argv[0], "rec", 3)) { |
| 785 | return __cmd_record(argc, argv); |
| 786 | } else if (!strcmp(argv[0], "stat")) { |
| 787 | setup_cpunode_map(); |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 788 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 789 | if (list_empty(&caller_sort)) |
| 790 | setup_sorting(&caller_sort, default_sort_order); |
| 791 | if (list_empty(&alloc_sort)) |
| 792 | setup_sorting(&alloc_sort, default_sort_order); |
Li Zefan | 7d0d394 | 2009-11-24 13:26:31 +0800 | [diff] [blame] | 793 | |
Li Zefan | 90b86a9 | 2009-12-10 15:21:57 +0800 | [diff] [blame] | 794 | return __cmd_kmem(); |
| 795 | } |
| 796 | |
| 797 | return 0; |
Li Zefan | ba77c9e | 2009-11-20 15:53:25 +0800 | [diff] [blame] | 798 | } |
| 799 | |