[PATCH 03/15] perf mem: Add -l/--ldlat option

From: Jiri Olsa
Date: Wed Feb 24 2016 - 03:47:23 EST


Adding -l/--ldlat option to specify desired latency
for loads event.

Specify 50 as loads event latency:

$ perf mem record -e ldlat-loads -v -l 50 true
calling: record -W -d -e cpu/mem-loads,ldlat=50/P true

Link: http://lkml.kernel.org/n/tip-ec2m0cvivkfs8uhtiv411hfc@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/builtin-mem.c | 1 +
tools/perf/util/mem-events.c | 17 ++++++++++++++++-
tools/perf/util/mem-events.h | 1 +
3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 88aeac9aa1da..9da09e058f4b 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -66,6 +66,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
OPT_CALLBACK('e', "event", &mem, "event",
"event selector. use 'perf mem record -e list' to list available events",
parse_record_events),
+ OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat, "mem-loads latency"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show counter open errors, etc)"),
OPT_END()
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 0f62e930de13..3772a3a8a6ee 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -9,18 +9,33 @@
#include "mem-events.h"
#include "debug.h"

+unsigned int perf_mem_events__loads_ldlat = 30;
+
#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }

struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
- E("ldlat-loads", "cpu/mem-loads,ldlat=30/P", "mem-loads"),
+ E("ldlat-loads", "cpu/mem-loads,ldlat=%u/P", "mem-loads"),
E("ldlat-stores", "cpu/mem-stores/P", "mem-stores"),
};
#undef E

#undef E

+static char mem_loads_name[100];
+static bool mem_loads_name__init;
+
char *perf_mem_events__name(int i)
{
+ if (i == PERF_MEM_EVENTS__LOAD) {
+ if (!mem_loads_name__init) {
+ mem_loads_name__init = true;
+ scnprintf(mem_loads_name, sizeof(mem_loads_name),
+ perf_mem_events[i].name,
+ perf_mem_events__loads_ldlat);
+ }
+ return mem_loads_name;
+ }
+
return (char *) perf_mem_events[i].name;
}

diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index 2a91b959de62..4ab437291589 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -18,6 +18,7 @@ enum {
};

extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
+extern unsigned int perf_mem_events__loads_ldlat;

int perf_mem_events__parse(const char *str);
int perf_mem_events__init(void);
--
2.4.3