diff options
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r-- | tools/perf/builtin-kmem.c | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 93c67bf53d2c..924a9518931a 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -92,23 +92,18 @@ static void setup_cpunode_map(void) | |||
92 | if (!dir1) | 92 | if (!dir1) |
93 | return; | 93 | return; |
94 | 94 | ||
95 | while (true) { | 95 | while ((dent1 = readdir(dir1)) != NULL) { |
96 | dent1 = readdir(dir1); | 96 | if (dent1->d_type != DT_DIR || |
97 | if (!dent1) | 97 | sscanf(dent1->d_name, "node%u", &mem) < 1) |
98 | break; | ||
99 | |||
100 | if (sscanf(dent1->d_name, "node%u", &mem) < 1) | ||
101 | continue; | 98 | continue; |
102 | 99 | ||
103 | snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name); | 100 | snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name); |
104 | dir2 = opendir(buf); | 101 | dir2 = opendir(buf); |
105 | if (!dir2) | 102 | if (!dir2) |
106 | continue; | 103 | continue; |
107 | while (true) { | 104 | while ((dent2 = readdir(dir2)) != NULL) { |
108 | dent2 = readdir(dir2); | 105 | if (dent2->d_type != DT_LNK || |
109 | if (!dent2) | 106 | sscanf(dent2->d_name, "cpu%u", &cpu) < 1) |
110 | break; | ||
111 | if (sscanf(dent2->d_name, "cpu%u", &cpu) < 1) | ||
112 | continue; | 107 | continue; |
113 | cpunode_map[cpu] = mem; | 108 | cpunode_map[cpu] = mem; |
114 | } | 109 | } |
@@ -321,11 +316,8 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
321 | 316 | ||
322 | event__parse_sample(event, session->sample_type, &data); | 317 | event__parse_sample(event, session->sample_type, &data); |
323 | 318 | ||
324 | dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", | 319 | dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc, |
325 | event->header.misc, | 320 | data.pid, data.tid, data.ip, data.period); |
326 | data.pid, data.tid, | ||
327 | (void *)(long)data.ip, | ||
328 | (long long)data.period); | ||
329 | 321 | ||
330 | thread = perf_session__findnew(session, event->ip.pid); | 322 | thread = perf_session__findnew(session, event->ip.pid); |
331 | if (thread == NULL) { | 323 | if (thread == NULL) { |
@@ -342,22 +334,9 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
342 | return 0; | 334 | return 0; |
343 | } | 335 | } |
344 | 336 | ||
345 | static int sample_type_check(struct perf_session *session) | ||
346 | { | ||
347 | if (!(session->sample_type & PERF_SAMPLE_RAW)) { | ||
348 | fprintf(stderr, | ||
349 | "No trace sample to read. Did you call perf record " | ||
350 | "without -R?"); | ||
351 | return -1; | ||
352 | } | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static struct perf_event_ops event_ops = { | 337 | static struct perf_event_ops event_ops = { |
358 | .process_sample_event = process_sample_event, | 338 | .sample = process_sample_event, |
359 | .process_comm_event = event__process_comm, | 339 | .comm = event__process_comm, |
360 | .sample_type_check = sample_type_check, | ||
361 | }; | 340 | }; |
362 | 341 | ||
363 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) | 342 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
@@ -390,7 +369,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
390 | if (is_caller) { | 369 | if (is_caller) { |
391 | addr = data->call_site; | 370 | addr = data->call_site; |
392 | if (!raw_ip) | 371 | if (!raw_ip) |
393 | sym = map_groups__find_function(&session->kmaps, session, addr, NULL); | 372 | sym = map_groups__find_function(&session->kmaps, addr, NULL); |
394 | } else | 373 | } else |
395 | addr = data->ptr; | 374 | addr = data->ptr; |
396 | 375 | ||
@@ -504,11 +483,14 @@ static void sort_result(void) | |||
504 | 483 | ||
505 | static int __cmd_kmem(void) | 484 | static int __cmd_kmem(void) |
506 | { | 485 | { |
507 | int err; | 486 | int err = -EINVAL; |
508 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); | 487 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); |
509 | if (session == NULL) | 488 | if (session == NULL) |
510 | return -ENOMEM; | 489 | return -ENOMEM; |
511 | 490 | ||
491 | if (!perf_session__has_traces(session, "kmem record")) | ||
492 | goto out_delete; | ||
493 | |||
512 | setup_pager(); | 494 | setup_pager(); |
513 | err = perf_session__process_events(session, &event_ops); | 495 | err = perf_session__process_events(session, &event_ops); |
514 | if (err != 0) | 496 | if (err != 0) |