summaryrefslogtreecommitdiff
path: root/tools/perf/util/s390-sample-raw.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/s390-sample-raw.c')
-rw-r--r--tools/perf/util/s390-sample-raw.c86
1 files changed, 67 insertions, 19 deletions
diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c
index 335217bb532b..52bbca5c56c8 100644
--- a/tools/perf/util/s390-sample-raw.c
+++ b/tools/perf/util/s390-sample-raw.c
@@ -19,12 +19,14 @@
#include <sys/stat.h>
#include <linux/compiler.h>
+#include <linux/err.h>
#include <asm/byteorder.h>
#include "debug.h"
#include "session.h"
#include "evlist.h"
#include "color.h"
+#include "hashmap.h"
#include "sample-raw.h"
#include "s390-cpumcf-kernel.h"
#include "util/pmu.h"
@@ -132,8 +134,8 @@ static int get_counterset_start(int setnr)
}
struct get_counter_name_data {
- int wanted;
- char *result;
+ long wanted;
+ const char *result;
};
static int get_counter_name_callback(void *vdata, struct pmu_event_info *info)
@@ -151,12 +153,22 @@ static int get_counter_name_callback(void *vdata, struct pmu_event_info *info)
rc = sscanf(event_str, "event=%x", &event_nr);
if (rc == 1 && event_nr == data->wanted) {
- data->result = strdup(info->name);
+ data->result = info->name;
return 1; /* Terminate the search. */
}
return 0;
}
+static size_t get_counter_name_hash_fn(long key, void *ctx __maybe_unused)
+{
+ return key;
+}
+
+static bool get_counter_name_hashmap_equal_fn(long key1, long key2, void *ctx __maybe_unused)
+{
+ return key1 == key2;
+}
+
/* Scan the PMU and extract the logical name of a counter from the event. Input
* is the counter set and counter number with in the set. Construct the event
* number and use this as key. If they match return the name of this counter.
@@ -164,21 +176,55 @@ static int get_counter_name_callback(void *vdata, struct pmu_event_info *info)
*/
static char *get_counter_name(int set, int nr, struct perf_pmu *pmu)
{
+ static struct hashmap *cache;
+ static struct perf_pmu *cache_pmu;
+ long cache_key = get_counterset_start(set) + nr;
struct get_counter_name_data data = {
- .wanted = get_counterset_start(set) + nr,
+ .wanted = cache_key,
.result = NULL,
};
+ char *result = NULL;
if (!pmu)
return NULL;
+ if (cache_pmu == pmu && hashmap__find(cache, cache_key, &result))
+ return strdup(result);
+
perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=*/ true,
&data, get_counter_name_callback);
- return data.result;
+
+ result = strdup(data.result ?: "<unknown>");
+
+ if (cache_pmu == NULL) {
+ struct hashmap *tmp = hashmap__new(get_counter_name_hash_fn,
+ get_counter_name_hashmap_equal_fn,
+ /*ctx=*/NULL);
+
+ if (!IS_ERR(tmp)) {
+ cache = tmp;
+ cache_pmu = pmu;
+ }
+ }
+
+ if (cache_pmu == pmu && result) {
+ char *old_value = NULL, *new_value = strdup(result);
+
+ if (new_value) {
+ hashmap__set(cache, cache_key, new_value, /*old_key=*/NULL, &old_value);
+ /*
+ * Free in case of a race, but resizing would be broken
+ * in that case.
+ */
+ free(old_value);
+ }
+ }
+ return result;
}
-static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample)
+static void s390_cpumcfdg_dump(struct perf_sample *sample)
{
+ struct perf_pmu *pmu = sample->evsel->pmu;
size_t i, len = sample->raw_size, offset = 0;
unsigned char *buf = sample->raw_data;
const char *color = PERF_COLOR_BLUE;
@@ -239,8 +285,9 @@ static bool s390_pai_all_test(struct perf_sample *sample)
return true;
}
-static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample)
+static void s390_pai_all_dump(struct perf_sample *sample)
{
+ struct evsel *evsel = sample->evsel;
size_t len = sample->raw_size, offset = 0;
unsigned char *p = sample->raw_data;
const char *color = PERF_COLOR_BLUE;
@@ -287,31 +334,32 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,
struct perf_sample *sample)
{
const char *pai_name;
- struct evsel *evsel;
if (event->header.type != PERF_RECORD_SAMPLE)
return;
- evsel = evlist__event2evsel(evlist, event);
- if (!evsel)
- return;
+ if (!sample->evsel) {
+ sample->evsel = evlist__event2evsel(evlist, event);
+ if (!sample->evsel)
+ return;
+ }
/* Check for raw data in sample */
if (!sample->raw_size || !sample->raw_data)
return;
/* Display raw data on screen */
- if (evsel->core.attr.config == PERF_EVENT_CPUM_CF_DIAG) {
- if (!evsel->pmu)
- evsel->pmu = perf_pmus__find("cpum_cf");
+ if (sample->evsel->core.attr.config == PERF_EVENT_CPUM_CF_DIAG) {
+ if (!sample->evsel->pmu)
+ sample->evsel->pmu = perf_pmus__find("cpum_cf");
if (!s390_cpumcfdg_testctr(sample))
pr_err("Invalid counter set data encountered\n");
else
- s390_cpumcfdg_dump(evsel->pmu, sample);
+ s390_cpumcfdg_dump(sample);
return;
}
- switch (evsel->core.attr.config) {
+ switch (sample->evsel->core.attr.config) {
case PERF_EVENT_PAI_NNPA_ALL:
pai_name = "NNPA_ALL";
break;
@@ -325,8 +373,8 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,
if (!s390_pai_all_test(sample)) {
pr_err("Invalid %s raw data encountered\n", pai_name);
} else {
- if (!evsel->pmu)
- evsel->pmu = perf_pmus__find_by_type(evsel->core.attr.type);
- s390_pai_all_dump(evsel, sample);
+ if (!sample->evsel->pmu)
+ sample->evsel->pmu = perf_pmus__find_by_type(sample->evsel->core.attr.type);
+ s390_pai_all_dump(sample);
}
}