Skip to content

Commit 99d725f

Browse files
ahunter6acmel
authored andcommitted
perf tools: Add pid to struct thread
Record pid on struct thread. The member is named 'pid_' to avoid confusion with the 'tid' member which was previously named 'pid'. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: David Ahern <dsahern@gmail.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1377522030-27870-3-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9e9716d commit 99d725f

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎tools/perf/util/machine.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size)
253253
return;
254254
}
255255

256-
static struct thread *__machine__findnew_thread(struct machine *machine, pid_t tid,
256+
static struct thread *__machine__findnew_thread(struct machine *machine,
257+
pid_t pid, pid_t tid,
257258
bool create)
258259
{
259260
struct rb_node **p = &machine->threads.rb_node;
@@ -265,15 +266,20 @@ static struct thread *__machine__findnew_thread(struct machine *machine, pid_t t
265266
* so most of the time we dont have to look up
266267
* the full rbtree:
267268
*/
268-
if (machine->last_match && machine->last_match->tid == tid)
269+
if (machine->last_match && machine->last_match->tid == tid) {
270+
if (pid && pid != machine->last_match->pid_)
271+
machine->last_match->pid_ = pid;
269272
return machine->last_match;
273+
}
270274

271275
while (*p != NULL) {
272276
parent = *p;
273277
th = rb_entry(parent, struct thread, rb_node);
274278

275279
if (th->tid == tid) {
276280
machine->last_match = th;
281+
if (pid && pid != th->pid_)
282+
th->pid_ = pid;
277283
return th;
278284
}
279285

@@ -286,7 +292,7 @@ static struct thread *__machine__findnew_thread(struct machine *machine, pid_t t
286292
if (!create)
287293
return NULL;
288294

289-
th = thread__new(tid);
295+
th = thread__new(pid, tid);
290296
if (th != NULL) {
291297
rb_link_node(&th->rb_node, parent, p);
292298
rb_insert_color(&th->rb_node, &machine->threads);
@@ -298,12 +304,12 @@ static struct thread *__machine__findnew_thread(struct machine *machine, pid_t t
298304

299305
struct thread *machine__findnew_thread(struct machine *machine, pid_t tid)
300306
{
301-
return __machine__findnew_thread(machine, tid, true);
307+
return __machine__findnew_thread(machine, 0, tid, true);
302308
}
303309

304310
struct thread *machine__find_thread(struct machine *machine, pid_t tid)
305311
{
306-
return __machine__findnew_thread(machine, tid, false);
312+
return __machine__findnew_thread(machine, 0, tid, false);
307313
}
308314

309315
int machine__process_comm_event(struct machine *machine, union perf_event *event)

‎tools/perf/util/thread.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
#include "util.h"
88
#include "debug.h"
99

10-
struct thread *thread__new(pid_t tid)
10+
struct thread *thread__new(pid_t pid, pid_t tid)
1111
{
1212
struct thread *self = zalloc(sizeof(*self));
1313

1414
if (self != NULL) {
1515
map_groups__init(&self->mg);
16+
self->pid_ = pid;
1617
self->tid = tid;
1718
self->ppid = -1;
1819
self->comm = malloc(32);

‎tools/perf/util/thread.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct thread {
1212
struct list_head node;
1313
};
1414
struct map_groups mg;
15+
pid_t pid_; /* Not all tools update this */
1516
pid_t tid;
1617
pid_t ppid;
1718
char shortname[3];
@@ -25,7 +26,7 @@ struct thread {
2526

2627
struct machine;
2728

28-
struct thread *thread__new(pid_t tid);
29+
struct thread *thread__new(pid_t pid, pid_t tid);
2930
void thread__delete(struct thread *self);
3031
static inline void thread__exited(struct thread *thread)
3132
{

0 commit comments

Comments
 (0)