[PATCH 09/15] perf tools: Change perf_mem__tlb_scnprintf to return nb of displayed bytes

From: Jiri Olsa
Date: Wed Feb 24 2016 - 03:47:47 EST


Moving strncat/strcpy calls into scnprintf to easily track
number of displayed bytes. It will be used in following patch.

Link: http://lkml.kernel.org/n/tip-9q9h9trua9zljnw26c56memh@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/mem-events.c | 13 +++++++------
tools/perf/util/mem-events.h | 2 +-
2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 3b16128234b7..7a4fb7e8159d 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -110,7 +110,7 @@ static const char * const tlb_access[] = {
"Fault",
};

-void perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
+int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
size_t l = 0, i;
u64 m = PERF_MEM_TLB_NA;
@@ -135,15 +135,16 @@ void perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
strcat(out, " or ");
l += 4;
}
- strncat(out, tlb_access[i], sz - l);
- l += strlen(tlb_access[i]);
+ l += scnprintf(out + l, sz - l, tlb_access[i]);
}
if (*out == '\0')
- strcpy(out, "N/A");
+ l += scnprintf(out, sz - l, "N/A");
if (hit)
- strncat(out, " hit", sz - l);
+ l += scnprintf(out + l, sz - l, " hit");
if (miss)
- strncat(out, " miss", sz - l);
+ l += scnprintf(out + l, sz - l, " miss");
+
+ return l;
}

static const char * const mem_lvl[] = {
diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index 06750f640586..c6fb8a741fbb 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -26,7 +26,7 @@ int perf_mem_events__init(void);
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);
+int 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);
void perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
--
2.4.3