From: Andi Kleen <andi@firstfloor.org>
To: jolsa@redhat.com
Cc: linux-kernel@vger.kernel.org, namhyung@kernel.org,
acme@infradead.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 4/9] perf, tools: Automatically look for event file name for cpu v2
Date: Thu, 15 May 2014 15:03:07 -0700 [thread overview]
Message-ID: <1400191392-11569-5-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1400191392-11569-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
When no JSON event file is specified automatically look
for a suitable file in ~/.cache/pmu-events. A "perf download" can
automatically add files there for the current CPUs.
This does not include the actual event files with perf,
but they can be automatically downloaded instead
(implemented in the next patch)
This has the advantage that the events can be always uptodate,
because they are freshly downloaded. In oprofile we always
had problems with out of date or incomplete events files.
The event file format is per architecture, but can be
extended for other architectures.
v2: Supports XDG_CACHE_HOME and defaults to ~/.cache/pmu-events
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/arch/x86/Makefile | 1 +
tools/perf/arch/x86/util/cpustr.c | 34 ++++++++++++++++++++++++++++++++++
tools/perf/util/jevents.c | 31 +++++++++++++++++++++++++++++++
tools/perf/util/jevents.h | 1 +
tools/perf/util/pmu.c | 2 +-
5 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 tools/perf/arch/x86/util/cpustr.c
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 1641542..0efeb14 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -14,4 +14,5 @@ LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o
endif
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/cpustr.o
LIB_H += arch/$(ARCH)/util/tsc.h
diff --git a/tools/perf/arch/x86/util/cpustr.c b/tools/perf/arch/x86/util/cpustr.c
new file mode 100644
index 0000000..e1cd76c
--- /dev/null
+++ b/tools/perf/arch/x86/util/cpustr.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "../../util/jevents.h"
+
+char *get_cpu_str(void)
+{
+ char *line = NULL;
+ size_t llen = 0;
+ int found = 0, n;
+ char vendor[30];
+ int model, fam;
+ char *res = NULL;
+ FILE *f = fopen("/proc/cpuinfo", "r");
+
+ if (!f)
+ return NULL;
+ while (getline(&line, &llen, f) > 0) {
+ if (sscanf(line, "vendor_id : %30s", vendor) == 1)
+ found++;
+ else if (sscanf(line, "model : %d", &model) == 1)
+ found++;
+ else if (sscanf(line, "cpu family : %d", &fam) == 1)
+ found++;
+ if (found == 3) {
+ n = asprintf(&res, "%s-%d-%X-core", vendor, fam, model);
+ if (n < 0)
+ res = NULL;
+ break;
+ }
+ }
+ free(line);
+ fclose(f);
+ return res;
+}
diff --git a/tools/perf/util/jevents.c b/tools/perf/util/jevents.c
index 943a1fc..b26c0b6 100644
--- a/tools/perf/util/jevents.c
+++ b/tools/perf/util/jevents.c
@@ -33,10 +33,39 @@
#include <errno.h>
#include <string.h>
#include <ctype.h>
+#include "cache.h"
#include "jsmn.h"
#include "json.h"
#include "jevents.h"
+__attribute__((weak)) char *get_cpu_str(void)
+{
+ return NULL;
+}
+
+static const char *json_default_name(void)
+{
+ char *cache = getenv("XDG_CACHE_HOME");
+ char *idstr = get_cpu_str();
+ char *res = NULL;
+ char *home = NULL;
+
+ if (!cache) {
+ home = getenv("HOME");
+ if (!home || asprintf(&cache, "%s/.cache", home) < 0)
+ goto out;
+ }
+ if (cache && idstr)
+ res = mkpath("%s/pmu-events/%s.json",
+ cache,
+ idstr);
+ if (home)
+ free(cache);
+out:
+ free(idstr);
+ return res;
+}
+
static void addfield(char *map, char **dst, const char *sep,
const char *a, jsmntok_t *bt)
{
@@ -174,6 +203,8 @@ int json_events(const char *fn,
int i, j, len;
char *map;
+ if (!fn)
+ fn = json_default_name();
tokens = parse_json(fn, &map, &size, &len);
if (!tokens)
return -EIO;
diff --git a/tools/perf/util/jevents.h b/tools/perf/util/jevents.h
index 4c2b879..6a377a8 100644
--- a/tools/perf/util/jevents.h
+++ b/tools/perf/util/jevents.h
@@ -1,3 +1,4 @@
int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc),
void *data);
+char *get_cpu_str(void);
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 9f154af..fa21319 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -433,7 +433,7 @@ static struct perf_pmu *pmu_lookup(const char *name)
if (pmu_aliases(name, &aliases))
return NULL;
- if (!strcmp(name, "cpu") && json_file)
+ if (!strcmp(name, "cpu"))
json_events(json_file, add_alias, &aliases);
if (pmu_type(name, &type))
--
1.9.0
next prev parent reply other threads:[~2014-05-15 22:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 22:03 perf: Add support for full Intel event lists v4 Andi Kleen
2014-05-15 22:03 ` [PATCH 1/9] perf, tools: Add jsmn `jasmine' JSON parser v2 Andi Kleen
2014-05-15 22:03 ` [PATCH 2/9] perf, tools: Add support for text descriptions of events and alias add Andi Kleen
2014-05-15 22:03 ` [PATCH 3/9] perf, tools: Add support for reading JSON event files v2 Andi Kleen
2014-05-15 22:03 ` Andi Kleen [this message]
2014-05-15 22:03 ` [PATCH 5/9] perf, tools: Add perf download to download event files v3 Andi Kleen
2014-05-15 22:03 ` [PATCH 6/9] perf, tools: Allow events with dot Andi Kleen
2014-05-15 22:03 ` [PATCH 7/9] perf, tools: Query terminal width and use in perf list Andi Kleen
2014-05-15 22:03 ` [PATCH 8/9] perf, tools, test: Add test case for alias and JSON parsing v2 Andi Kleen
2014-05-15 22:03 ` [PATCH 9/9] perf, tools, record: Always allow to overide default period v2 Andi Kleen
-- strict thread matches above, loose matches on Subject: below --
2014-05-30 21:50 perf: Add support for full Intel event lists v5 Andi Kleen
2014-05-30 21:50 ` [PATCH 4/9] perf, tools: Automatically look for event file name for cpu v2 Andi Kleen
2014-05-12 22:51 perf: Add support for full Intel event lists v3 Andi Kleen
2014-05-12 22:51 ` [PATCH 4/9] perf, tools: Automatically look for event file name for cpu v2 Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400191392-11569-5-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@infradead.org \
--cc=ak@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).