Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf script: Factor out perf_sample__sprintf_flags()

Factor out perf_sample__sprintf_flags() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210525095112.1399-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
54cd8b03 3f8e009e

+21 -10
+18 -10
tools/perf/builtin-script.c
··· 1553 1553 return NULL; 1554 1554 } 1555 1555 1556 - static int perf_sample__fprintf_flags(u32 flags, FILE *fp) 1556 + int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz) 1557 1557 { 1558 1558 const char *chars = PERF_IP_FLAG_CHARS; 1559 - const int n = strlen(PERF_IP_FLAG_CHARS); 1559 + const size_t n = strlen(PERF_IP_FLAG_CHARS); 1560 1560 bool in_tx = flags & PERF_IP_FLAG_IN_TX; 1561 1561 const char *name = NULL; 1562 - char str[33]; 1563 - int i, pos = 0; 1562 + size_t i, pos = 0; 1564 1563 1565 1564 name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX); 1566 1565 if (name) 1567 - return fprintf(fp, " %-15s%4s ", name, in_tx ? "(x)" : ""); 1566 + return snprintf(str, sz, "%-15s%4s", name, in_tx ? "(x)" : ""); 1568 1567 1569 1568 if (flags & PERF_IP_FLAG_TRACE_BEGIN) { 1570 1569 name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN)); 1571 1570 if (name) 1572 - return fprintf(fp, " tr strt %-7s%4s ", name, in_tx ? "(x)" : ""); 1571 + return snprintf(str, sz, "tr strt %-7s%4s", name, in_tx ? "(x)" : ""); 1573 1572 } 1574 1573 1575 1574 if (flags & PERF_IP_FLAG_TRACE_END) { 1576 1575 name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END)); 1577 1576 if (name) 1578 - return fprintf(fp, " tr end %-7s%4s ", name, in_tx ? "(x)" : ""); 1577 + return snprintf(str, sz, "tr end %-7s%4s", name, in_tx ? "(x)" : ""); 1579 1578 } 1580 1579 1581 1580 for (i = 0; i < n; i++, flags >>= 1) { 1582 - if (flags & 1) 1581 + if ((flags & 1) && pos < sz) 1583 1582 str[pos++] = chars[i]; 1584 1583 } 1585 1584 for (; i < 32; i++, flags >>= 1) { 1586 - if (flags & 1) 1585 + if ((flags & 1) && pos < sz) 1587 1586 str[pos++] = '?'; 1588 1587 } 1589 - str[pos] = 0; 1588 + if (pos < sz) 1589 + str[pos] = 0; 1590 1590 1591 + return pos; 1592 + } 1593 + 1594 + static int perf_sample__fprintf_flags(u32 flags, FILE *fp) 1595 + { 1596 + char str[SAMPLE_FLAGS_BUF_SIZE]; 1597 + 1598 + perf_sample__sprintf_flags(flags, str, sizeof(str)); 1591 1599 return fprintf(fp, " %-19s ", str); 1592 1600 } 1593 1601
+3
tools/perf/util/trace-event.h
··· 105 105 int common_flags(struct scripting_context *context); 106 106 int common_lock_depth(struct scripting_context *context); 107 107 108 + #define SAMPLE_FLAGS_BUF_SIZE 64 109 + int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz); 110 + 108 111 #endif /* _PERF_UTIL_TRACE_EVENT_H */