perf trace: Move strarrays to beauty.h for further reuse

We'll use it in the upcoming arch_prctl() 'code' arg beautifier.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-6e4tj2fjen8qa73gy4u49vav@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2018-12-18 10:25:28 -03:00
parent 40714e8b37
commit 1f2d085e0f
2 changed files with 28 additions and 22 deletions

View file

@ -386,34 +386,28 @@ static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size,
#define SCA_STRARRAY syscall_arg__scnprintf_strarray #define SCA_STRARRAY syscall_arg__scnprintf_strarray
struct strarrays { size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val)
int nr_entries; {
struct strarray **entries; int i;
};
#define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \ for (i = 0; i < sas->nr_entries; ++i) {
.nr_entries = ARRAY_SIZE(array), \ struct strarray *sa = sas->entries[i];
.entries = array, \ int idx = val - sa->offset;
if (idx >= 0 && idx < sa->nr_entries) {
if (sa->entries[idx] == NULL)
break;
return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]);
}
}
return scnprintf(bf, size, intfmt, val);
} }
size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size,
struct syscall_arg *arg) struct syscall_arg *arg)
{ {
struct strarrays *sas = arg->parm; return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix, arg->val);
int i;
for (i = 0; i < sas->nr_entries; ++i) {
struct strarray *sa = sas->entries[i];
int idx = arg->val - sa->offset;
if (idx >= 0 && idx < sa->nr_entries) {
if (sa->entries[idx] == NULL)
break;
return scnprintf(bf, size, "%s%s", arg->show_string_prefix ? sa->prefix : "", sa->entries[idx]);
}
}
return scnprintf(bf, size, "%d", arg->val);
} }
#ifndef AT_FDCWD #ifndef AT_FDCWD

View file

@ -32,6 +32,18 @@ size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, boo
struct trace; struct trace;
struct thread; struct thread;
struct strarrays {
int nr_entries;
struct strarray **entries;
};
#define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \
.nr_entries = ARRAY_SIZE(array), \
.entries = array, \
}
size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size); size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
extern struct strarray strarray__socket_families; extern struct strarray strarray__socket_families;