[PATCH v4 05/12] perf util: Create the runtime_stat init/free function

From: Jin Yao
Date: Wed Nov 29 2017 - 23:04:38 EST


It mainly initializes the rblist in struct runtime_stat.

For the original rblist 'runtime_saved_values', it's still there
for keeping the patch bisectable. The rblist 'runtime_saved_values'
will be removed in later patch at switching time.

Signed-off-by: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
---
tools/perf/util/stat-shadow.c | 17 +++++++++++++++++
tools/perf/util/stat.h | 3 +++
2 files changed, 20 insertions(+)

diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 528be3e..7098275 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -40,6 +40,7 @@ static struct stats runtime_aperf_stats[NUM_CTX][MAX_NR_CPUS];
static struct rblist runtime_saved_values;
static bool have_frontend_stalled;

+struct runtime_stat rt_stat;
struct stats walltime_nsecs_stats;

struct saved_value {
@@ -134,6 +135,21 @@ static struct saved_value *saved_value_lookup(struct perf_evsel *evsel,
return NULL;
}

+void runtime_stat__init(struct runtime_stat *stat)
+{
+ struct rblist *rblist = &stat->value_list;
+
+ rblist__init(rblist);
+ rblist->node_cmp = saved_value_cmp;
+ rblist->node_new = saved_value_new;
+ rblist->node_delete = saved_value_delete;
+}
+
+void runtime_stat__free(struct runtime_stat *stat)
+{
+ rblist__reset(&stat->value_list);
+}
+
void perf_stat__init_shadow_stats(void)
{
have_frontend_stalled = pmu_have_event("cpu", "stalled-cycles-frontend");
@@ -141,6 +157,7 @@ void perf_stat__init_shadow_stats(void)
runtime_saved_values.node_cmp = saved_value_cmp;
runtime_saved_values.node_new = saved_value_new;
runtime_saved_values.node_delete = saved_value_delete;
+ runtime_stat__init(&rt_stat);
}

static int evsel_context(struct perf_evsel *evsel)
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 290c51e..2d61e37 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -118,12 +118,15 @@ bool __perf_evsel_stat__is(struct perf_evsel *evsel,

void perf_stat_evsel_id_init(struct perf_evsel *evsel);

+extern struct runtime_stat rt_stat;
extern struct stats walltime_nsecs_stats;

typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
const char *fmt, double val);
typedef void (*new_line_t )(void *ctx);

+void runtime_stat__init(struct runtime_stat *stat);
+void runtime_stat__free(struct runtime_stat *stat);
void perf_stat__init_shadow_stats(void);
void perf_stat__reset_shadow_stats(void);
void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
--
2.7.4