]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
libbeauty: Add a strarray__scnprintf_suffix() method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 15 Oct 2019 19:01:42 +0000 (16:01 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 15 Oct 2019 19:01:42 +0000 (16:01 -0300)
In some cases, like with x86 IRQ vectors, the common part in names is at
the end, so a suffix, add a scnprintf function for that.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-agxbj6es2ke3rehwt4gkdw23@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c
tools/perf/trace/beauty/beauty.h

index 907eaf316f5ba4bbfe2e8f9b0921c5f51b7c440e..58bbe85d41667aa0407d5e7e9f4ba6e48a154aea 100644 (file)
@@ -423,6 +423,20 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void *
        ({ struct syscall_tp *fields = evsel->priv; \
           fields->name.pointer(&fields->name, sample); })
 
+size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val)
+{
+       int idx = val - sa->offset;
+
+       if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) {
+               size_t printed = scnprintf(bf, size, intfmt, val);
+               if (show_suffix)
+                       printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix);
+               return printed;
+       }
+
+       return scnprintf(bf, size, "%s%s", sa->entries[idx], show_suffix ? sa->prefix : "");
+}
+
 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val)
 {
        int idx = val - sa->offset;
index 0dee0cf4fda8a68e80d7bef7e63eaf6a04c2c3e9..165f56b456be78de486fa20b0e377eea475390a4 100644 (file)
@@ -28,6 +28,7 @@ struct strarray {
 }
 
 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
+size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val);
 size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags);
 
 bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret);