aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/mem-events.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-02-24 03:46:47 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-02-24 08:20:28 -0500
commit071e9a1e12dceaec6f9d3ffe6e77ee68364166d6 (patch)
treeffb30685af7fb259be96aec0b664d400c7974105 /tools/perf/util/mem-events.c
parent0c877d759d3a62a01d75dc6de4a923a686bb285a (diff)
perf tools: Introduce perf_mem__lvl_scnprintf function
Move meminfo's lvl display function into mem-events.c object, so it could be reused later from script code. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1456303616-26926-7-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/mem-events.c')
-rw-r--r--tools/perf/util/mem-events.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 4be3eb74001b..bddb1217d129 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -130,3 +130,56 @@ void perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
130 if (miss) 130 if (miss)
131 strncat(out, " miss", sz - l); 131 strncat(out, " miss", sz - l);
132} 132}
133
134static const char * const mem_lvl[] = {
135 "N/A",
136 "HIT",
137 "MISS",
138 "L1",
139 "LFB",
140 "L2",
141 "L3",
142 "Local RAM",
143 "Remote RAM (1 hop)",
144 "Remote RAM (2 hops)",
145 "Remote Cache (1 hop)",
146 "Remote Cache (2 hops)",
147 "I/O",
148 "Uncached",
149};
150
151void perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
152{
153 size_t i, l = 0;
154 u64 m = PERF_MEM_LVL_NA;
155 u64 hit, miss;
156
157 if (mem_info)
158 m = mem_info->data_src.mem_lvl;
159
160 sz -= 1; /* -1 for null termination */
161 out[0] = '\0';
162
163 hit = m & PERF_MEM_LVL_HIT;
164 miss = m & PERF_MEM_LVL_MISS;
165
166 /* already taken care of */
167 m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
168
169 for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
170 if (!(m & 0x1))
171 continue;
172 if (l) {
173 strcat(out, " or ");
174 l += 4;
175 }
176 strncat(out, mem_lvl[i], sz - l);
177 l += strlen(mem_lvl[i]);
178 }
179 if (*out == '\0')
180 strcpy(out, "N/A");
181 if (hit)
182 strncat(out, " hit", sz - l);
183 if (miss)
184 strncat(out, " miss", sz - l);
185}