mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-12 05:48:39 +08:00
98dcf14d7f
Add kernel AUX area sampling definitions, which brings perf_event.h into line with the kernel version. New sample type PERF_SAMPLE_AUX requests a sample of the AUX area buffer. New perf_event_attr member 'aux_sample_size' specifies the desired size of the sample. Also add support for parsing samples containing AUX area data i.e. PERF_SAMPLE_AUX. Committer notes: I squashed the first two patches in this series to avoid breaking automatic bisection, i.e. after applying only the original first patch in this series we would have: # perf test -v parsing 26: Sample parsing : --- start --- test child forked, pid 17018 sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating test child finished with -1 ---- end ---- Sample parsing: FAILED! # With the two paches combined: # perf test parsing 26: Sample parsing : Ok # Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lore.kernel.org/lkml/20191115124225.5247-3-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
150 lines
4.7 KiB
C
150 lines
4.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <linux/perf_event.h>
|
|
#include "util/evsel_fprintf.h"
|
|
|
|
struct bit_names {
|
|
int bit;
|
|
const char *name;
|
|
};
|
|
|
|
static void __p_bits(char *buf, size_t size, u64 value, struct bit_names *bits)
|
|
{
|
|
bool first_bit = true;
|
|
int i = 0;
|
|
|
|
do {
|
|
if (value & bits[i].bit) {
|
|
buf += scnprintf(buf, size, "%s%s", first_bit ? "" : "|", bits[i].name);
|
|
first_bit = false;
|
|
}
|
|
} while (bits[++i].name != NULL);
|
|
}
|
|
|
|
static void __p_sample_type(char *buf, size_t size, u64 value)
|
|
{
|
|
#define bit_name(n) { PERF_SAMPLE_##n, #n }
|
|
struct bit_names bits[] = {
|
|
bit_name(IP), bit_name(TID), bit_name(TIME), bit_name(ADDR),
|
|
bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU),
|
|
bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW),
|
|
bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),
|
|
bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC),
|
|
bit_name(WEIGHT), bit_name(PHYS_ADDR), bit_name(AUX),
|
|
{ .name = NULL, }
|
|
};
|
|
#undef bit_name
|
|
__p_bits(buf, size, value, bits);
|
|
}
|
|
|
|
static void __p_branch_sample_type(char *buf, size_t size, u64 value)
|
|
{
|
|
#define bit_name(n) { PERF_SAMPLE_BRANCH_##n, #n }
|
|
struct bit_names bits[] = {
|
|
bit_name(USER), bit_name(KERNEL), bit_name(HV), bit_name(ANY),
|
|
bit_name(ANY_CALL), bit_name(ANY_RETURN), bit_name(IND_CALL),
|
|
bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
|
|
bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
|
|
bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
|
|
{ .name = NULL, }
|
|
};
|
|
#undef bit_name
|
|
__p_bits(buf, size, value, bits);
|
|
}
|
|
|
|
static void __p_read_format(char *buf, size_t size, u64 value)
|
|
{
|
|
#define bit_name(n) { PERF_FORMAT_##n, #n }
|
|
struct bit_names bits[] = {
|
|
bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING),
|
|
bit_name(ID), bit_name(GROUP),
|
|
{ .name = NULL, }
|
|
};
|
|
#undef bit_name
|
|
__p_bits(buf, size, value, bits);
|
|
}
|
|
|
|
#define BUF_SIZE 1024
|
|
|
|
#define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val))
|
|
#define p_unsigned(val) snprintf(buf, BUF_SIZE, "%"PRIu64, (uint64_t)(val))
|
|
#define p_signed(val) snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)(val))
|
|
#define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)
|
|
#define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val)
|
|
#define p_read_format(val) __p_read_format(buf, BUF_SIZE, val)
|
|
|
|
#define PRINT_ATTRn(_n, _f, _p) \
|
|
do { \
|
|
if (attr->_f) { \
|
|
_p(attr->_f); \
|
|
ret += attr__fprintf(fp, _n, buf, priv);\
|
|
} \
|
|
} while (0)
|
|
|
|
#define PRINT_ATTRf(_f, _p) PRINT_ATTRn(#_f, _f, _p)
|
|
|
|
int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
|
|
attr__fprintf_f attr__fprintf, void *priv)
|
|
{
|
|
char buf[BUF_SIZE];
|
|
int ret = 0;
|
|
|
|
PRINT_ATTRf(type, p_unsigned);
|
|
PRINT_ATTRf(size, p_unsigned);
|
|
PRINT_ATTRf(config, p_hex);
|
|
PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned);
|
|
PRINT_ATTRf(sample_type, p_sample_type);
|
|
PRINT_ATTRf(read_format, p_read_format);
|
|
|
|
PRINT_ATTRf(disabled, p_unsigned);
|
|
PRINT_ATTRf(inherit, p_unsigned);
|
|
PRINT_ATTRf(pinned, p_unsigned);
|
|
PRINT_ATTRf(exclusive, p_unsigned);
|
|
PRINT_ATTRf(exclude_user, p_unsigned);
|
|
PRINT_ATTRf(exclude_kernel, p_unsigned);
|
|
PRINT_ATTRf(exclude_hv, p_unsigned);
|
|
PRINT_ATTRf(exclude_idle, p_unsigned);
|
|
PRINT_ATTRf(mmap, p_unsigned);
|
|
PRINT_ATTRf(comm, p_unsigned);
|
|
PRINT_ATTRf(freq, p_unsigned);
|
|
PRINT_ATTRf(inherit_stat, p_unsigned);
|
|
PRINT_ATTRf(enable_on_exec, p_unsigned);
|
|
PRINT_ATTRf(task, p_unsigned);
|
|
PRINT_ATTRf(watermark, p_unsigned);
|
|
PRINT_ATTRf(precise_ip, p_unsigned);
|
|
PRINT_ATTRf(mmap_data, p_unsigned);
|
|
PRINT_ATTRf(sample_id_all, p_unsigned);
|
|
PRINT_ATTRf(exclude_host, p_unsigned);
|
|
PRINT_ATTRf(exclude_guest, p_unsigned);
|
|
PRINT_ATTRf(exclude_callchain_kernel, p_unsigned);
|
|
PRINT_ATTRf(exclude_callchain_user, p_unsigned);
|
|
PRINT_ATTRf(mmap2, p_unsigned);
|
|
PRINT_ATTRf(comm_exec, p_unsigned);
|
|
PRINT_ATTRf(use_clockid, p_unsigned);
|
|
PRINT_ATTRf(context_switch, p_unsigned);
|
|
PRINT_ATTRf(write_backward, p_unsigned);
|
|
PRINT_ATTRf(namespaces, p_unsigned);
|
|
PRINT_ATTRf(ksymbol, p_unsigned);
|
|
PRINT_ATTRf(bpf_event, p_unsigned);
|
|
PRINT_ATTRf(aux_output, p_unsigned);
|
|
|
|
PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
|
|
PRINT_ATTRf(bp_type, p_unsigned);
|
|
PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex);
|
|
PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex);
|
|
PRINT_ATTRf(branch_sample_type, p_branch_sample_type);
|
|
PRINT_ATTRf(sample_regs_user, p_hex);
|
|
PRINT_ATTRf(sample_stack_user, p_unsigned);
|
|
PRINT_ATTRf(clockid, p_signed);
|
|
PRINT_ATTRf(sample_regs_intr, p_hex);
|
|
PRINT_ATTRf(aux_watermark, p_unsigned);
|
|
PRINT_ATTRf(sample_max_stack, p_unsigned);
|
|
PRINT_ATTRf(aux_sample_size, p_unsigned);
|
|
|
|
return ret;
|
|
}
|