[PATCH 15/23] perf tools: Introduce perf_mem__snp_scnprintf function
From: Jiri Olsa
Date: Mon Feb 15 2016 - 03:38:07 EST
Move meminfo's snp display function into mem-events.c
object, so it could be reused later from script code.
Link: http://lkml.kernel.org/n/tip-zhd9q561o49xzhrtg8cz5jui@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/mem-events.c | 34 ++++++++++++++++++++++++++++++++++
tools/perf/util/mem-events.h | 1 +
tools/perf/util/sort.c | 31 +------------------------------
3 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index f291f93ac11d..1d57defe6ea7 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -217,3 +217,37 @@ void perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
if (miss)
strncat(out, " miss", sz - l);
}
+
+static const char * const snoop_access[] = {
+ "N/A",
+ "None",
+ "Miss",
+ "Hit",
+ "HitM",
+};
+
+void perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
+{
+ size_t i, l = 0;
+ u64 m = PERF_MEM_SNOOP_NA;
+
+ sz -= 1; /* -1 for null termination */
+ out[0] = '\0';
+
+ if (mem_info)
+ m = mem_info->data_src.mem_snoop;
+
+ for (i = 0; m && i < ARRAY_SIZE(snoop_access); i++, m >>= 1) {
+ if (!(m & 0x1))
+ continue;
+ if (l) {
+ strcat(out, " or ");
+ l += 4;
+ }
+ strncat(out, snoop_access[i], sz - l);
+ l += strlen(snoop_access[i]);
+ }
+
+ if (*out == '\0')
+ strcpy(out, "N/A");
+}
diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index fc6d94fc96e8..7b9e172cfa72 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -47,5 +47,6 @@ char *perf_mem_events__name(int i);
struct mem_info;
void perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
void perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
+void perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
#endif /* __PERF_MEM_EVENTS_H */
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index c7b52f4987d8..de936ce324b7 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -891,41 +891,12 @@ sort__snoop_cmp(struct hist_entry *left, struct hist_entry *right)
return (int64_t)(data_src_r.mem_snoop - data_src_l.mem_snoop);
}
-static const char * const snoop_access[] = {
- "N/A",
- "None",
- "Miss",
- "Hit",
- "HitM",
-};
-
static int hist_entry__snoop_snprintf(struct hist_entry *he, char *bf,
size_t size, unsigned int width)
{
char out[64];
- size_t sz = sizeof(out) - 1; /* -1 for null termination */
- size_t i, l = 0;
- u64 m = PERF_MEM_SNOOP_NA;
-
- out[0] = '\0';
-
- if (he->mem_info)
- m = he->mem_info->data_src.mem_snoop;
-
- for (i = 0; m && i < ARRAY_SIZE(snoop_access); i++, m >>= 1) {
- if (!(m & 0x1))
- continue;
- if (l) {
- strcat(out, " or ");
- l += 4;
- }
- strncat(out, snoop_access[i], sz - l);
- l += strlen(snoop_access[i]);
- }
-
- if (*out == '\0')
- strcpy(out, "N/A");
+ perf_mem__snp_scnprintf(out, sizeof(out), he->mem_info);
return repsep_snprintf(bf, size, "%-*s", width, out);
}
--
2.4.3