[PATCH V13 01/12] perf tools: change machine__findnew_thread() to set thread pid

2013-08-27 Thread Adrian Hunter
Add a new parameter for 'pid' to machine__findnew_thread().
Change callers to pass 'pid' when it is known.

Note that callers sometimes want to find the main thread
which has the memory maps.  The main thread has tid == pid
so the usage in that case is:

machine__findnew_thread(machine, pid, pid)

whereas the usage to find the specific thread is:

machine__findnew_thread(machine, pid, tid)

Signed-off-by: Adrian Hunter 
Acked-by: David Ahern 
---
 tools/perf/builtin-inject.c |  2 +-
 tools/perf/builtin-kmem.c   |  3 ++-
 tools/perf/builtin-kvm.c|  2 +-
 tools/perf/builtin-lock.c   |  3 ++-
 tools/perf/builtin-sched.c  | 20 +++-
 tools/perf/builtin-script.c |  3 ++-
 tools/perf/builtin-trace.c  | 10 +++---
 tools/perf/tests/code-reading.c |  4 ++--
 tools/perf/tests/hists_link.c   |  3 ++-
 tools/perf/util/build-id.c  |  7 +--
 tools/perf/util/event.c |  3 ++-
 tools/perf/util/machine.c   | 22 +++---
 tools/perf/util/machine.h   |  3 ++-
 tools/perf/util/session.c   |  2 +-
 14 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 1d8de2e..0d4ae1d 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -198,7 +198,7 @@ static int perf_event__inject_buildid(struct perf_tool 
*tool,
 
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
-   thread = machine__findnew_thread(machine, event->ip.pid);
+   thread = machine__findnew_thread(machine, event->ip.pid, event->ip.pid);
if (thread == NULL) {
pr_err("problem processing %d event, skipping it.\n",
   event->header.type);
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index b49f5c5..c324778 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -305,7 +305,8 @@ static int process_sample_event(struct perf_tool *tool 
__maybe_unused,
struct perf_evsel *evsel,
struct machine *machine)
 {
-   struct thread *thread = machine__findnew_thread(machine, event->ip.pid);
+   struct thread *thread = machine__findnew_thread(machine, event->ip.pid,
+   event->ip.pid);
 
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6cd4de5..47b3540 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -815,7 +815,7 @@ static int process_sample_event(struct perf_tool *tool,
if (skip_sample(kvm, sample))
return 0;
 
-   thread = machine__findnew_thread(machine, sample->tid);
+   thread = machine__findnew_thread(machine, sample->pid, sample->tid);
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
event->header.type);
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 76543a4..ee33ba2 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -805,7 +805,8 @@ static int process_sample_event(struct perf_tool *tool 
__maybe_unused,
struct perf_evsel *evsel,
struct machine *machine)
 {
-   struct thread *thread = machine__findnew_thread(machine, sample->tid);
+   struct thread *thread = machine__findnew_thread(machine, sample->pid,
+   sample->tid);
 
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index f809cc7..d8c51b2 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -724,8 +724,10 @@ static int replay_fork_event(struct perf_sched *sched,
 {
struct thread *child, *parent;
 
-   child = machine__findnew_thread(machine, event->fork.tid);
-   parent = machine__findnew_thread(machine, event->fork.ptid);
+   child = machine__findnew_thread(machine, event->fork.pid,
+   event->fork.tid);
+   parent = machine__findnew_thread(machine, event->fork.ppid,
+event->fork.ptid);
 
if (child == NULL || parent == NULL) {
pr_debug("thread does not exist on fork event: child %p, parent 
%p\n",
@@ -934,8 +936,8 @@ static int latency_switch_event(struct perf_sched *sched,
return -1;
}
 
-   sched_out = machine__findnew_thread(machine, prev_pid);
-   sched_in = machine__findnew_thread(machine, next_pid);
+   sched_out = machine__findnew_thread(machine, 0, prev_pid);
+   sched_in = machine__findnew_thread(machine, 0, next_pid);
 
out_events = 

[PATCH V13 01/12] perf tools: change machine__findnew_thread() to set thread pid

2013-08-27 Thread Adrian Hunter
Add a new parameter for 'pid' to machine__findnew_thread().
Change callers to pass 'pid' when it is known.

Note that callers sometimes want to find the main thread
which has the memory maps.  The main thread has tid == pid
so the usage in that case is:

machine__findnew_thread(machine, pid, pid)

whereas the usage to find the specific thread is:

machine__findnew_thread(machine, pid, tid)

Signed-off-by: Adrian Hunter adrian.hun...@intel.com
Acked-by: David Ahern dsah...@gmail.com
---
 tools/perf/builtin-inject.c |  2 +-
 tools/perf/builtin-kmem.c   |  3 ++-
 tools/perf/builtin-kvm.c|  2 +-
 tools/perf/builtin-lock.c   |  3 ++-
 tools/perf/builtin-sched.c  | 20 +++-
 tools/perf/builtin-script.c |  3 ++-
 tools/perf/builtin-trace.c  | 10 +++---
 tools/perf/tests/code-reading.c |  4 ++--
 tools/perf/tests/hists_link.c   |  3 ++-
 tools/perf/util/build-id.c  |  7 +--
 tools/perf/util/event.c |  3 ++-
 tools/perf/util/machine.c   | 22 +++---
 tools/perf/util/machine.h   |  3 ++-
 tools/perf/util/session.c   |  2 +-
 14 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 1d8de2e..0d4ae1d 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -198,7 +198,7 @@ static int perf_event__inject_buildid(struct perf_tool 
*tool,
 
cpumode = event-header.misc  PERF_RECORD_MISC_CPUMODE_MASK;
 
-   thread = machine__findnew_thread(machine, event-ip.pid);
+   thread = machine__findnew_thread(machine, event-ip.pid, event-ip.pid);
if (thread == NULL) {
pr_err(problem processing %d event, skipping it.\n,
   event-header.type);
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index b49f5c5..c324778 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -305,7 +305,8 @@ static int process_sample_event(struct perf_tool *tool 
__maybe_unused,
struct perf_evsel *evsel,
struct machine *machine)
 {
-   struct thread *thread = machine__findnew_thread(machine, event-ip.pid);
+   struct thread *thread = machine__findnew_thread(machine, event-ip.pid,
+   event-ip.pid);
 
if (thread == NULL) {
pr_debug(problem processing %d event, skipping it.\n,
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6cd4de5..47b3540 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -815,7 +815,7 @@ static int process_sample_event(struct perf_tool *tool,
if (skip_sample(kvm, sample))
return 0;
 
-   thread = machine__findnew_thread(machine, sample-tid);
+   thread = machine__findnew_thread(machine, sample-pid, sample-tid);
if (thread == NULL) {
pr_debug(problem processing %d event, skipping it.\n,
event-header.type);
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 76543a4..ee33ba2 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -805,7 +805,8 @@ static int process_sample_event(struct perf_tool *tool 
__maybe_unused,
struct perf_evsel *evsel,
struct machine *machine)
 {
-   struct thread *thread = machine__findnew_thread(machine, sample-tid);
+   struct thread *thread = machine__findnew_thread(machine, sample-pid,
+   sample-tid);
 
if (thread == NULL) {
pr_debug(problem processing %d event, skipping it.\n,
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index f809cc7..d8c51b2 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -724,8 +724,10 @@ static int replay_fork_event(struct perf_sched *sched,
 {
struct thread *child, *parent;
 
-   child = machine__findnew_thread(machine, event-fork.tid);
-   parent = machine__findnew_thread(machine, event-fork.ptid);
+   child = machine__findnew_thread(machine, event-fork.pid,
+   event-fork.tid);
+   parent = machine__findnew_thread(machine, event-fork.ppid,
+event-fork.ptid);
 
if (child == NULL || parent == NULL) {
pr_debug(thread does not exist on fork event: child %p, parent 
%p\n,
@@ -934,8 +936,8 @@ static int latency_switch_event(struct perf_sched *sched,
return -1;
}
 
-   sched_out = machine__findnew_thread(machine, prev_pid);
-   sched_in = machine__findnew_thread(machine, next_pid);
+   sched_out = machine__findnew_thread(machine, 0, prev_pid);
+   sched_in = machine__findnew_thread(machine, 0, next_pid);
 
out_events =