From: Andi Kleen <a...@linux.intel.com>

Some enhancements to the JSON parser to prepare for metrics support

- Parse the new MetricGroup field
- Support JSON events with no event name, that have only MetricName.

Signed-off-by: Andi Kleen <a...@linux.intel.com>
---
 tools/perf/pmu-events/jevents.c    | 24 ++++++++++++++++++------
 tools/perf/pmu-events/jevents.h    |  2 +-
 tools/perf/pmu-events/pmu-events.h |  1 +
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index 2350f6099a46..8e7ced6a0517 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -290,7 +290,7 @@ static int print_events_table_entry(void *data, char *name, 
char *event,
                                    char *desc, char *long_desc,
                                    char *pmu, char *unit, char *perpkg,
                                    char *metric_expr,
-                                   char *metric_name)
+                                   char *metric_name, char *metric_group)
 {
        struct perf_entry_data *pd = data;
        FILE *outfp = pd->outfp;
@@ -302,8 +302,10 @@ static int print_events_table_entry(void *data, char 
*name, char *event,
         */
        fprintf(outfp, "{\n");
 
-       fprintf(outfp, "\t.name = \"%s\",\n", name);
-       fprintf(outfp, "\t.event = \"%s\",\n", event);
+       if (name)
+               fprintf(outfp, "\t.name = \"%s\",\n", name);
+       if (event)
+               fprintf(outfp, "\t.event = \"%s\",\n", event);
        fprintf(outfp, "\t.desc = \"%s\",\n", desc);
        fprintf(outfp, "\t.topic = \"%s\",\n", topic);
        if (long_desc && long_desc[0])
@@ -318,6 +320,8 @@ static int print_events_table_entry(void *data, char *name, 
char *event,
                fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
        if (metric_name)
                fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name);
+       if (metric_group)
+               fprintf(outfp, "\t.metric_group = \"%s\",\n", metric_group);
        fprintf(outfp, "},\n");
 
        return 0;
@@ -355,6 +359,9 @@ static char *real_event(const char *name, char *event)
 {
        int i;
 
+       if (!name)
+               return NULL;
+
        for (i = 0; fixed[i].name; i++)
                if (!strcasecmp(name, fixed[i].name))
                        return (char *)fixed[i].event;
@@ -367,7 +374,7 @@ int json_events(const char *fn,
                      char *long_desc,
                      char *pmu, char *unit, char *perpkg,
                      char *metric_expr,
-                     char *metric_name),
+                     char *metric_name, char *metric_group),
          void *data)
 {
        int err = -EIO;
@@ -395,6 +402,7 @@ int json_events(const char *fn,
                char *unit = NULL;
                char *metric_expr = NULL;
                char *metric_name = NULL;
+               char *metric_group = NULL;
                unsigned long long eventcode = 0;
                struct msrmap *msr = NULL;
                jsmntok_t *msrval = NULL;
@@ -474,6 +482,8 @@ int json_events(const char *fn,
                                addfield(map, &perpkg, "", "", val);
                        } else if (json_streq(map, field, "MetricName")) {
                                addfield(map, &metric_name, "", "", val);
+                       } else if (json_streq(map, field, "MetricGroup")) {
+                               addfield(map, &metric_group, "", "", val);
                        } else if (json_streq(map, field, "MetricExpr")) {
                                addfield(map, &metric_expr, "", "", val);
                                for (s = metric_expr; *s; s++)
@@ -499,10 +509,11 @@ int json_events(const char *fn,
                        addfield(map, &event, ",", filter, NULL);
                if (msr != NULL)
                        addfield(map, &event, ",", msr->pname, msrval);
-               fixname(name);
+               if (name)
+                       fixname(name);
 
                err = func(data, name, real_event(name, event), desc, long_desc,
-                               pmu, unit, perpkg, metric_expr, metric_name);
+                          pmu, unit, perpkg, metric_expr, metric_name, 
metric_group);
                free(event);
                free(desc);
                free(name);
@@ -514,6 +525,7 @@ int json_events(const char *fn,
                free(unit);
                free(metric_expr);
                free(metric_name);
+               free(metric_group);
                if (err)
                        break;
                tok += j;
diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h
index 611fac01913d..557994754410 100644
--- a/tools/perf/pmu-events/jevents.h
+++ b/tools/perf/pmu-events/jevents.h
@@ -6,7 +6,7 @@ int json_events(const char *fn,
                                char *long_desc,
                                char *pmu,
                                char *unit, char *perpkg, char *metric_expr,
-                               char *metric_name),
+                               char *metric_name, char *metric_group),
                void *data);
 char *get_cpu_str(void);
 
diff --git a/tools/perf/pmu-events/pmu-events.h 
b/tools/perf/pmu-events/pmu-events.h
index 569eab3688dd..94fa1720f6fd 100644
--- a/tools/perf/pmu-events/pmu-events.h
+++ b/tools/perf/pmu-events/pmu-events.h
@@ -15,6 +15,7 @@ struct pmu_event {
        const char *perpkg;
        const char *metric_expr;
        const char *metric_name;
+       const char *metric_group;
 };
 
 /*
-- 
2.9.4

Reply via email to