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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 794f594e
...@@ -24,6 +24,7 @@ struct strarray { ...@@ -24,6 +24,7 @@ struct strarray {
} }
size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, int val); size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, int val);
size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, unsigned long flags);
struct trace; struct trace;
struct thread; struct thread;
......
...@@ -9,31 +9,28 @@ ...@@ -9,31 +9,28 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/log2.h> #include <linux/log2.h>
static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size) size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, unsigned long flags)
{ {
int i, printed = 0; int i, printed = 0;
#include "trace/beauty/generated/pkey_alloc_access_rights_array.c" if (flags == 0) {
static DEFINE_STRARRAY(pkey_alloc_access_rights); const char *s = sa->entries[0];
if (access_rights == 0) {
const char *s = strarray__pkey_alloc_access_rights.entries[0];
if (s) if (s)
return scnprintf(bf, size, "%s", s); return scnprintf(bf, size, "%s", s);
return scnprintf(bf, size, "%d", 0); return scnprintf(bf, size, "%d", 0);
} }
for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) { for (i = 1; i < sa->nr_entries; ++i) {
int bit = 1 << (i - 1); unsigned long bit = 1UL << (i - 1);
if (!(access_rights & bit)) if (!(flags & bit))
continue; continue;
if (printed != 0) if (printed != 0)
printed += scnprintf(bf + printed, size - printed, "|"); printed += scnprintf(bf + printed, size - printed, "|");
if (strarray__pkey_alloc_access_rights.entries[i] != NULL) if (sa->entries[i] != NULL)
printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]); printed += scnprintf(bf + printed, size - printed, "%s", sa->entries[i]);
else else
printed += scnprintf(bf + printed, size - printed, "0x%#", bit); printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
} }
...@@ -41,6 +38,14 @@ static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, s ...@@ -41,6 +38,14 @@ static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, s
return printed; return printed;
} }
static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
{
#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
static DEFINE_STRARRAY(pkey_alloc_access_rights);
return strarray__scnprintf_flags(&strarray__pkey_alloc_access_rights, bf, size, access_rights);
}
size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg) size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
{ {
unsigned long cmd = arg->val; unsigned long cmd = arg->val;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment