aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-06-28 07:29:04 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-06-30 17:27:45 -0400
commita24020e6b7cf6eb8b75d8bca6b89870b1cee6ba7 (patch)
tree16e36c1b28e054b765b8f104ca9debbcf10de99e
parent7fa9b8fba0b55edd1ff5b8ea696ec75fc5f6194c (diff)
perf tools: Change cpu_map__fprintf output
Display cpu map in standard list form. (perf report -D output on perf stat data). before: 0x590 [0x18]: PERF_RECORD_CPU_MAP nr: 4 cpus: 0, 1, 2, 3 after: 0x590 [0x18]: PERF_RECORD_CPU_MAP: 0-3 Adding automated testcase. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1467113345-12669-4-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/tests/builtin-test.c4
-rw-r--r--tools/perf/tests/cpumap.c24
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/util/cpumap.c54
-rw-r--r--tools/perf/util/cpumap.h1
-rw-r--r--tools/perf/util/event.c2
6 files changed, 79 insertions, 7 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 5781c1640eae..07c14e9f6546 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -214,6 +214,10 @@ static struct test generic_tests[] = {
214 .func = test__backward_ring_buffer, 214 .func = test__backward_ring_buffer,
215 }, 215 },
216 { 216 {
217 .desc = "Test cpu map print",
218 .func = test__cpu_map_print,
219 },
220 {
217 .func = NULL, 221 .func = NULL,
218 }, 222 },
219}; 223};
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index 4cb6418a8ffc..c9ec5f83e42c 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -86,3 +86,27 @@ int test__cpu_map_synthesize(int subtest __maybe_unused)
86 cpu_map__put(cpus); 86 cpu_map__put(cpus);
87 return 0; 87 return 0;
88} 88}
89
90static int cpu_map_print(const char *str)
91{
92 struct cpu_map *map = cpu_map__new(str);
93 char buf[100];
94
95 if (!map)
96 return -1;
97
98 cpu_map__snprint(map, buf, sizeof(buf));
99 return !strcmp(buf, str);
100}
101
102int test__cpu_map_print(int subtest __maybe_unused)
103{
104 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1"));
105 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,5"));
106 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3,5,7,9,11,13,15,17,19,21-40"));
107 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("2-5"));
108 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
109 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
110 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1-10,12-20,22-30,32-40"));
111 return 0;
112}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index c57e72c826d2..52f969570c97 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -87,6 +87,7 @@ int test__synthesize_stat_round(int subtest);
87int test__event_update(int subtest); 87int test__event_update(int subtest);
88int test__event_times(int subtest); 88int test__event_times(int subtest);
89int test__backward_ring_buffer(int subtest); 89int test__backward_ring_buffer(int subtest);
90int test__cpu_map_print(int subtest);
90 91
91#if defined(__arm__) || defined(__aarch64__) 92#if defined(__arm__) || defined(__aarch64__)
92#ifdef HAVE_DWARF_UNWIND_SUPPORT 93#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 02d801670f30..15f83acac1b8 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -236,13 +236,12 @@ struct cpu_map *cpu_map__new_data(struct cpu_map_data *data)
236 236
237size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) 237size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp)
238{ 238{
239 int i; 239#define BUFSIZE 1024
240 size_t printed = fprintf(fp, "%d cpu%s: ", 240 char buf[BUFSIZE];
241 map->nr, map->nr > 1 ? "s" : "");
242 for (i = 0; i < map->nr; ++i)
243 printed += fprintf(fp, "%s%d", i ? ", " : "", map->map[i]);
244 241
245 return printed + fprintf(fp, "\n"); 242 cpu_map__snprint(map, buf, sizeof(buf));
243 return fprintf(fp, "%s\n", buf);
244#undef BUFSIZE
246} 245}
247 246
248struct cpu_map *cpu_map__dummy_new(void) 247struct cpu_map *cpu_map__dummy_new(void)
@@ -599,3 +598,46 @@ bool cpu_map__has(struct cpu_map *cpus, int cpu)
599 598
600 return false; 599 return false;
601} 600}
601
602size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size)
603{
604 int i, cpu, start = -1;
605 bool first = true;
606 size_t ret = 0;
607
608#define COMMA first ? "" : ","
609
610 for (i = 0; i < map->nr + 1; i++) {
611 bool last = i == map->nr;
612
613 cpu = last ? INT_MAX : map->map[i];
614
615 if (start == -1) {
616 start = i;
617 if (last) {
618 ret += snprintf(buf + ret, size - ret,
619 "%s%d", COMMA,
620 map->map[i]);
621 }
622 } else if (((i - start) != (cpu - map->map[start])) || last) {
623 int end = i - 1;
624
625 if (start == end) {
626 ret += snprintf(buf + ret, size - ret,
627 "%s%d", COMMA,
628 map->map[start]);
629 } else {
630 ret += snprintf(buf + ret, size - ret,
631 "%s%d-%d", COMMA,
632 map->map[start], map->map[end]);
633 }
634 first = false;
635 start = i;
636 }
637 }
638
639#undef COMMA
640
641 pr_debug("cpumask list: %s\n", buf);
642 return ret;
643}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 1a0a35073ce1..206dc550354a 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -19,6 +19,7 @@ struct cpu_map *cpu_map__empty_new(int nr);
19struct cpu_map *cpu_map__dummy_new(void); 19struct cpu_map *cpu_map__dummy_new(void);
20struct cpu_map *cpu_map__new_data(struct cpu_map_data *data); 20struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
21struct cpu_map *cpu_map__read(FILE *file); 21struct cpu_map *cpu_map__read(FILE *file);
22size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
22size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); 23size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
23int cpu_map__get_socket_id(int cpu); 24int cpu_map__get_socket_id(int cpu);
24int cpu_map__get_socket(struct cpu_map *map, int idx, void *data); 25int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 9b141f12329e..e20438b784be 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1092,7 +1092,7 @@ size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp)
1092 struct cpu_map *cpus = cpu_map__new_data(&event->cpu_map.data); 1092 struct cpu_map *cpus = cpu_map__new_data(&event->cpu_map.data);
1093 size_t ret; 1093 size_t ret;
1094 1094
1095 ret = fprintf(fp, " nr: "); 1095 ret = fprintf(fp, ": ");
1096 1096
1097 if (cpus) 1097 if (cpus)
1098 ret += cpu_map__fprintf(cpus, fp); 1098 ret += cpu_map__fprintf(cpus, fp);