[RFC/PATCH 18/38] perf tools: Introduce thread__find_addr_location_by_time() and friends
From: Namhyung Kim
Date: Fri Oct 02 2015 - 01:24:12 EST
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@xxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
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 887f18266ab5..c960cbcd30d4 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -895,16 +895,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;
@@ -973,6 +971,29 @@ try_again:
}
}
+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)
@@ -985,6 +1006,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()
@@ -1014,7 +1052,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
machine__kernel_map(machine) == 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>");
@@ -1097,10 +1137,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 3373e8455945..d5e5b9de54b0 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1688,7 +1688,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;
@@ -1700,7 +1700,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;
@@ -1708,21 +1709,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;
@@ -1739,8 +1744,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;
@@ -1814,8 +1820,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 3e900c0efc73..1dd864e983d2 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -138,4 +138,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 33de8b010282..efd510d5d966 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -400,3 +400,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 c8463d08a6dd..8815ac7bba3c 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.6.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/