Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-10 Thread Andi Kleen
On Thu, Jul 10, 2014 at 08:25:08AM +0200, Jiri Olsa wrote:
> On Thu, Jul 10, 2014 at 02:05:54AM +0200, Andi Kleen wrote:
> > On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
> > > Im confused, your branch shows v4 in patch Subject,
> > > while this patch has v3... ?
> > 
> > Patchkits and patches both have their own numeric 
> > version spaces.
> 
> yes, but this specific patch has higher (different) version
> in the branch, that patch you sent

Yes the branch contains an unposted version.

Only change was just the manpage changes that were requested
during review.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-10 Thread Jiri Olsa
On Thu, Jul 10, 2014 at 02:05:54AM +0200, Andi Kleen wrote:
> On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
> > Im confused, your branch shows v4 in patch Subject,
> > while this patch has v3... ?
> 
> Patchkits and patches both have their own numeric 
> version spaces.

yes, but this specific patch has higher (different) version
in the branch, that patch you sent

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-10 Thread Jiri Olsa
On Thu, Jul 10, 2014 at 02:05:54AM +0200, Andi Kleen wrote:
 On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
  Im confused, your branch shows v4 in patch Subject,
  while this patch has v3... ?
 
 Patchkits and patches both have their own numeric 
 version spaces.

yes, but this specific patch has higher (different) version
in the branch, that patch you sent

jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-10 Thread Andi Kleen
On Thu, Jul 10, 2014 at 08:25:08AM +0200, Jiri Olsa wrote:
 On Thu, Jul 10, 2014 at 02:05:54AM +0200, Andi Kleen wrote:
  On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
   Im confused, your branch shows v4 in patch Subject,
   while this patch has v3... ?
  
  Patchkits and patches both have their own numeric 
  version spaces.
 
 yes, but this specific patch has higher (different) version
 in the branch, that patch you sent

Yes the branch contains an unposted version.

Only change was just the manpage changes that were requested
during review.

-Andi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Andi Kleen
> what happens if we fail to realloc?

Then the field doesn't get added. No problem.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Andi Kleen
On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
> Im confused, your branch shows v4 in patch Subject,
> while this patch has v3... ?

Patchkits and patches both have their own numeric 
version spaces.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 
> Add a parser for Intel style JSON event files. This allows
> to use an Intel event list directly with perf. The Intel
> event lists can be quite large and are too big to store
> in unswappable kernel memory.
> 
> The parser code knows how to convert the JSON fields
> to perf fields. The conversion code is straight forward.
> It knows (very little) Intel specific information, and can be easily
> extended to handle fields for other CPUs.
> 
> The parser code is partially shared with an independent parsing
> library, which is 2-clause BSD licenced. To avoid any conflicts I marked
> those files as BSD licenced too. As part of perf they become GPLv2.

this change breaks compilation, which is probably fixed later on in patchset

  CC   util/jevents.o
util/jevents.c: In function ‘lookup_msr’:
util/jevents.c:140:2: error: unknown type name ‘bool’
  static bool warned;
  ^
util/jevents.c:148:12: error: ‘true’ undeclared (first use in this function)
   warned = true;
^
util/jevents.c:148:12: note: each undeclared identifier is reported only once 
for each function it appears in
util/jevents.c:149:3: error: implicit declaration of function ‘pr_err’ 
[-Werror=implicit-function-declaration]
   pr_err("Unknown MSR in event file %.*s\n",
   ^
util/jevents.c:149:3: error: nested extern declaration of ‘pr_err’ 
[-Werror=nested-externs]
cc1: all warnings being treated as errors
make[1]: *** [util/jevents.o] Error 1
make: *** [all] Error 2


jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
Im confused, your branch shows v4 in patch Subject,
while this patch has v3... ?

jirka

On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 
> Add a parser for Intel style JSON event files. This allows
> to use an Intel event list directly with perf. The Intel
> event lists can be quite large and are too big to store
> in unswappable kernel memory.
> 
> The parser code knows how to convert the JSON fields
> to perf fields. The conversion code is straight forward.
> It knows (very little) Intel specific information, and can be easily
> extended to handle fields for other CPUs.
> 
> The parser code is partially shared with an independent parsing
> library, which is 2-clause BSD licenced. To avoid any conflicts I marked
> those files as BSD licenced too. As part of perf they become GPLv2.
> 

SNIP

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 
> Add a parser for Intel style JSON event files. This allows
> to use an Intel event list directly with perf. The Intel
> event lists can be quite large and are too big to store
> in unswappable kernel memory.
> 
> The parser code knows how to convert the JSON fields
> to perf fields. The conversion code is straight forward.
> It knows (very little) Intel specific information, and can be easily
> extended to handle fields for other CPUs.
> 
> The parser code is partially shared with an independent parsing
> library, which is 2-clause BSD licenced. To avoid any conflicts I marked
> those files as BSD licenced too. As part of perf they become GPLv2.

SNIP

> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "jsmn.h"
> +#include "json.h"
> +#include "jevents.h"
> +
> +static void addfield(char *map, char **dst, const char *sep,
> +  const char *a, jsmntok_t *bt)
> +{
> + unsigned len = strlen(a) + 1 + strlen(sep);
> + int olen = *dst ? strlen(*dst) : 0;
> + int blen = bt ? json_len(bt) : 0;
> + char *out;
> +
> + out = realloc(*dst, len + olen + blen);
> + if (!out)
> + return;

what happens if we fail to realloc?

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
> From: Andi Kleen 

SNIP

> +}
> diff --git a/tools/perf/util/jevents.h b/tools/perf/util/jevents.h
> new file mode 100644
> index 000..4c2b879
> --- /dev/null
> +++ b/tools/perf/util/jevents.h
> @@ -0,0 +1,3 @@

missing standard '#ifndef ...' macros

> +int json_events(const char *fn,
> + int (*func)(void *data, char *name, char *event, char *desc),
> + void *data);

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
Im confused, your branch shows v4 in patch Subject,
while this patch has v3... ?

jirka

On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com
 
 Add a parser for Intel style JSON event files. This allows
 to use an Intel event list directly with perf. The Intel
 event lists can be quite large and are too big to store
 in unswappable kernel memory.
 
 The parser code knows how to convert the JSON fields
 to perf fields. The conversion code is straight forward.
 It knows (very little) Intel specific information, and can be easily
 extended to handle fields for other CPUs.
 
 The parser code is partially shared with an independent parsing
 library, which is 2-clause BSD licenced. To avoid any conflicts I marked
 those files as BSD licenced too. As part of perf they become GPLv2.
 

SNIP

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com
 
 Add a parser for Intel style JSON event files. This allows
 to use an Intel event list directly with perf. The Intel
 event lists can be quite large and are too big to store
 in unswappable kernel memory.
 
 The parser code knows how to convert the JSON fields
 to perf fields. The conversion code is straight forward.
 It knows (very little) Intel specific information, and can be easily
 extended to handle fields for other CPUs.
 
 The parser code is partially shared with an independent parsing
 library, which is 2-clause BSD licenced. To avoid any conflicts I marked
 those files as BSD licenced too. As part of perf they become GPLv2.

SNIP

 +
 +#include stdio.h
 +#include stdlib.h
 +#include errno.h
 +#include string.h
 +#include ctype.h
 +#include jsmn.h
 +#include json.h
 +#include jevents.h
 +
 +static void addfield(char *map, char **dst, const char *sep,
 +  const char *a, jsmntok_t *bt)
 +{
 + unsigned len = strlen(a) + 1 + strlen(sep);
 + int olen = *dst ? strlen(*dst) : 0;
 + int blen = bt ? json_len(bt) : 0;
 + char *out;
 +
 + out = realloc(*dst, len + olen + blen);
 + if (!out)
 + return;

what happens if we fail to realloc?

jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com

SNIP

 +}
 diff --git a/tools/perf/util/jevents.h b/tools/perf/util/jevents.h
 new file mode 100644
 index 000..4c2b879
 --- /dev/null
 +++ b/tools/perf/util/jevents.h
 @@ -0,0 +1,3 @@

missing standard '#ifndef ...' macros

 +int json_events(const char *fn,
 + int (*func)(void *data, char *name, char *event, char *desc),
 + void *data);

jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Jiri Olsa
On Fri, Jun 27, 2014 at 04:15:58PM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com
 
 Add a parser for Intel style JSON event files. This allows
 to use an Intel event list directly with perf. The Intel
 event lists can be quite large and are too big to store
 in unswappable kernel memory.
 
 The parser code knows how to convert the JSON fields
 to perf fields. The conversion code is straight forward.
 It knows (very little) Intel specific information, and can be easily
 extended to handle fields for other CPUs.
 
 The parser code is partially shared with an independent parsing
 library, which is 2-clause BSD licenced. To avoid any conflicts I marked
 those files as BSD licenced too. As part of perf they become GPLv2.

this change breaks compilation, which is probably fixed later on in patchset

  CC   util/jevents.o
util/jevents.c: In function ‘lookup_msr’:
util/jevents.c:140:2: error: unknown type name ‘bool’
  static bool warned;
  ^
util/jevents.c:148:12: error: ‘true’ undeclared (first use in this function)
   warned = true;
^
util/jevents.c:148:12: note: each undeclared identifier is reported only once 
for each function it appears in
util/jevents.c:149:3: error: implicit declaration of function ‘pr_err’ 
[-Werror=implicit-function-declaration]
   pr_err(Unknown MSR in event file %.*s\n,
   ^
util/jevents.c:149:3: error: nested extern declaration of ‘pr_err’ 
[-Werror=nested-externs]
cc1: all warnings being treated as errors
make[1]: *** [util/jevents.o] Error 1
make: *** [all] Error 2


jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Andi Kleen
On Thu, Jul 10, 2014 at 12:19:58AM +0200, Jiri Olsa wrote:
 Im confused, your branch shows v4 in patch Subject,
 while this patch has v3... ?

Patchkits and patches both have their own numeric 
version spaces.

-Andi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-07-09 Thread Andi Kleen
 what happens if we fail to realloc?

Then the field doesn't get added. No problem.

-Andi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-06-27 Thread Andi Kleen
From: Andi Kleen 

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
"EventCode": "0x00",
"UMask": "0x01",
"EventName": "INST_RETIRED.ANY",
"BriefDescription": "Instructions retired from execution.",
"PublicDescription": "Instructions retired from execution.",
"Counter": "Fixed counter 1",
"CounterHTOff": "Fixed counter 1",
"SampleAfterValue": "203",
"MSRIndex": "0",
"MSRValue": "0",
"TakenAlone": "0",
"CounterMask": "0",
"Invert": "0",
"AnyThread": "0",
"EdgeDetect": "0",
"PEBS": "0",
"PRECISE_STORE": "0",
"Errata": "null",
"Offcore": "0"
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Acked-by: Namhyung Kim 
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index d460049..59778f4 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -214,6 +214,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 1cd32c5..0016d1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, "events-file", _file, "json file",
+  "Read event json file"),
OPT_END()
};

