[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1431909055-21442-19-git-send-email-namhyung@kernel.org>
Date: Mon, 18 May 2015 09:30:33 +0900
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Jiri Olsa <jolsa@...hat.com>,
LKML <linux-kernel@...r.kernel.org>,
David Ahern <dsahern@...il.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Andi Kleen <andi@...stfloor.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Stephane Eranian <eranian@...gle.com>
Subject: [PATCH 18/40] perf tools: Introduce thread__find_addr_location_by_time() and friends
These new functions are for find appropriate map (and symbol) at the
given time when used with an indexed data file. This is based on the
fact that map_groups list is sorted by time in the previous patch.
Cc: Frederic Weisbecker <fweisbec@...il.com>
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
tools/perf/util/event.c | 59 +++++++++++++++++++++++++++++++++++++++--------
tools/perf/util/machine.c | 28 ++++++++++++++--------
tools/perf/util/session.h | 1 +
tools/perf/util/thread.c | 26 +++++++++++++++++++++
tools/perf/util/thread.h | 11 +++++++++
5 files changed, 106 insertions(+), 19 deletions(-)
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 0ad76b06cd48..bb391c20920d 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -832,16 +832,14 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
return machine__process_event(machine, event, sample);
}
-void thread__find_addr_map(struct thread *thread, u8 cpumode,
- enum map_type type, u64 addr,
- struct addr_location *al)
+static void map_groups__find_addr_map(struct map_groups *mg, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al)
{
- struct map_groups *mg = thread->mg;
struct machine *machine = mg->machine;
bool load_map = false;
al->machine = machine;
- al->thread = thread;
al->addr = addr;
al->cpumode = cpumode;
al->filtered = 0;
@@ -910,6 +908,29 @@ void thread__find_addr_map(struct thread *thread, u8 cpumode,
}
}
+void thread__find_addr_map(struct thread *thread, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al)
+{
+ al->thread = thread;
+ map_groups__find_addr_map(thread->mg, cpumode, type, addr, al);
+}
+
+void thread__find_addr_map_by_time(struct thread *thread, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al, u64 timestamp)
+{
+ struct map_groups *mg;
+
+ if (perf_has_index)
+ mg = thread__get_map_groups(thread, timestamp);
+ else
+ mg = thread->mg;
+
+ al->thread = thread;
+ map_groups__find_addr_map(mg, cpumode, type, addr, al);
+}
+
void thread__find_addr_location(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al)
@@ -922,6 +943,23 @@ void thread__find_addr_location(struct thread *thread,
al->sym = NULL;
}
+void thread__find_addr_location_by_time(struct thread *thread, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al, u64 timestamp)
+{
+ if (perf_has_index)
+ thread__find_addr_map_by_time(thread, cpumode, type, addr, al,
+ timestamp);
+ else
+ thread__find_addr_map(thread, cpumode, type, addr, al);
+
+ if (al->map != NULL)
+ al->sym = map__find_symbol(al->map, al->addr,
+ thread->mg->machine->symbol_filter);
+ else
+ al->sym = NULL;
+}
+
/*
* Callers need to drop the reference to al->thread, obtained in
* machine__findnew_thread()
@@ -951,7 +989,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
machine->vmlinux_maps[MAP__FUNCTION] == NULL)
machine__create_kernel_maps(machine);
- thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al);
+ thread__find_addr_map_by_time(thread, cpumode, MAP__FUNCTION,
+ sample->ip, al, sample->time);
+
dump_printf(" ...... dso: %s\n",
al->map ? al->map->dso->long_name :
al->level == 'H' ? "[hypervisor]" : "<not found>");
@@ -1026,10 +1066,11 @@ void perf_event__preprocess_sample_addr(union perf_event *event,
{
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
- thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
+ thread__find_addr_map_by_time(thread, cpumode, MAP__FUNCTION,
+ sample->addr, al, sample->time);
if (!al->map)
- thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
- sample->addr, al);
+ thread__find_addr_map_by_time(thread, cpumode, MAP__VARIABLE,
+ sample->addr, al, sample->time);
al->cpu = sample->cpu;
al->sym = NULL;
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 99fb14926351..64719692ec77 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1604,7 +1604,7 @@ static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
static void ip__resolve_ams(struct thread *thread,
struct addr_map_symbol *ams,
- u64 ip)
+ u64 ip, u64 timestamp)
{
struct addr_location al;
@@ -1616,7 +1616,8 @@ static void ip__resolve_ams(struct thread *thread,
* Thus, we have to try consecutively until we find a match
* or else, the symbol is unknown
*/
- thread__find_cpumode_addr_location(thread, MAP__FUNCTION, ip, &al);
+ thread__find_cpumode_addr_location_by_time(thread, MAP__FUNCTION,
+ ip, &al, timestamp);
ams->addr = ip;
ams->al_addr = al.addr;
@@ -1624,21 +1625,25 @@ static void ip__resolve_ams(struct thread *thread,
ams->map = al.map;
}
-static void ip__resolve_data(struct thread *thread,
- u8 m, struct addr_map_symbol *ams, u64 addr)
+static void ip__resolve_data(struct thread *thread, u8 m,
+ struct addr_map_symbol *ams,
+ u64 addr, u64 timestamp)
{
struct addr_location al;
memset(&al, 0, sizeof(al));
- thread__find_addr_location(thread, m, MAP__VARIABLE, addr, &al);
+ thread__find_addr_location_by_time(thread, m, MAP__VARIABLE,
+ addr, &al, timestamp);
+
if (al.map == NULL) {
/*
* some shared data regions have execute bit set which puts
* their mapping in the MAP__FUNCTION type array.
* Check there as a fallback option before dropping the sample.
*/
- thread__find_addr_location(thread, m, MAP__FUNCTION, addr, &al);
+ thread__find_addr_location_by_time(thread, m, MAP__FUNCTION,
+ addr, &al, timestamp);
}
ams->addr = addr;
@@ -1655,8 +1660,9 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
if (!mi)
return NULL;
- ip__resolve_ams(al->thread, &mi->iaddr, sample->ip);
- ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr);
+ ip__resolve_ams(al->thread, &mi->iaddr, sample->ip, sample->time);
+ ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr,
+ sample->time);
mi->data_src.val = sample->data_src;
return mi;
@@ -1730,8 +1736,10 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
return NULL;
for (i = 0; i < bs->nr; i++) {
- ip__resolve_ams(al->thread, &bi[i].to, bs->entries[i].to);
- ip__resolve_ams(al->thread, &bi[i].from, bs->entries[i].from);
+ ip__resolve_ams(al->thread, &bi[i].to,
+ bs->entries[i].to, sample->time);
+ ip__resolve_ams(al->thread, &bi[i].from,
+ bs->entries[i].from, sample->time);
bi[i].flags = bs->entries[i].flags;
}
return bi;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index b44afc75d1cc..2cf4ee24e40c 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -136,4 +136,5 @@ int perf_event__synthesize_id_index(struct perf_tool *tool,
struct perf_evlist *evlist,
struct machine *machine);
+
#endif /* __PERF_SESSION_H */
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index fc4e51afaf18..e35cd18adc0e 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -392,3 +392,29 @@ void thread__find_cpumode_addr_location(struct thread *thread,
break;
}
}
+
+void thread__find_cpumode_addr_location_by_time(struct thread *thread,
+ enum map_type type, u64 addr,
+ struct addr_location *al,
+ u64 timestamp)
+{
+ size_t i;
+ const u8 const cpumodes[] = {
+ PERF_RECORD_MISC_USER,
+ PERF_RECORD_MISC_KERNEL,
+ PERF_RECORD_MISC_GUEST_USER,
+ PERF_RECORD_MISC_GUEST_KERNEL
+ };
+
+ if (!perf_has_index) {
+ thread__find_cpumode_addr_location(thread, type, addr, al);
+ return;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
+ thread__find_addr_location_by_time(thread, cpumodes[i], type,
+ addr, al, timestamp);
+ if (al->map)
+ break;
+ }
+}
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 468bb785f061..eb73720f4009 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -81,14 +81,25 @@ size_t thread__fprintf(struct thread *thread, FILE *fp);
void thread__find_addr_map(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al);
+void thread__find_addr_map_by_time(struct thread *thread, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al, u64 timestamp);
void thread__find_addr_location(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al);
+void thread__find_addr_location_by_time(struct thread *thread, u8 cpumode,
+ enum map_type type, u64 addr,
+ struct addr_location *al,
+ u64 timestamp);
void thread__find_cpumode_addr_location(struct thread *thread,
enum map_type type, u64 addr,
struct addr_location *al);
+void thread__find_cpumode_addr_location_by_time(struct thread *thread,
+ enum map_type type, u64 addr,
+ struct addr_location *al,
+ u64 timestamp);
static inline void *thread__priv(struct thread *thread)
{
--
2.4.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists