perf metric: Add referenced metrics to hash data
Adding referenced metrics to the parsing context so they can be resolved during the metric processing. Adding expr__add_ref function to store referenced metrics into parse context. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Reviewed-by: Kajol Jain <kjain@linux.ibm.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: John Garry <john.garry@huawei.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Clarke <pc@us.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20200719181320.785305-11-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
4ea2896715
commit
fc393839c1
@@ -4,10 +4,14 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "metricgroup.h"
|
||||
#include "debug.h"
|
||||
#include "expr.h"
|
||||
#include "expr-bison.h"
|
||||
#include "expr-flex.h"
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/zalloc.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef PARSER_DEBUG
|
||||
extern int expr_debug;
|
||||
@@ -63,6 +67,7 @@ int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val)
|
||||
if (!data_ptr)
|
||||
return -ENOMEM;
|
||||
data_ptr->val = val;
|
||||
data_ptr->is_ref = false;
|
||||
|
||||
ret = hashmap__set(&ctx->ids, id, data_ptr,
|
||||
(const void **)&old_key, (void **)&old_data);
|
||||
@@ -73,6 +78,55 @@ int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref)
|
||||
{
|
||||
struct expr_id_data *data_ptr = NULL, *old_data = NULL;
|
||||
char *old_key = NULL;
|
||||
char *name, *p;
|
||||
int ret;
|
||||
|
||||
data_ptr = zalloc(sizeof(*data_ptr));
|
||||
if (!data_ptr)
|
||||
return -ENOMEM;
|
||||
|
||||
name = strdup(ref->metric_name);
|
||||
if (!name) {
|
||||
free(data_ptr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* The jevents tool converts all metric expressions
|
||||
* to lowercase, including metric references, hence
|
||||
* we need to add lowercase name for metric, so it's
|
||||
* properly found.
|
||||
*/
|
||||
for (p = name; *p; p++)
|
||||
*p = tolower(*p);
|
||||
|
||||
/*
|
||||
* Intentionally passing just const char pointers,
|
||||
* originally from 'struct pmu_event' object.
|
||||
* We don't need to change them, so there's no
|
||||
* need to create our own copy.
|
||||
*/
|
||||
data_ptr->ref.metric_name = ref->metric_name;
|
||||
data_ptr->ref.metric_expr = ref->metric_expr;
|
||||
data_ptr->is_ref = true;
|
||||
|
||||
ret = hashmap__set(&ctx->ids, name, data_ptr,
|
||||
(const void **)&old_key, (void **)&old_data);
|
||||
if (ret)
|
||||
free(data_ptr);
|
||||
|
||||
pr_debug2("adding ref metric %s: %s\n",
|
||||
ref->metric_name, ref->metric_expr);
|
||||
|
||||
free(old_key);
|
||||
free(old_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
|
||||
struct expr_id_data **data)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user