From: Jiri Olsa <jolsa@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Andi Kleen <ak@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>
Subject: [PATCH 12/13] perf tests: Add test case for alias and JSON parsing
Date: Wed, 16 Jul 2014 22:02:48 +0200 [thread overview]
Message-ID: <1405540969-18975-13-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1405540969-18975-1-git-send-email-jolsa@kernel.org>
From: Andi Kleen <ak@linux.intel.com>
Add a simple test case to perf test that runs perf download and parses
all the available events, including json events.
This needs adding an all event iterator to pmu.c
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/n/1405123165-22666-11-git-send-email-andi@firstfloor.org
[ use pr_* for output instead of fprintf calls ]
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/Makefile.perf | 1 +
tools/perf/tests/aliases.c | 58 +++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/builtin-test.c | 4 +++
tools/perf/tests/tests.h | 1 +
4 files changed, 64 insertions(+)
create mode 100644 tools/perf/tests/aliases.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index b1c0b758f88d..a38191a335b4 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -420,6 +420,7 @@ endif
LIB_OBJS += $(OUTPUT)tests/code-reading.o
LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
+LIB_OBJS += $(OUTPUT)tests/aliases.o
ifndef NO_DWARF_UNWIND
ifeq ($(ARCH),$(filter $(ARCH),x86 arm))
LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
diff --git a/tools/perf/tests/aliases.c b/tools/perf/tests/aliases.c
new file mode 100644
index 000000000000..f315fbc25272
--- /dev/null
+++ b/tools/perf/tests/aliases.c
@@ -0,0 +1,58 @@
+/* Check if we can set up all aliases and can read JSON files */
+#include <stdlib.h>
+#include "tests.h"
+#include "pmu.h"
+#include "evlist.h"
+#include "parse-events.h"
+
+static struct perf_evlist *evlist;
+
+static int num_events;
+static int failed;
+
+static int test__event(const char *pmu, const char *name)
+{
+ int ret;
+
+ /* Not supported for now */
+ if (strcmp(pmu, "cpu"))
+ return 0;
+
+ ret = parse_events(evlist, name);
+
+ if (ret) {
+ /*
+ * We only print on failure because common perf setups
+ * have events that cannot be parsed.
+ */
+ pr_err("invalid or unsupported event: '%s'\n", name);
+ ret = 0;
+ failed++;
+ } else
+ num_events++;
+ return ret;
+}
+
+int test__aliases(void)
+{
+ int err;
+
+ /* Download JSON files */
+ /* XXX assumes perf is installed */
+ /* For now user must manually download */
+ if (0 && system("perf download > /dev/null") < 0) {
+ /* Don't error out for this for now */
+ pr_err("perf download failed\n");
+ }
+
+ evlist = perf_evlist__new();
+ if (evlist == NULL)
+ return -ENOMEM;
+
+ err = pmu_iterate_events(test__event);
+ pr_debug(" Parsed %d events :", num_events);
+ if (failed > 0)
+ pr_err(" %d events failed", failed);
+ perf_evlist__delete(evlist);
+ return err;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 6f8b01bc6033..bb37ac205971 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -154,6 +154,10 @@ static struct test {
.func = test__hists_cumulate,
},
{
+ .desc = "Test parsing JSON aliases",
+ .func = test__aliases,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index ed64790a395f..ab92ad9bf0e6 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -48,6 +48,7 @@ int test__mmap_thread_lookup(void);
int test__thread_mg_share(void);
int test__hists_output(void);
int test__hists_cumulate(void);
+int test__aliases(void);
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
--
1.8.3.1
next prev parent reply other threads:[~2014-07-16 20:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-16 20:02 [GIT PULL 00/13] perf/core improvements and fixes Jiri Olsa
2014-07-16 20:02 ` [PATCH 01/13] perf tools: Enable close-on-exec flag on perf file descriptor Jiri Olsa
2014-07-16 20:02 ` [PATCH 02/13] perf tests: Update attr test with PERF_FLAG_FD_CLOEXEC flag Jiri Olsa
2014-07-16 20:02 ` [PATCH 03/13] perf tools: Add jsmn `jasmine' JSON parser Jiri Olsa
2014-07-16 20:02 ` [PATCH 04/13] perf tools: Add support for text descriptions of events and alias add Jiri Olsa
2014-07-16 20:02 ` [PATCH 05/13] perf tools: Update perf list to output descriptions Jiri Olsa
2014-07-16 20:02 ` [PATCH 06/13] perf tools: Allow events with dot Jiri Olsa
2014-07-16 20:02 ` [PATCH 07/13] perf tools: Add support for reading JSON event files Jiri Olsa
2014-07-16 20:02 ` [PATCH 08/13] perf tools: Automatically look for event file name for cpu Jiri Olsa
2014-07-16 20:02 ` [PATCH 09/13] perf tools: Add perf download to download event files Jiri Olsa
2014-07-17 10:47 ` Ingo Molnar
2014-07-17 10:51 ` Ingo Molnar
2014-07-18 17:35 ` Andi Kleen
2014-07-19 9:51 ` Ingo Molnar
2014-08-06 1:16 ` Michael Ellerman
2014-08-06 1:09 ` Michael Ellerman
2014-07-16 20:02 ` [PATCH 10/13] perf tools: Query terminal width and use in perf list Jiri Olsa
2014-07-16 20:02 ` [PATCH 11/13] perf tools: Add a new pmu interface to iterate over all events Jiri Olsa
2014-07-16 20:02 ` Jiri Olsa [this message]
2014-07-16 20:02 ` [PATCH 13/13] perf tools: Add a --no-desc flag to perf list Jiri Olsa
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=1405540969-18975-13-git-send-email-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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).