| Date | Wed, 11 Dec 2013 11:19:08 -0300 | From | Arnaldo Carvalho de Melo <> | Subject | Re: [PATCH v0 14/71] perf tools: Add cpu to struct thread |
| |
Em Wed, Dec 11, 2013 at 02:36:26PM +0200, Alexander Shishkin escreveu: > From: Adrian Hunter <adrian.hunter@intel.com> > > Tools may wish to track on which cpu a thread > is running. Add 'cpu' to struct thread for > that purpose. Also add machine functions to > get / set the cpu for a tid. > > This will be used to determine the cpu when > decoding a per-thread Instruction Trace. > > > +++ b/tools/perf/util/machine.c > @@ -1412,3 +1412,29 @@ pid_t machine__get_thread_pid(struct machine *machine, pid_t tid) > > return thread->pid_; > } > + > +int machine__get_thread_cpu(struct machine *machine, pid_t tid, pid_t *pid) > +{ > + struct thread *thread = machine__find_thread(machine, tid); > + > + if (!thread) > + return -1; > + > + if (pid) > + *pid = thread->pid_; > + > + return thread->cpu; > +}
What is the problem with:
struct thread *thread = machine__find_thread(machine, tid); pid_t pid = thread->pid_; int cpu = thread->cpu;
In your case you'll have:
int pid; int cpu = machine__get_thread_cpu(machine, tid, &pid);
Which is slightly more compact, but then we end up with a function that from its name should just get a 'cpu' but also asks for the pid.
I think it is better to just use what we have (machine__find_thread), have a 'thread' variable and then use any of its members, directly.
- ARnaldo
|