diff options
author | Jiri Olsa <jolsa@kernel.org> | 2016-12-12 11:35:41 +0100 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-15 16:25:45 -0300 |
commit | 38af91f01de0e160c17ae380acb5bab5d51066f4 (patch) | |
tree | 3225cf99867dccf856ca842da5a029d182c2dd6b /tools/perf/util | |
parent | 83c2e4f3968d6871eed295f2f5675d3d70b01afa (diff) | |
download | op-kernel-dev-38af91f01de0e160c17ae380acb5bab5d51066f4.zip op-kernel-dev-38af91f01de0e160c17ae380acb5bab5d51066f4.tar.gz |
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/perf/util')
-rw-r--r-- | tools/perf/util/thread_map.c | 22 | ||||
-rw-r--r-- | tools/perf/util/thread_map.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 40585f5..f9eab20 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) return false; } + +int thread_map__remove(struct thread_map *threads, int idx) +{ + int i; + + if (threads->nr < 1) + return -EINVAL; + + if (idx >= threads->nr) + return -EINVAL; + + /* + * Free the 'idx' item and shift the rest up. + */ + free(threads->map[idx].comm); + + for (i = idx; i < threads->nr - 1; i++) + threads->map[i] = threads->map[i + 1]; + + threads->nr--; + return 0; +} diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index bd3b971..ea0ef08 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) void thread_map__read_comms(struct thread_map *threads); bool thread_map__has(struct thread_map *threads, pid_t pid); +int thread_map__remove(struct thread_map *threads, int idx); #endif /* __PERF_THREAD_MAP_H */ |