summaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2021-05-25 12:51:06 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2021-05-25 10:07:17 -0300
commit54cd8b03245291c8509f96ed12a55eb1cb7dddf8 (patch)
treee2e85d8c705611357f6333265a3286ff1318cc6c /tools/perf/builtin-script.c
parent3f8e009e01c4ed9f75c10f33936990f3a3d39fcd (diff)
downloadlinux-54cd8b03245291c8509f96ed12a55eb1cb7dddf8.tar.gz
linux-54cd8b03245291c8509f96ed12a55eb1cb7dddf8.tar.bz2
linux-54cd8b03245291c8509f96ed12a55eb1cb7dddf8.zip
perf script: Factor out perf_sample__sprintf_flags()
Factor out perf_sample__sprintf_flags() so it can be reused. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: https://lore.kernel.org/r/20210525095112.1399-5-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index f502d1c8a353..69bce65ea430 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1553,41 +1553,49 @@ static const char *sample_flags_to_name(u32 flags)
return NULL;
}
-static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
+int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz)
{
const char *chars = PERF_IP_FLAG_CHARS;
- const int n = strlen(PERF_IP_FLAG_CHARS);
+ const size_t n = strlen(PERF_IP_FLAG_CHARS);
bool in_tx = flags & PERF_IP_FLAG_IN_TX;
const char *name = NULL;
- char str[33];
- int i, pos = 0;
+ size_t i, pos = 0;
name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX);
if (name)
- return fprintf(fp, " %-15s%4s ", name, in_tx ? "(x)" : "");
+ return snprintf(str, sz, "%-15s%4s", name, in_tx ? "(x)" : "");
if (flags & PERF_IP_FLAG_TRACE_BEGIN) {
name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN));
if (name)
- return fprintf(fp, " tr strt %-7s%4s ", name, in_tx ? "(x)" : "");
+ return snprintf(str, sz, "tr strt %-7s%4s", name, in_tx ? "(x)" : "");
}
if (flags & PERF_IP_FLAG_TRACE_END) {
name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END));
if (name)
- return fprintf(fp, " tr end %-7s%4s ", name, in_tx ? "(x)" : "");
+ return snprintf(str, sz, "tr end %-7s%4s", name, in_tx ? "(x)" : "");
}
for (i = 0; i < n; i++, flags >>= 1) {
- if (flags & 1)
+ if ((flags & 1) && pos < sz)
str[pos++] = chars[i];
}
for (; i < 32; i++, flags >>= 1) {
- if (flags & 1)
+ if ((flags & 1) && pos < sz)
str[pos++] = '?';
}
- str[pos] = 0;
+ if (pos < sz)
+ str[pos] = 0;
+
+ return pos;
+}
+
+static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
+{
+ char str[SAMPLE_FLAGS_BUF_SIZE];
+ perf_sample__sprintf_flags(flags, str, sizeof(str));
return fprintf(fp, " %-19s ", str);
}