Re: [RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-09 Thread Namhyung Kim
On Thu, Oct 08, 2015 at 02:20:11PM +0200, Jiri Olsa wrote:
> On Fri, Oct 02, 2015 at 02:18:56PM +0900, Namhyung Kim wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> > index 674792e8fa2f..ad7c2a00bff8 100644
> > --- a/tools/perf/util/thread.c
> > +++ b/tools/perf/util/thread.c
> > @@ -160,6 +160,9 @@ int __thread__set_comm(struct thread *thread, const 
> > char *str, u64 timestamp,
> >  
> > /* Override the default :tid entry */
> > if (!thread->comm_set) {
> > +   if (!thread->start_time)
> > +   thread->start_time = timestamp;
> > +
> > err = comm__override(curr, str, timestamp, exec);
> > if (err)
> > return err;
> > @@ -266,6 +269,7 @@ int thread__fork(struct thread *thread, struct thread 
> > *parent, u64 timestamp)
> > }
> >  
> > thread->ppid = parent->tid;
> > +   thread->start_time = timestamp;
> > return thread__clone_map_groups(thread, parent);
> >  }
> >  
> > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> > index b8f794d97b75..97026a9660ec 100644
> > --- a/tools/perf/util/thread.h
> > +++ b/tools/perf/util/thread.h
> > @@ -28,6 +28,7 @@ struct thread {
> > booldead; /* thread is in dead_threads list */
> > struct list_headcomm_list;
> > u64 db_id;
> > +   u64 start_time;
> 
> introducing start_time could be in separate patch
> would ease up the review a bit

Will split.

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-09 Thread Namhyung Kim
On Thu, Oct 08, 2015 at 02:20:11PM +0200, Jiri Olsa wrote:
> On Fri, Oct 02, 2015 at 02:18:56PM +0900, Namhyung Kim wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> > index 674792e8fa2f..ad7c2a00bff8 100644
> > --- a/tools/perf/util/thread.c
> > +++ b/tools/perf/util/thread.c
> > @@ -160,6 +160,9 @@ int __thread__set_comm(struct thread *thread, const 
> > char *str, u64 timestamp,
> >  
> > /* Override the default :tid entry */
> > if (!thread->comm_set) {
> > +   if (!thread->start_time)
> > +   thread->start_time = timestamp;
> > +
> > err = comm__override(curr, str, timestamp, exec);
> > if (err)
> > return err;
> > @@ -266,6 +269,7 @@ int thread__fork(struct thread *thread, struct thread 
> > *parent, u64 timestamp)
> > }
> >  
> > thread->ppid = parent->tid;
> > +   thread->start_time = timestamp;
> > return thread__clone_map_groups(thread, parent);
> >  }
> >  
> > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> > index b8f794d97b75..97026a9660ec 100644
> > --- a/tools/perf/util/thread.h
> > +++ b/tools/perf/util/thread.h
> > @@ -28,6 +28,7 @@ struct thread {
> > booldead; /* thread is in dead_threads list */
> > struct list_headcomm_list;
> > u64 db_id;
> > +   u64 start_time;
> 
> introducing start_time could be in separate patch
> would ease up the review a bit

Will split.

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-08 Thread Jiri Olsa
On Fri, Oct 02, 2015 at 02:18:56PM +0900, Namhyung Kim wrote:

SNIP

> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> index 674792e8fa2f..ad7c2a00bff8 100644
> --- a/tools/perf/util/thread.c
> +++ b/tools/perf/util/thread.c
> @@ -160,6 +160,9 @@ int __thread__set_comm(struct thread *thread, const char 
> *str, u64 timestamp,
>  
>   /* Override the default :tid entry */
>   if (!thread->comm_set) {
> + if (!thread->start_time)
> + thread->start_time = timestamp;
> +
>   err = comm__override(curr, str, timestamp, exec);
>   if (err)
>   return err;
> @@ -266,6 +269,7 @@ int thread__fork(struct thread *thread, struct thread 
> *parent, u64 timestamp)
>   }
>  
>   thread->ppid = parent->tid;
> + thread->start_time = timestamp;
>   return thread__clone_map_groups(thread, parent);
>  }
>  
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index b8f794d97b75..97026a9660ec 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -28,6 +28,7 @@ struct thread {
>   booldead; /* thread is in dead_threads list */
>   struct list_headcomm_list;
>   u64 db_id;
> + u64 start_time;

introducing start_time could be in separate patch
would ease up the review a bit

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-08 Thread Jiri Olsa
On Fri, Oct 02, 2015 at 02:18:56PM +0900, Namhyung Kim wrote:

SNIP

> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> index 674792e8fa2f..ad7c2a00bff8 100644
> --- a/tools/perf/util/thread.c
> +++ b/tools/perf/util/thread.c
> @@ -160,6 +160,9 @@ int __thread__set_comm(struct thread *thread, const char 
> *str, u64 timestamp,
>  
>   /* Override the default :tid entry */
>   if (!thread->comm_set) {
> + if (!thread->start_time)
> + thread->start_time = timestamp;
> +
>   err = comm__override(curr, str, timestamp, exec);
>   if (err)
>   return err;
> @@ -266,6 +269,7 @@ int thread__fork(struct thread *thread, struct thread 
> *parent, u64 timestamp)
>   }
>  
>   thread->ppid = parent->tid;
> + thread->start_time = timestamp;
>   return thread__clone_map_groups(thread, parent);
>  }
>  
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index b8f794d97b75..97026a9660ec 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -28,6 +28,7 @@ struct thread {
>   booldead; /* thread is in dead_threads list */
>   struct list_headcomm_list;
>   u64 db_id;
> + u64 start_time;

introducing start_time could be in separate patch
would ease up the review a bit

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-01 Thread Namhyung Kim
With data file indexing is enabled, it needs to search thread based on
sample time since sample processing is done after other (task, comm and
mmap) events are processed.  This can be a problem if a session is very
long and pid is recycled - in that case it'll only see the last one.

So keep thread start time in it, and search thread based on the time.
This patch introduces machine__find{,new}_thread_by_time() function
for this.  It'll first search current (i.e. recent) thread rbtree and
then dead thread tree (and tid list).  If it couldn't find anyone,
it'll create a new (missing) thread.

The sample timestamp of 0 means that this is called from synthesized
event so just use current rbtree.  The timestamp will be -1 if sample
didn't record the timestamp so will see current threads automatically.

Cc: Frederic Weisbecker 
Signed-off-by: Namhyung Kim 
---
 tools/perf/tests/dwarf-unwind.c |   8 +--
 tools/perf/tests/hists_common.c |   3 +-
 tools/perf/tests/hists_link.c   |   2 +-
 tools/perf/util/event.c |   6 +-
 tools/perf/util/machine.c   | 126 +++-
 tools/perf/util/machine.h   |  10 +++-
 tools/perf/util/thread.c|   4 ++
 tools/perf/util/thread.h|   1 +
 8 files changed, 148 insertions(+), 12 deletions(-)

diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 40b36c462427..b9ca0a72fc4d 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -16,10 +16,10 @@
 
 static int mmap_handler(struct perf_tool *tool __maybe_unused,
union perf_event *event,
-   struct perf_sample *sample __maybe_unused,
+   struct perf_sample *sample,
struct machine *machine)
 {
-   return machine__process_mmap2_event(machine, event, NULL);
+   return machine__process_mmap2_event(machine, event, sample);
 }
 
 static int init_live_machine(struct machine *machine)
@@ -66,12 +66,10 @@ static int unwind_entry(struct unwind_entry *entry, void 
*arg)
 __attribute__ ((noinline))
 static int unwind_thread(struct thread *thread)
 {
-   struct perf_sample sample;
+   struct perf_sample sample = { .time = -1ULL, };
unsigned long cnt = 0;
int err = -1;
 
-   memset(, 0, sizeof(sample));
-
if (test__arch_unwind_sample(, thread)) {
pr_debug("failed to get unwind sample\n");
goto out;
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index ce80b274b097..1d657fa2830f 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -80,6 +80,7 @@ static struct {
 struct machine *setup_fake_machine(struct machines *machines)
 {
struct machine *machine = machines__find(machines, HOST_KERNEL_ID);
+   struct perf_sample sample = { .time = -1ULL, };
size_t i;
 
if (machine == NULL) {
@@ -114,7 +115,7 @@ struct machine *setup_fake_machine(struct machines 
*machines)
strcpy(fake_mmap_event.mmap.filename,
   fake_mmap_info[i].filename);
 
-   machine__process_mmap_event(machine, _mmap_event, NULL);
+   machine__process_mmap_event(machine, _mmap_event, );
}
 
for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 27bae90c9a95..cacc8617bf02 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -64,7 +64,7 @@ static int add_hist_entries(struct perf_evlist *evlist, 
struct machine *machine)
struct perf_evsel *evsel;
struct addr_location al;
struct hist_entry *he;
-   struct perf_sample sample = { .period = 1, };
+   struct perf_sample sample = { .period = 1, .time = -1ULL, };
size_t i = 0, k;
 
/*
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index cb98b5af9e17..3dff1b5cd4cc 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -9,6 +9,7 @@
 #include "strlist.h"
 #include "thread.h"
 #include "thread_map.h"
+#include "session.h"
 #include "symbol/kallsyms.h"
 
 static const char *perf_event__names[] = {
@@ -992,9 +993,10 @@ int perf_event__preprocess_sample(const union perf_event 
*event,
  struct perf_sample *sample)
 {
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
-   struct thread *thread = machine__findnew_thread(machine, sample->pid,
-   sample->tid);
+   struct thread *thread;
 
+   thread = machine__findnew_thread_by_time(machine, sample->pid,
+sample->tid, sample->time);
if (thread == NULL)
return -1;
 
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2b9fbe55c896..7cfaa2c3f131 100644
--- a/tools/perf/util/machine.c

[RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time()

2015-10-01 Thread Namhyung Kim
With data file indexing is enabled, it needs to search thread based on
sample time since sample processing is done after other (task, comm and
mmap) events are processed.  This can be a problem if a session is very
long and pid is recycled - in that case it'll only see the last one.

So keep thread start time in it, and search thread based on the time.
This patch introduces machine__find{,new}_thread_by_time() function
for this.  It'll first search current (i.e. recent) thread rbtree and
then dead thread tree (and tid list).  If it couldn't find anyone,
it'll create a new (missing) thread.

The sample timestamp of 0 means that this is called from synthesized
event so just use current rbtree.  The timestamp will be -1 if sample
didn't record the timestamp so will see current threads automatically.

Cc: Frederic Weisbecker 
Signed-off-by: Namhyung Kim 
---
 tools/perf/tests/dwarf-unwind.c |   8 +--
 tools/perf/tests/hists_common.c |   3 +-
 tools/perf/tests/hists_link.c   |   2 +-
 tools/perf/util/event.c |   6 +-
 tools/perf/util/machine.c   | 126 +++-
 tools/perf/util/machine.h   |  10 +++-
 tools/perf/util/thread.c|   4 ++
 tools/perf/util/thread.h|   1 +
 8 files changed, 148 insertions(+), 12 deletions(-)

diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
index 40b36c462427..b9ca0a72fc4d 100644
--- a/tools/perf/tests/dwarf-unwind.c
+++ b/tools/perf/tests/dwarf-unwind.c
@@ -16,10 +16,10 @@
 
 static int mmap_handler(struct perf_tool *tool __maybe_unused,
union perf_event *event,
-   struct perf_sample *sample __maybe_unused,
+   struct perf_sample *sample,
struct machine *machine)
 {
-   return machine__process_mmap2_event(machine, event, NULL);
+   return machine__process_mmap2_event(machine, event, sample);
 }
 
 static int init_live_machine(struct machine *machine)
@@ -66,12 +66,10 @@ static int unwind_entry(struct unwind_entry *entry, void 
*arg)
 __attribute__ ((noinline))
 static int unwind_thread(struct thread *thread)
 {
-   struct perf_sample sample;
+   struct perf_sample sample = { .time = -1ULL, };
unsigned long cnt = 0;
int err = -1;
 
-   memset(, 0, sizeof(sample));
-
if (test__arch_unwind_sample(, thread)) {
pr_debug("failed to get unwind sample\n");
goto out;
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index ce80b274b097..1d657fa2830f 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -80,6 +80,7 @@ static struct {
 struct machine *setup_fake_machine(struct machines *machines)
 {
struct machine *machine = machines__find(machines, HOST_KERNEL_ID);
+   struct perf_sample sample = { .time = -1ULL, };
size_t i;
 
if (machine == NULL) {
@@ -114,7 +115,7 @@ struct machine *setup_fake_machine(struct machines 
*machines)
strcpy(fake_mmap_event.mmap.filename,
   fake_mmap_info[i].filename);
 
-   machine__process_mmap_event(machine, _mmap_event, NULL);
+   machine__process_mmap_event(machine, _mmap_event, );
}
 
for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 27bae90c9a95..cacc8617bf02 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -64,7 +64,7 @@ static int add_hist_entries(struct perf_evlist *evlist, 
struct machine *machine)
struct perf_evsel *evsel;
struct addr_location al;
struct hist_entry *he;
-   struct perf_sample sample = { .period = 1, };
+   struct perf_sample sample = { .period = 1, .time = -1ULL, };
size_t i = 0, k;
 
/*
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index cb98b5af9e17..3dff1b5cd4cc 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -9,6 +9,7 @@
 #include "strlist.h"
 #include "thread.h"
 #include "thread_map.h"
+#include "session.h"
 #include "symbol/kallsyms.h"
 
 static const char *perf_event__names[] = {
@@ -992,9 +993,10 @@ int perf_event__preprocess_sample(const union perf_event 
*event,
  struct perf_sample *sample)
 {
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
-   struct thread *thread = machine__findnew_thread(machine, sample->pid,
-   sample->tid);
+   struct thread *thread;
 
+   thread = machine__findnew_thread_by_time(machine, sample->pid,
+sample->tid, sample->time);
if (thread == NULL)
return -1;
 
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index