Skip to content

Commit 04cb4fc

Browse files
committed
perf thread: Allow tools to register a thread->priv destructor
So that when thread__delete() runs it can be called and free stuff tools stashed into thread->priv, like 'perf trace' does and will use this new facility to plug some leaks. Added an assert(thread__priv_destructor == NULL) as suggested in Ian's review. Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/lkml/CAP-5=fV3Er=Ek8=iE=bSGbEBmM56_PJffMWot1g_5Bh8B5hO7A@mail.gmail.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3f6a74b commit 04cb4fc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tools/perf/util/thread.c

+13
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ struct thread *thread__new(pid_t pid, pid_t tid)
8080
return NULL;
8181
}
8282

83+
static void (*thread__priv_destructor)(void *priv);
84+
85+
void thread__set_priv_destructor(void (*destructor)(void *priv))
86+
{
87+
assert(thread__priv_destructor == NULL);
88+
89+
thread__priv_destructor = destructor;
90+
}
91+
8392
void thread__delete(struct thread *thread)
8493
{
8594
struct namespaces *namespaces, *tmp_namespaces;
@@ -112,6 +121,10 @@ void thread__delete(struct thread *thread)
112121
exit_rwsem(thread__namespaces_lock(thread));
113122
exit_rwsem(thread__comm_lock(thread));
114123
thread__free_stitch_list(thread);
124+
125+
if (thread__priv_destructor)
126+
thread__priv_destructor(thread__priv(thread));
127+
115128
RC_CHK_FREE(thread);
116129
}
117130

tools/perf/util/thread.h

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid);
7171
int thread__init_maps(struct thread *thread, struct machine *machine);
7272
void thread__delete(struct thread *thread);
7373

74+
void thread__set_priv_destructor(void (*destructor)(void *priv));
75+
7476
struct thread *thread__get(struct thread *thread);
7577
void thread__put(struct thread *thread);
7678

0 commit comments

Comments
 (0)