[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-06-27 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
EventCode: 0x00,
UMask: 0x01,
EventName: INST_RETIRED.ANY,
BriefDescription: Instructions retired from execution.,
PublicDescription: Instructions retired from execution.,
Counter: Fixed counter 1,
CounterHTOff: Fixed counter 1,
SampleAfterValue: 203,
MSRIndex: 0,
MSRValue: 0,
TakenAlone: 0,
CounterMask: 0,
Invert: 0,
AnyThread: 0,
EdgeDetect: 0,
PEBS: 0,
PRECISE_STORE: 0,
Errata: null,
Offcore: 0
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Acked-by: Namhyung Kim namhy...@kernel.org
Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index d460049..59778f4 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -214,6 +214,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 1cd32c5..0016d1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, events-file, json_file, json file,
+  Read event json file),
OPT_END()
};
const char * const 

[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-06-13 Thread Andi Kleen
From: Andi Kleen 

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
"EventCode": "0x00",
"UMask": "0x01",
"EventName": "INST_RETIRED.ANY",
"BriefDescription": "Instructions retired from execution.",
"PublicDescription": "Instructions retired from execution.",
"Counter": "Fixed counter 1",
"CounterHTOff": "Fixed counter 1",
"SampleAfterValue": "203",
"MSRIndex": "0",
"MSRValue": "0",
"TakenAlone": "0",
"CounterMask": "0",
"Invert": "0",
"AnyThread": "0",
"EdgeDetect": "0",
"PEBS": "0",
"PRECISE_STORE": "0",
"Errata": "null",
"Offcore": "0"
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Acked-by: Namhyung Kim 
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index d460049..59778f4 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -214,6 +214,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 1cd32c5..0016d1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, "events-file", _file, "json file",
+  "Read event json file"),
OPT_END()
};

