Skip to contentSkip to conversation

libbeauty: Add a strarray__scnprintf_suffix() method

tip: perf/core tip-bot2 for Arnaldo Carvalho de Melo 1 participant 1 message Oct 22, 2019 1 message not in the archive perf events

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

tip-bot2 for Arnaldo Carvalho de Melo

author merge bot Applied
#1 lore raw

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     97c2a7806f691f4124914623baa54223416a8cef
Gitweb:        https://git.kernel.org/tip/97c2a7806f691f4124914623baa54223416a8cef
Author:        Arnaldo Carvalho de Melo <[email protected]>
AuthorDate:    Tue, 15 Oct 2019 16:01:42 -03:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 15 Oct 2019 16:01:42 -03:00

libbeauty: Add a strarray__scnprintf_suffix() method

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.

---
 tools/perf/builtin-trace.c       | 14 ++++++++++++++
 tools/perf/trace/beauty/beauty.h |  1 +
 2 files changed, 15 insertions(+)
tools/perf/builtin-trace.c +14 -0
index 907eaf3..58bbe85 100644
@@ -423,6 +423,20 @@ out_delete:
 	({ 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;
tools/perf/trace/beauty/beauty.h +1 -0
index 0dee0cf..165f56b 100644
@@ -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);