[PATCH 21/40] perf tools: Save timestamp of a map creation

From: Namhyung Kim
Date: Sun May 17 2015 - 20:46:42 EST


It'll be used to support multiple maps on a same address like dlopen()
and/or JIT compile cases.

Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/dso.c | 2 +-
tools/perf/util/machine.c | 28 ++++++++++++++++------------
tools/perf/util/machine.h | 2 +-
tools/perf/util/map.c | 12 +++++++-----
tools/perf/util/map.h | 9 ++++++---
tools/perf/util/probe-event.c | 2 +-
tools/perf/util/symbol-elf.c | 2 +-
tools/perf/util/symbol.c | 4 ++--
8 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 13d9ae0bd15c..7078700233fa 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -747,7 +747,7 @@ struct map *dso__new_map(const char *name)
struct dso *dso = dso__new(name);

if (dso)
- map = map__new2(0, dso, MAP__FUNCTION);
+ map = map__new2(0, dso, MAP__FUNCTION, 0);

return map;
}
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 17e900a6a3c3..e3566365d320 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -668,7 +668,7 @@ int machine__process_itrace_start_event(struct machine *machine __maybe_unused,
}

struct map *machine__new_module(struct machine *machine, u64 start,
- const char *filename)
+ const char *filename, u64 timestamp)
{
struct map *map = NULL;
struct dso *dso;
@@ -686,7 +686,7 @@ struct map *machine__new_module(struct machine *machine, u64 start,
if (dso == NULL)
goto out;

- map = map__new2(start, dso, MAP__FUNCTION);
+ map = map__new2(start, dso, MAP__FUNCTION, timestamp);
if (map == NULL)
goto out;

@@ -854,7 +854,7 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
for (type = 0; type < MAP__NR_TYPES; ++type) {
struct kmap *kmap;

- machine->vmlinux_maps[type] = map__new2(start, kernel, type);
+ machine->vmlinux_maps[type] = map__new2(start, kernel, type, 0);
if (machine->vmlinux_maps[type] == NULL)
return -1;

@@ -1155,7 +1155,7 @@ static int machine__create_module(void *arg, const char *name, u64 start)
struct machine *machine = arg;
struct map *map;

- map = machine__new_module(machine, start, name);
+ map = machine__new_module(machine, start, name, 0);
if (map == NULL)
return -1;

@@ -1256,7 +1256,8 @@ static bool machine__uses_kcore(struct machine *machine)
}

static int machine__process_kernel_mmap_event(struct machine *machine,
- union perf_event *event)
+ union perf_event *event,
+ u64 timestamp)
{
struct map *map;
char kmmap_prefix[PATH_MAX];
@@ -1279,7 +1280,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
if (event->mmap.filename[0] == '/' ||
(!is_kernel_mmap && event->mmap.filename[0] == '[')) {
map = machine__new_module(machine, event->mmap.start,
- event->mmap.filename);
+ event->mmap.filename, timestamp);
if (map == NULL)
goto out_problem;

@@ -1343,7 +1344,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine,

int machine__process_mmap2_event(struct machine *machine,
union perf_event *event,
- struct perf_sample *sample __maybe_unused)
+ struct perf_sample *sample)
{
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct thread *thread;
@@ -1356,7 +1357,8 @@ int machine__process_mmap2_event(struct machine *machine,

if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
cpumode == PERF_RECORD_MISC_KERNEL) {
- ret = machine__process_kernel_mmap_event(machine, event);
+ ret = machine__process_kernel_mmap_event(machine, event,
+ sample->time);
if (ret < 0)
goto out_problem;
return 0;
@@ -1379,7 +1381,8 @@ int machine__process_mmap2_event(struct machine *machine,
event->mmap2.ino_generation,
event->mmap2.prot,
event->mmap2.flags,
- event->mmap2.filename, type, thread);
+ event->mmap2.filename, type, thread,
+ sample->time);

if (map == NULL)
goto out_problem_map;
@@ -1396,7 +1399,7 @@ int machine__process_mmap2_event(struct machine *machine,
}

int machine__process_mmap_event(struct machine *machine, union perf_event *event,
- struct perf_sample *sample __maybe_unused)
+ struct perf_sample *sample)
{
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct thread *thread;
@@ -1409,7 +1412,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event

if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
cpumode == PERF_RECORD_MISC_KERNEL) {
- ret = machine__process_kernel_mmap_event(machine, event);
+ ret = machine__process_kernel_mmap_event(machine, event,
+ sample->time);
if (ret < 0)
goto out_problem;
return 0;
@@ -1429,7 +1433,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
event->mmap.len, event->mmap.pgoff,
event->mmap.pid, 0, 0, 0, 0, 0, 0,
event->mmap.filename,
- type, thread);
+ type, thread, sample->time);

if (map == NULL)
goto out_problem_map;
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 863c0e90ceb1..f0f6bd420237 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -193,7 +193,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
}

struct map *machine__new_module(struct machine *machine, u64 start,
- const char *filename);
+ const char *filename, u64 timestamp);

int machine__load_kallsyms(struct machine *machine, const char *filename,
enum map_type type, symbol_filter_t filter);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index b794c3561995..fef4e38ccd93 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -123,7 +123,7 @@ static inline bool replace_android_lib(const char *filename, char *newfilename)
}

void map__init(struct map *map, enum map_type type,
- u64 start, u64 end, u64 pgoff, struct dso *dso)
+ u64 start, u64 end, u64 pgoff, struct dso *dso, u64 timestamp)
{
map->type = type;
map->start = start;
@@ -137,12 +137,13 @@ void map__init(struct map *map, enum map_type type,
map->groups = NULL;
map->referenced = false;
map->erange_warned = false;
+ map->timestamp = timestamp;
}

struct map *map__new(struct machine *machine, u64 start, u64 len,
u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
u64 ino_gen, u32 prot, u32 flags, char *filename,
- enum map_type type, struct thread *thread)
+ enum map_type type, struct thread *thread, u64 timestamp)
{
struct map *map = malloc(sizeof(*map));

@@ -182,7 +183,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
if (dso == NULL)
goto out_delete;

- map__init(map, type, start, start + len, pgoff, dso);
+ map__init(map, type, start, start + len, pgoff, dso, timestamp);

if (anon || no_dso) {
map->map_ip = map->unmap_ip = identity__map_ip;
@@ -207,7 +208,8 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
* they are loaded) and for vmlinux, where only after we load all the
* symbols we'll know where it starts and ends.
*/
-struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
+struct map *map__new2(u64 start, struct dso *dso, enum map_type type,
+ u64 timestamp)
{
struct map *map = calloc(1, (sizeof(*map) +
(dso->kernel ? sizeof(struct kmap) : 0)));
@@ -215,7 +217,7 @@ struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
/*
* ->end will be filled after we load all the symbols
*/
- map__init(map, type, start, 0, 0, dso);
+ map__init(map, type, start, 0, 0, dso, timestamp);
}

return map;
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 074453d332dd..c1ed11a3e16c 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -42,6 +42,7 @@ struct map {
u32 maj, min; /* only valid for MMAP2 record */
u64 ino; /* only valid for MMAP2 record */
u64 ino_generation;/* only valid for MMAP2 record */
+ u64 timestamp;

/* ip -> dso rip */
u64 (*map_ip)(struct map *, u64);
@@ -136,12 +137,14 @@ typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);

int arch__compare_symbol_names(const char *namea, const char *nameb);
void map__init(struct map *map, enum map_type type,
- u64 start, u64 end, u64 pgoff, struct dso *dso);
+ u64 start, u64 end, u64 pgoff, struct dso *dso, u64 timestamp);
struct map *map__new(struct machine *machine, u64 start, u64 len,
u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
u64 ino_gen, u32 prot, u32 flags,
- char *filename, enum map_type type, struct thread *thread);
-struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
+ char *filename, enum map_type type, struct thread *thread,
+ u64 timestamp);
+struct map *map__new2(u64 start, struct dso *dso, enum map_type type,
+ u64 timestamp);
void map__delete(struct map *map);
struct map *map__clone(struct map *map);
int map__overlap(struct map *l, struct map *r);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 2399dc4f6089..5a1d6bee4731 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -167,7 +167,7 @@ static struct map *kernel_get_module_map(const char *module)

/* A file path -- this is an offline module */
if (module && strchr(module, '/'))
- return machine__new_module(host_machine, 0, module);
+ return machine__new_module(host_machine, 0, module, 0);

if (!module)
module = "kernel";
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 9d526a5312b1..eb84dd5e86c9 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1012,7 +1012,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
curr_dso->long_name = dso->long_name;
curr_dso->long_name_len = dso->long_name_len;
curr_map = map__new2(start, curr_dso,
- map->type);
+ map->type, map->timestamp);
if (curr_map == NULL) {
dso__delete(curr_dso);
goto out_elf_end;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 45ba48a7acb3..5d69d3c407e6 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -781,7 +781,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta,

ndso->kernel = dso->kernel;

- curr_map = map__new2(pos->start, ndso, map->type);
+ curr_map = map__new2(pos->start, ndso, map->type, 0);
if (curr_map == NULL) {
dso__delete(ndso);
return -1;
@@ -1083,7 +1083,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
struct kcore_mapfn_data *md = data;
struct map *map;

- map = map__new2(start, md->dso, md->type);
+ map = map__new2(start, md->dso, md->type, 0);
if (map == NULL)
return -ENOMEM;

--
2.4.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/