[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-06-13 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
EventCode: 0x00,
UMask: 0x01,
EventName: INST_RETIRED.ANY,
BriefDescription: Instructions retired from execution.,
PublicDescription: Instructions retired from execution.,
Counter: Fixed counter 1,
CounterHTOff: Fixed counter 1,
SampleAfterValue: 203,
MSRIndex: 0,
MSRValue: 0,
TakenAlone: 0,
CounterMask: 0,
Invert: 0,
AnyThread: 0,
EdgeDetect: 0,
PEBS: 0,
PRECISE_STORE: 0,
Errata: null,
Offcore: 0
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Acked-by: Namhyung Kim namhy...@kernel.org
Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index d460049..59778f4 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -214,6 +214,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 1cd32c5..0016d1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, events-file, json_file, json file,
+  Read event json file),
OPT_END()
};
const char * const 

[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-05-30 Thread Andi Kleen
From: Andi Kleen 

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
"EventCode": "0x00",
"UMask": "0x01",
"EventName": "INST_RETIRED.ANY",
"BriefDescription": "Instructions retired from execution.",
"PublicDescription": "Instructions retired from execution.",
"Counter": "Fixed counter 1",
"CounterHTOff": "Fixed counter 1",
"SampleAfterValue": "203",
"MSRIndex": "0",
"MSRValue": "0",
"TakenAlone": "0",
"CounterMask": "0",
"Invert": "0",
"AnyThread": "0",
"EdgeDetect": "0",
"PEBS": "0",
"PRECISE_STORE": "0",
"Errata": "null",
"Offcore": "0"
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..cff0869 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index cc8fb36..b2f69cb 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, "events-file", _file, "json file",
+  "Read event json file"),
OPT_END()
};
const char * const 

[PATCH 3/9] perf, tools: Add support for reading JSON event files v3

2014-05-30 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

JSON files look like this:

