aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-10-25 13:21:31 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-10-30 10:46:23 -0400
commit579e5ff629b17744f62473f314768de8b6f1e66c (patch)
treeb87465a92e71f447639096eb2b38e72e9e0fa12e /tools/perf
parent794f594e0c3be6199e0b3e2324280e8785806fb6 (diff)
perf beauty: Introduce strarray__scnprintf_flags()
Generalizing pkey_alloc__scnprintf_access_rights(), so that we can use it with other flags-like arguments, such as mount's mountflags argument. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Benjamin Peterson <benjamin@python.org> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-o3ymi3104m8moaz9865g09w9@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/trace/beauty/beauty.h1
-rw-r--r--tools/perf/trace/beauty/pkey_alloc.c27
2 files changed, 17 insertions, 11 deletions
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 2570152d3909..a1806c4f3ccd 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -24,6 +24,7 @@ struct strarray {
24} 24}
25 25
26size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, int val); 26size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, int val);
27size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, unsigned long flags);
27 28
28struct trace; 29struct trace;
29struct thread; 30struct thread;
diff --git a/tools/perf/trace/beauty/pkey_alloc.c b/tools/perf/trace/beauty/pkey_alloc.c
index d3e5188a9bef..1b8ed4cac815 100644
--- a/tools/perf/trace/beauty/pkey_alloc.c
+++ b/tools/perf/trace/beauty/pkey_alloc.c
@@ -9,31 +9,28 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/log2.h> 10#include <linux/log2.h>
11 11
12static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size) 12size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, unsigned long flags)
13{ 13{
14 int i, printed = 0; 14 int i, printed = 0;
15 15
16#include "trace/beauty/generated/pkey_alloc_access_rights_array.c" 16 if (flags == 0) {
17 static DEFINE_STRARRAY(pkey_alloc_access_rights); 17 const char *s = sa->entries[0];
18
19 if (access_rights == 0) {
20 const char *s = strarray__pkey_alloc_access_rights.entries[0];
21 if (s) 18 if (s)
22 return scnprintf(bf, size, "%s", s); 19 return scnprintf(bf, size, "%s", s);
23 return scnprintf(bf, size, "%d", 0); 20 return scnprintf(bf, size, "%d", 0);
24 } 21 }
25 22
26 for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) { 23 for (i = 1; i < sa->nr_entries; ++i) {
27 int bit = 1 << (i - 1); 24 unsigned long bit = 1UL << (i - 1);
28 25
29 if (!(access_rights & bit)) 26 if (!(flags & bit))
30 continue; 27 continue;
31 28
32 if (printed != 0) 29 if (printed != 0)
33 printed += scnprintf(bf + printed, size - printed, "|"); 30 printed += scnprintf(bf + printed, size - printed, "|");
34 31
35 if (strarray__pkey_alloc_access_rights.entries[i] != NULL) 32 if (sa->entries[i] != NULL)
36 printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]); 33 printed += scnprintf(bf + printed, size - printed, "%s", sa->entries[i]);
37 else 34 else
38 printed += scnprintf(bf + printed, size - printed, "0x%#", bit); 35 printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
39 } 36 }
@@ -41,6 +38,14 @@ static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, s
41 return printed; 38 return printed;
42} 39}
43 40
41static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
42{
43#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
44 static DEFINE_STRARRAY(pkey_alloc_access_rights);
45
46 return strarray__scnprintf_flags(&strarray__pkey_alloc_access_rights, bf, size, access_rights);
47}
48
44size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg) 49size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
45{ 50{
46 unsigned long cmd = arg->val; 51 unsigned long cmd = arg->val;