diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2016-12-12 05:35:41 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-15 14:25:45 -0500 |
| commit | 38af91f01de0e160c17ae380acb5bab5d51066f4 (patch) | |
| tree | 3225cf99867dccf856ca842da5a029d182c2dd6b /tools | |
| parent | 83c2e4f3968d6871eed295f2f5675d3d70b01afa (diff) | |
perf thread_map: Add thread_map__remove function
Add thread_map__remove function to remove thread from thread map.
Add automated test also.
Committer notes:
Testing it:
# perf test "Remove thread map"
39: Remove thread map : Ok
# perf test -v "Remove thread map"
39: Remove thread map :
--- start ---
test child forked, pid 4483
2 threads: 4482, 4483
1 thread: 4483
0 thread:
test child finished with 0
---- end ----
Remove thread map: Ok
#
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/1481538943-21874-4-git-send-email-jolsa@kernel.org
[ Added stdlib.h, to get the free() declaration ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/tests/builtin-test.c | 4 | ||||
| -rw-r--r-- | tools/perf/tests/tests.h | 1 | ||||
| -rw-r--r-- | tools/perf/tests/thread-map.c | 44 | ||||
| -rw-r--r-- | tools/perf/util/thread_map.c | 22 | ||||
| -rw-r--r-- | tools/perf/util/thread_map.h | 1 |
5 files changed, 72 insertions, 0 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 23605202d4a1..a77dcc0d24e3 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
| @@ -186,6 +186,10 @@ static struct test generic_tests[] = { | |||
| 186 | .func = test__thread_map_synthesize, | 186 | .func = test__thread_map_synthesize, |
| 187 | }, | 187 | }, |
| 188 | { | 188 | { |
| 189 | .desc = "Remove thread map", | ||
| 190 | .func = test__thread_map_remove, | ||
| 191 | }, | ||
| 192 | { | ||
| 189 | .desc = "Synthesize cpu map", | 193 | .desc = "Synthesize cpu map", |
| 190 | .func = test__cpu_map_synthesize, | 194 | .func = test__cpu_map_synthesize, |
| 191 | }, | 195 | }, |
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 0d7b251305af..a512f0c8ff5b 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
| @@ -80,6 +80,7 @@ const char *test__bpf_subtest_get_desc(int subtest); | |||
| 80 | int test__bpf_subtest_get_nr(void); | 80 | int test__bpf_subtest_get_nr(void); |
| 81 | int test_session_topology(int subtest); | 81 | int test_session_topology(int subtest); |
| 82 | int test__thread_map_synthesize(int subtest); | 82 | int test__thread_map_synthesize(int subtest); |
| 83 | int test__thread_map_remove(int subtest); | ||
| 83 | int test__cpu_map_synthesize(int subtest); | 84 | int test__cpu_map_synthesize(int subtest); |
| 84 | int test__synthesize_stat_config(int subtest); | 85 | int test__synthesize_stat_config(int subtest); |
| 85 | int test__synthesize_stat(int subtest); | 86 | int test__synthesize_stat(int subtest); |
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index cee2a2cdc933..a4a4b4625ac3 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <stdlib.h> | ||
| 1 | #include <sys/types.h> | 2 | #include <sys/types.h> |
| 2 | #include <unistd.h> | 3 | #include <unistd.h> |
| 3 | #include <sys/prctl.h> | 4 | #include <sys/prctl.h> |
| @@ -93,3 +94,46 @@ int test__thread_map_synthesize(int subtest __maybe_unused) | |||
| 93 | 94 | ||
| 94 | return 0; | 95 | return 0; |
| 95 | } | 96 | } |
| 97 | |||
| 98 | int test__thread_map_remove(int subtest __maybe_unused) | ||
| 99 | { | ||
| 100 | struct thread_map *threads; | ||
| 101 | char *str; | ||
| 102 | int i; | ||
| 103 | |||
| 104 | TEST_ASSERT_VAL("failed to allocate map string", | ||
| 105 | asprintf(&str, "%d,%d", getpid(), getppid()) >= 0); | ||
| 106 | |||
| 107 | threads = thread_map__new_str(str, NULL, 0); | ||
| 108 | |||
| 109 | TEST_ASSERT_VAL("failed to allocate thread_map", | ||
| 110 | threads); | ||
| 111 | |||
| 112 | if (verbose) | ||
| 113 | thread_map__fprintf(threads, stderr); | ||
| 114 | |||
| 115 | TEST_ASSERT_VAL("failed to remove thread", | ||
| 116 | !thread_map__remove(threads, 0)); | ||
| 117 | |||
| 118 | TEST_ASSERT_VAL("thread_map count != 1", threads->nr == 1); | ||
| 119 | |||
| 120 | if (verbose) | ||
| 121 | thread_map__fprintf(threads, stderr); | ||
| 122 | |||
| 123 | TEST_ASSERT_VAL("failed to remove thread", | ||
| 124 | !thread_map__remove(threads, 0)); | ||
| 125 | |||
| 126 | TEST_ASSERT_VAL("thread_map count != 0", threads->nr == 0); | ||
| 127 | |||
| 128 | if (verbose) | ||
| 129 | thread_map__fprintf(threads, stderr); | ||
| 130 | |||
| 131 | TEST_ASSERT_VAL("failed to not remove thread", | ||
| 132 | thread_map__remove(threads, 0)); | ||
| 133 | |||
| 134 | for (i = 0; i < threads->nr; i++) | ||
| 135 | free(threads->map[i].comm); | ||
| 136 | |||
| 137 | free(threads); | ||
| 138 | return 0; | ||
| 139 | } | ||
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 40585f5b7027..f9eab200fd75 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c | |||
| @@ -448,3 +448,25 @@ bool thread_map__has(struct thread_map *threads, pid_t pid) | |||
| 448 | 448 | ||
| 449 | return false; | 449 | return false; |
| 450 | } | 450 | } |
| 451 | |||
| 452 | int thread_map__remove(struct thread_map *threads, int idx) | ||
| 453 | { | ||
| 454 | int i; | ||
| 455 | |||
| 456 | if (threads->nr < 1) | ||
| 457 | return -EINVAL; | ||
| 458 | |||
| 459 | if (idx >= threads->nr) | ||
| 460 | return -EINVAL; | ||
| 461 | |||
| 462 | /* | ||
| 463 | * Free the 'idx' item and shift the rest up. | ||
| 464 | */ | ||
| 465 | free(threads->map[idx].comm); | ||
| 466 | |||
| 467 | for (i = idx; i < threads->nr - 1; i++) | ||
| 468 | threads->map[i] = threads->map[i + 1]; | ||
| 469 | |||
| 470 | threads->nr--; | ||
| 471 | return 0; | ||
| 472 | } | ||
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index bd3b971588da..ea0ef08c6303 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h | |||
| @@ -58,4 +58,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread) | |||
| 58 | 58 | ||
| 59 | void thread_map__read_comms(struct thread_map *threads); | 59 | void thread_map__read_comms(struct thread_map *threads); |
| 60 | bool thread_map__has(struct thread_map *threads, pid_t pid); | 60 | bool thread_map__has(struct thread_map *threads, pid_t pid); |
| 61 | int thread_map__remove(struct thread_map *threads, int idx); | ||
| 61 | #endif /* __PERF_THREAD_MAP_H */ | 62 | #endif /* __PERF_THREAD_MAP_H */ |