[
  {
EventCode: 0x00,
UMask: 0x01,
EventName: INST_RETIRED.ANY,
BriefDescription: Instructions retired from execution.,
PublicDescription: Instructions retired from execution.,
Counter: Fixed counter 1,
CounterHTOff: Fixed counter 1,
SampleAfterValue: 203,
MSRIndex: 0,
MSRValue: 0,
TakenAlone: 0,
CounterMask: 0,
Invert: 0,
AnyThread: 0,
EdgeDetect: 0,
PEBS: 0,
PRECISE_STORE: 0,
Errata: null,
Offcore: 0
  },

v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..cff0869 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index cc8fb36..b2f69cb 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, events-file, json_file, json file,
+  Read event json file),
OPT_END()
};
const char * const list_usage[] = {
diff --git 

[PATCH 3/9] perf, tools: Add support for reading JSON event files v2

2014-05-15 Thread Andi Kleen
From: Andi Kleen 

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

v2: Address review feedback. Rename option to --event-files
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..cff0869 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 43d4109..8800838 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, "events-file", _file, "json file",
+  "Read event json file"),
OPT_END()
};
const char * const list_usage[] = {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e4c85b8..ed00556 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -25,6 +25,7 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/data.h"
+#include "util/pmu.h"
 
 #include 
 #include 
@@ -871,6 +872,8 @@ const struct option record_options[] = {
"sample transaction flags (special events only)"),
OPT_BOOLEAN(0, "per-thread", _thread,
"use per-thread mmaps"),
+   OPT_STRING(0, "events-file", _file, "json file",
+  

Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-15 Thread Andi Kleen
> And more generally, can we extend these if-else's to a generic loop to
> check a table like in match_field() so that it can be added easily?

The simple cases are all already handled in a table above.

The if() only contains cases that need special code. I don't think
callbacks would be better here.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-15 Thread Andi Kleen
 And more generally, can we extend these if-else's to a generic loop to
 check a table like in match_field() so that it can be added easily?

The simple cases are all already handled in a table above.

The if() only contains cases that need special code. I don't think
callbacks would be better here.

-Andi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/9] perf, tools: Add support for reading JSON event files v2

2014-05-15 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

v2: Address review feedback. Rename option to --event-files
Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 250 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 290 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..9305a37 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..cff0869 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..7adbb08 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--events-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 43d4109..8800838 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..086c96f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, events-file, json_file, json file,
+  Read event json file),
OPT_END()
};
const char * const list_usage[] = {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e4c85b8..ed00556 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -25,6 +25,7 @@
 #include util/cpumap.h
 #include util/thread_map.h
 #include util/data.h
+#include util/pmu.h
 
 #include unistd.h
 #include sched.h
@@ -871,6 +872,8 @@ const struct option record_options[] = {
sample transaction flags (special events only)),
OPT_BOOLEAN(0, per-thread, record.opts.target.per_thread,
use per-thread mmaps),
+   

Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-13 Thread Namhyung Kim
On Mon, 12 May 2014 15:51:08 -0700, Andi Kleen wrote:
> From: Andi Kleen 
>
> Add a parser for Intel style JSON event files. This allows
> to use an Intel event list directly with perf. The Intel
> event lists can be quite large and are too big to store
> in unswappable kernel memory.
>
> The parser code knows how to convert the JSON fields
> to perf fields. The conversion code is straight forward.
> It knows (very little) Intel specific information, and can be easily
> extended to handle fields for other CPUs.
>
> The parser code is partially shared with an independent parsing
> library, which is 2-clause BSD licenced. To avoid any conflicts I marked
> those files as BSD licenced too. As part of perf they become GPLv2.
>
> The events are handled using the existing alias machinery.
>
> We output the BriefDescription in perf list.
>
> Right now the json file can be specified as an argument
> to perf stat/record/list. Followon patches will automate this.

I think it'd be good to show an example json event file content in
the changelog and/or comment.

>
> Signed-off-by: Andi Kleen 
> ---
>  tools/perf/Documentation/perf-list.txt   |   6 +
>  tools/perf/Documentation/perf-record.txt |   3 +
>  tools/perf/Documentation/perf-stat.txt   |   3 +
>  tools/perf/Makefile.perf |   2 +
>  tools/perf/builtin-list.c|   2 +
>  tools/perf/builtin-record.c  |   3 +
>  tools/perf/builtin-stat.c|   2 +
>  tools/perf/util/jevents.c| 248 
> +++
>  tools/perf/util/jevents.h|   3 +
>  tools/perf/util/pmu.c|  14 ++
>  tools/perf/util/pmu.h|   2 +
>  11 files changed, 288 insertions(+)
>  create mode 100644 tools/perf/util/jevents.c
>  create mode 100644 tools/perf/util/jevents.h
>
> diff --git a/tools/perf/Documentation/perf-list.txt 
> b/tools/perf/Documentation/perf-list.txt
> index 6fce6a6..d399e04 100644
> --- a/tools/perf/Documentation/perf-list.txt
> +++ b/tools/perf/Documentation/perf-list.txt
> @@ -15,6 +15,12 @@ DESCRIPTION
>  This command displays the symbolic event types which can be selected in the
>  various perf commands with the -e option.
>  
> +OPTIONS
> +---
> +--json-file=::

Hmm.. I think the option name should not be tied to the implementation.
How about --event-file or --event-alias then?


> +Specify JSON event list file to use for parsing events.
> +
> +
>  [[EVENT_MODIFIERS]]
>  EVENT MODIFIERS
>  ---
> diff --git a/tools/perf/Documentation/perf-record.txt 
> b/tools/perf/Documentation/perf-record.txt
> index c71b0f3..8a1e0d9 100644
> --- a/tools/perf/Documentation/perf-record.txt
> +++ b/tools/perf/Documentation/perf-record.txt
> @@ -213,6 +213,9 @@ if combined with -a or -C options.
>  After starting the program, wait msecs before measuring. This is useful to
>  filter out the startup phase of the program, which is often very different.
>  
> +--json-file=::
> +Specify JSON event list file to use for parsing events.
> +
>  SEE ALSO
>  
>  linkperf:perf-stat[1], linkperf:perf-list[1]
> diff --git a/tools/perf/Documentation/perf-stat.txt 
> b/tools/perf/Documentation/perf-stat.txt
> index 29ee857..a946283 100644
> --- a/tools/perf/Documentation/perf-stat.txt
> +++ b/tools/perf/Documentation/perf-stat.txt
> @@ -142,6 +142,9 @@ filter out the startup phase of the program, which is 
> often very different.
>  
>  Print statistics of transactional execution if supported.
>  
> +--json-file=::
> +Specify JSON event list file to use for parsing events.
> +
>  EXAMPLES
>  
>  
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 43d4109..8800838 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -302,6 +302,7 @@ LIB_H += ui/ui.h
>  LIB_H += util/data.h
>  LIB_H += util/jsmn.h
>  LIB_H += util/json.h
> +LIB_H += util/jevents.h
>  
>  LIB_OBJS += $(OUTPUT)util/abspath.o
>  LIB_OBJS += $(OUTPUT)util/alias.o
> @@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
>  LIB_OBJS += $(OUTPUT)util/data.o
>  LIB_OBJS += $(OUTPUT)util/jsmn.o
>  LIB_OBJS += $(OUTPUT)util/json.o
> +LIB_OBJS += $(OUTPUT)util/jevents.o
>  
>  LIB_OBJS += $(OUTPUT)ui/setup.o
>  LIB_OBJS += $(OUTPUT)ui/helpline.o
> diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> index 011195e..ca3dd18 100644
> --- a/tools/perf/builtin-list.c
> +++ b/tools/perf/builtin-list.c
> @@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char 
> *prefix __maybe_unused)
>  {
>   int i;
>   const struct option list_options[] = {
> + OPT_STRING(0, "json-file", _file, "json file",
> +"Read event json file"),
>   OPT_END()
>   };
>   const char * const list_usage[] = {
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index e4c85b8..e4a5be0 100644
> --- a/tools/perf/builtin-record.c
> +++ 

Re: [PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-13 Thread Namhyung Kim
On Mon, 12 May 2014 15:51:08 -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com

 Add a parser for Intel style JSON event files. This allows
 to use an Intel event list directly with perf. The Intel
 event lists can be quite large and are too big to store
 in unswappable kernel memory.

 The parser code knows how to convert the JSON fields
 to perf fields. The conversion code is straight forward.
 It knows (very little) Intel specific information, and can be easily
 extended to handle fields for other CPUs.

 The parser code is partially shared with an independent parsing
 library, which is 2-clause BSD licenced. To avoid any conflicts I marked
 those files as BSD licenced too. As part of perf they become GPLv2.

 The events are handled using the existing alias machinery.

 We output the BriefDescription in perf list.

 Right now the json file can be specified as an argument
 to perf stat/record/list. Followon patches will automate this.

I think it'd be good to show an example json event file content in
the changelog and/or comment.


 Signed-off-by: Andi Kleen a...@linux.intel.com
 ---
  tools/perf/Documentation/perf-list.txt   |   6 +
  tools/perf/Documentation/perf-record.txt |   3 +
  tools/perf/Documentation/perf-stat.txt   |   3 +
  tools/perf/Makefile.perf |   2 +
  tools/perf/builtin-list.c|   2 +
  tools/perf/builtin-record.c  |   3 +
  tools/perf/builtin-stat.c|   2 +
  tools/perf/util/jevents.c| 248 
 +++
  tools/perf/util/jevents.h|   3 +
  tools/perf/util/pmu.c|  14 ++
  tools/perf/util/pmu.h|   2 +
  11 files changed, 288 insertions(+)
  create mode 100644 tools/perf/util/jevents.c
  create mode 100644 tools/perf/util/jevents.h

 diff --git a/tools/perf/Documentation/perf-list.txt 
 b/tools/perf/Documentation/perf-list.txt
 index 6fce6a6..d399e04 100644
 --- a/tools/perf/Documentation/perf-list.txt
 +++ b/tools/perf/Documentation/perf-list.txt
 @@ -15,6 +15,12 @@ DESCRIPTION
  This command displays the symbolic event types which can be selected in the
  various perf commands with the -e option.
  
 +OPTIONS
 +---
 +--json-file=::

Hmm.. I think the option name should not be tied to the implementation.
How about --event-file or --event-alias then?


 +Specify JSON event list file to use for parsing events.
 +
 +
  [[EVENT_MODIFIERS]]
  EVENT MODIFIERS
  ---
 diff --git a/tools/perf/Documentation/perf-record.txt 
 b/tools/perf/Documentation/perf-record.txt
 index c71b0f3..8a1e0d9 100644
 --- a/tools/perf/Documentation/perf-record.txt
 +++ b/tools/perf/Documentation/perf-record.txt
 @@ -213,6 +213,9 @@ if combined with -a or -C options.
  After starting the program, wait msecs before measuring. This is useful to
  filter out the startup phase of the program, which is often very different.
  
 +--json-file=::
 +Specify JSON event list file to use for parsing events.
 +
  SEE ALSO
  
  linkperf:perf-stat[1], linkperf:perf-list[1]
 diff --git a/tools/perf/Documentation/perf-stat.txt 
 b/tools/perf/Documentation/perf-stat.txt
 index 29ee857..a946283 100644
 --- a/tools/perf/Documentation/perf-stat.txt
 +++ b/tools/perf/Documentation/perf-stat.txt
 @@ -142,6 +142,9 @@ filter out the startup phase of the program, which is 
 often very different.
  
  Print statistics of transactional execution if supported.
  
 +--json-file=::
 +Specify JSON event list file to use for parsing events.
 +
  EXAMPLES
  
  
 diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
 index 43d4109..8800838 100644
 --- a/tools/perf/Makefile.perf
 +++ b/tools/perf/Makefile.perf
 @@ -302,6 +302,7 @@ LIB_H += ui/ui.h
  LIB_H += util/data.h
  LIB_H += util/jsmn.h
  LIB_H += util/json.h
 +LIB_H += util/jevents.h
  
  LIB_OBJS += $(OUTPUT)util/abspath.o
  LIB_OBJS += $(OUTPUT)util/alias.o
 @@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
  LIB_OBJS += $(OUTPUT)util/data.o
  LIB_OBJS += $(OUTPUT)util/jsmn.o
  LIB_OBJS += $(OUTPUT)util/json.o
 +LIB_OBJS += $(OUTPUT)util/jevents.o
  
  LIB_OBJS += $(OUTPUT)ui/setup.o
  LIB_OBJS += $(OUTPUT)ui/helpline.o
 diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
 index 011195e..ca3dd18 100644
 --- a/tools/perf/builtin-list.c
 +++ b/tools/perf/builtin-list.c
 @@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char 
 *prefix __maybe_unused)
  {
   int i;
   const struct option list_options[] = {
 + OPT_STRING(0, json-file, json_file, json file,
 +Read event json file),
   OPT_END()
   };
   const char * const list_usage[] = {
 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
 index e4c85b8..e4a5be0 100644
 --- a/tools/perf/builtin-record.c
 +++ b/tools/perf/builtin-record.c
 @@ -25,6 +25,7 @@
  #include util/cpumap.h
  #include util/thread_map.h
  #include 

[PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-12 Thread Andi Kleen
From: Andi Kleen 

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 248 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 288 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..d399e04 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..8a1e0d9 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..a946283 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 43d4109..8800838 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..ca3dd18 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, "json-file", _file, "json file",
+  "Read event json file"),
OPT_END()
};
const char * const list_usage[] = {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e4c85b8..e4a5be0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -25,6 +25,7 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/data.h"
+#include "util/pmu.h"
 
 #include 
 #include 
@@ -871,6 +872,8 @@ const struct option record_options[] = {
"sample transaction flags (special events only)"),
OPT_BOOLEAN(0, "per-thread", _thread,
"use per-thread mmaps"),
+   OPT_STRING(0, "json-file", _file, "json file",
+  "Read event json file"),
OPT_END()
 };
 
diff --git 

[PATCH 3/9] perf, tools: Add support for reading JSON event files

2014-05-12 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

Add a parser for Intel style JSON event files. This allows
to use an Intel event list directly with perf. The Intel
event lists can be quite large and are too big to store
in unswappable kernel memory.

The parser code knows how to convert the JSON fields
to perf fields. The conversion code is straight forward.
It knows (very little) Intel specific information, and can be easily
extended to handle fields for other CPUs.

The parser code is partially shared with an independent parsing
library, which is 2-clause BSD licenced. To avoid any conflicts I marked
those files as BSD licenced too. As part of perf they become GPLv2.

The events are handled using the existing alias machinery.

We output the BriefDescription in perf list.

Right now the json file can be specified as an argument
to perf stat/record/list. Followon patches will automate this.

Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Documentation/perf-list.txt   |   6 +
 tools/perf/Documentation/perf-record.txt |   3 +
 tools/perf/Documentation/perf-stat.txt   |   3 +
 tools/perf/Makefile.perf |   2 +
 tools/perf/builtin-list.c|   2 +
 tools/perf/builtin-record.c  |   3 +
 tools/perf/builtin-stat.c|   2 +
 tools/perf/util/jevents.c| 248 +++
 tools/perf/util/jevents.h|   3 +
 tools/perf/util/pmu.c|  14 ++
 tools/perf/util/pmu.h|   2 +
 11 files changed, 288 insertions(+)
 create mode 100644 tools/perf/util/jevents.c
 create mode 100644 tools/perf/util/jevents.h

diff --git a/tools/perf/Documentation/perf-list.txt 
b/tools/perf/Documentation/perf-list.txt
index 6fce6a6..d399e04 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,12 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+---
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---
diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index c71b0f3..8a1e0d9 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -213,6 +213,9 @@ if combined with -a or -C options.
 After starting the program, wait msecs before measuring. This is useful to
 filter out the startup phase of the program, which is often very different.
 
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
 SEE ALSO
 
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/Documentation/perf-stat.txt 
b/tools/perf/Documentation/perf-stat.txt
index 29ee857..a946283 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -142,6 +142,9 @@ filter out the startup phase of the program, which is often 
very different.
 
 Print statistics of transactional execution if supported.
 
+--json-file=::
+Specify JSON event list file to use for parsing events.
+
 EXAMPLES
 
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 43d4109..8800838 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -302,6 +302,7 @@ LIB_H += ui/ui.h
 LIB_H += util/data.h
 LIB_H += util/jsmn.h
 LIB_H += util/json.h
+LIB_H += util/jevents.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -377,6 +378,7 @@ LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
 LIB_OBJS += $(OUTPUT)util/jsmn.o
 LIB_OBJS += $(OUTPUT)util/json.o
+LIB_OBJS += $(OUTPUT)util/jevents.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 011195e..ca3dd18 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -20,6 +20,8 @@ int cmd_list(int argc, const char **argv, const char *prefix 
__maybe_unused)
 {
int i;
const struct option list_options[] = {
+   OPT_STRING(0, json-file, json_file, json file,
+  Read event json file),
OPT_END()
};
const char * const list_usage[] = {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e4c85b8..e4a5be0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -25,6 +25,7 @@
 #include util/cpumap.h
 #include util/thread_map.h
 #include util/data.h
+#include util/pmu.h
 
 #include unistd.h
 #include sched.h
@@ -871,6 +872,8 @@ const struct option record_options[] = {
sample transaction flags (special events only)),
OPT_BOOLEAN(0, per-thread, record.opts.target.per_thread,
use per-thread mmaps),
+   OPT_STRING(0, json-file, json_file, json file,
+  Read