Commit 3ba36d36 authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf vendor events: Support metric_group and no event name in JSON parser

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: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170831194036.30146-3-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5a5dfe4b
...@@ -292,7 +292,7 @@ static int print_events_table_entry(void *data, char *name, char *event, ...@@ -292,7 +292,7 @@ static int print_events_table_entry(void *data, char *name, char *event,
char *desc, char *long_desc, char *desc, char *long_desc,
char *pmu, char *unit, char *perpkg, char *pmu, char *unit, char *perpkg,
char *metric_expr, char *metric_expr,
char *metric_name) char *metric_name, char *metric_group)
{ {
struct perf_entry_data *pd = data; struct perf_entry_data *pd = data;
FILE *outfp = pd->outfp; FILE *outfp = pd->outfp;
...@@ -304,8 +304,10 @@ static int print_events_table_entry(void *data, char *name, char *event, ...@@ -304,8 +304,10 @@ static int print_events_table_entry(void *data, char *name, char *event,
*/ */
fprintf(outfp, "{\n"); fprintf(outfp, "{\n");
fprintf(outfp, "\t.name = \"%s\",\n", name); if (name)
fprintf(outfp, "\t.event = \"%s\",\n", event); 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.desc = \"%s\",\n", desc);
fprintf(outfp, "\t.topic = \"%s\",\n", topic); fprintf(outfp, "\t.topic = \"%s\",\n", topic);
if (long_desc && long_desc[0]) if (long_desc && long_desc[0])
...@@ -320,6 +322,8 @@ static int print_events_table_entry(void *data, char *name, char *event, ...@@ -320,6 +322,8 @@ static int print_events_table_entry(void *data, char *name, char *event,
fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr); fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
if (metric_name) if (metric_name)
fprintf(outfp, "\t.metric_name = \"%s\",\n", 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"); fprintf(outfp, "},\n");
return 0; return 0;
...@@ -357,6 +361,9 @@ static char *real_event(const char *name, char *event) ...@@ -357,6 +361,9 @@ static char *real_event(const char *name, char *event)
{ {
int i; int i;
if (!name)
return NULL;
for (i = 0; fixed[i].name; i++) for (i = 0; fixed[i].name; i++)
if (!strcasecmp(name, fixed[i].name)) if (!strcasecmp(name, fixed[i].name))
return (char *)fixed[i].event; return (char *)fixed[i].event;
...@@ -369,7 +376,7 @@ int json_events(const char *fn, ...@@ -369,7 +376,7 @@ int json_events(const char *fn,
char *long_desc, char *long_desc,
char *pmu, char *unit, char *perpkg, char *pmu, char *unit, char *perpkg,
char *metric_expr, char *metric_expr,
char *metric_name), char *metric_name, char *metric_group),
void *data) void *data)
{ {
int err = -EIO; int err = -EIO;
...@@ -397,6 +404,7 @@ int json_events(const char *fn, ...@@ -397,6 +404,7 @@ int json_events(const char *fn,
char *unit = NULL; char *unit = NULL;
char *metric_expr = NULL; char *metric_expr = NULL;
char *metric_name = NULL; char *metric_name = NULL;
char *metric_group = NULL;
unsigned long long eventcode = 0; unsigned long long eventcode = 0;
struct msrmap *msr = NULL; struct msrmap *msr = NULL;
jsmntok_t *msrval = NULL; jsmntok_t *msrval = NULL;
...@@ -476,6 +484,8 @@ int json_events(const char *fn, ...@@ -476,6 +484,8 @@ int json_events(const char *fn,
addfield(map, &perpkg, "", "", val); addfield(map, &perpkg, "", "", val);
} else if (json_streq(map, field, "MetricName")) { } else if (json_streq(map, field, "MetricName")) {
addfield(map, &metric_name, "", "", val); addfield(map, &metric_name, "", "", val);
} else if (json_streq(map, field, "MetricGroup")) {
addfield(map, &metric_group, "", "", val);
} else if (json_streq(map, field, "MetricExpr")) { } else if (json_streq(map, field, "MetricExpr")) {
addfield(map, &metric_expr, "", "", val); addfield(map, &metric_expr, "", "", val);
for (s = metric_expr; *s; s++) for (s = metric_expr; *s; s++)
...@@ -501,10 +511,11 @@ int json_events(const char *fn, ...@@ -501,10 +511,11 @@ int json_events(const char *fn,
addfield(map, &event, ",", filter, NULL); addfield(map, &event, ",", filter, NULL);
if (msr != NULL) if (msr != NULL)
addfield(map, &event, ",", msr->pname, msrval); addfield(map, &event, ",", msr->pname, msrval);
fixname(name); if (name)
fixname(name);
err = func(data, name, real_event(name, event), desc, long_desc, 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(event);
free(desc); free(desc);
free(name); free(name);
...@@ -516,6 +527,7 @@ int json_events(const char *fn, ...@@ -516,6 +527,7 @@ int json_events(const char *fn,
free(unit); free(unit);
free(metric_expr); free(metric_expr);
free(metric_name); free(metric_name);
free(metric_group);
if (err) if (err)
break; break;
tok += j; tok += j;
......
...@@ -6,7 +6,7 @@ int json_events(const char *fn, ...@@ -6,7 +6,7 @@ int json_events(const char *fn,
char *long_desc, char *long_desc,
char *pmu, char *pmu,
char *unit, char *perpkg, char *metric_expr, char *unit, char *perpkg, char *metric_expr,
char *metric_name), char *metric_name, char *metric_group),
void *data); void *data);
char *get_cpu_str(void); char *get_cpu_str(void);
......
...@@ -15,6 +15,7 @@ struct pmu_event { ...@@ -15,6 +15,7 @@ struct pmu_event {
const char *perpkg; const char *perpkg;
const char *metric_expr; const char *metric_expr;
const char *metric_name; const char *metric_name;
const char *metric_group;
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment