tools/perf/util/evsel.c
Source file repositories/reference/linux-study-clean/tools/perf/util/evsel.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/evsel.c- Extension
.c- Size
- 115682 bytes
- Lines
- 4439
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
byteswap.herrno.hinttypes.hlinux/bitops.hapi/fs/fs.hapi/fs/tracing_path.hlinux/hw_breakpoint.hlinux/perf_event.hlinux/compiler.hlinux/err.hlinux/zalloc.hsys/ioctl.hsys/resource.hsys/syscall.hsys/types.hdirent.hstdlib.hperf/evsel.hasm/bug.hbpf_counter.hcallchain.hcgroup.hcounts.hdwarf-regs.hevent.hevsel.htime-utils.hutil/env.hutil/evsel_config.hutil/evsel_fprintf.hevlist.hperf/cpumap.h
Detected Declarations
function evsel__no_extra_initfunction test_attr__enabledfunction store_eventfunction test_attr__openfunction evsel__no_extra_finifunction evsel__object_configfunction __evsel__sample_sizefunction idfunction positionfunction evsel__calc_id_posfunction __evsel__set_sample_bitfunction __evsel__reset_sample_bitfunction evsel__set_sample_idfunction evsel__is_function_eventfunction evsel__initfunction copy_config_termsfunction list_for_each_entryfunction evsel__copy_config_termsfunction evsel__match_bpf_counter_eventsfunction evsel__add_modifiersfunction arch_evsel__hw_namefunction evsel__hw_namefunction evsel__sw_namefunction __evsel__bp_namefunction evsel__bp_namefunction evsel__is_cache_op_validfunction __evsel__hw_cache_type_op_res_namefunction __evsel__hw_cache_namefunction evsel__hw_cache_namefunction evsel__raw_namefunction evsel__name_isfunction evsel__group_descfunction for_each_group_evselfunction evsel__e_machinefunction __evsel__config_callchainfunction evsel__config_callchainfunction evsel__reset_callgraphfunction evsel__apply_ratio_to_prevfunction evsel__apply_config_termsfunction list_for_each_entryfunction list_for_each_entryfunction evsel__set_config_if_unsetfunction evsel__get_config_valfunction arch_evsel__set_sample_weightfunction arch__post_evsel_configfunction evsel__is_offcpu_eventfunction evsel__configfunction evsel__set_filter
Annotated Snippet
WRITE_ASS(context_switch, "d");
WRITE_ASS(write_backward, "d");
WRITE_ASS(namespaces, "d");
WRITE_ASS(use_clockid, "d");
WRITE_ASS(wakeup_events, PRIu32);
WRITE_ASS(bp_type, PRIu32);
WRITE_ASS(config1, "llu");
WRITE_ASS(config2, "llu");
WRITE_ASS(branch_sample_type, "llu");
WRITE_ASS(sample_regs_user, "llu");
WRITE_ASS(sample_stack_user, PRIu32);
fclose(file);
return 0;
}
#undef __WRITE_ASS
#undef WRITE_ASS
static void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_cpu cpu,
int fd, int group_fd, unsigned long flags)
{
int errno_saved = errno;
if ((fd != -1) && store_event(attr, pid, cpu, fd, group_fd, flags)) {
pr_err("test attr FAILED");
exit(128);
}
errno = errno_saved;
}
static void evsel__no_extra_fini(struct evsel *evsel __maybe_unused)
{
}
static struct {
size_t size;
int (*init)(struct evsel *evsel);
void (*fini)(struct evsel *evsel);
} perf_evsel__object = {
.size = sizeof(struct evsel),
.init = evsel__no_extra_init,
.fini = evsel__no_extra_fini,
};
int evsel__object_config(size_t object_size, int (*init)(struct evsel *evsel),
void (*fini)(struct evsel *evsel))
{
if (object_size == 0)
goto set_methods;
if (perf_evsel__object.size > object_size)
return -EINVAL;
perf_evsel__object.size = object_size;
set_methods:
if (init != NULL)
perf_evsel__object.init = init;
if (fini != NULL)
perf_evsel__object.fini = fini;
return 0;
}
const char *evsel__pmu_name(const struct evsel *evsel)
{
struct perf_pmu *pmu = evsel__find_pmu(evsel);
if (pmu)
return pmu->name;
return event_type(evsel->core.attr.type);
}
#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
int __evsel__sample_size(u64 sample_type)
{
u64 mask = sample_type & PERF_SAMPLE_MASK;
int size = 0;
int i;
for (i = 0; i < 64; i++) {
if (mask & (1ULL << i))
size++;
}
Annotation
- Immediate include surface: `byteswap.h`, `errno.h`, `inttypes.h`, `linux/bitops.h`, `api/fs/fs.h`, `api/fs/tracing_path.h`, `linux/hw_breakpoint.h`, `linux/perf_event.h`.
- Detected declarations: `function evsel__no_extra_init`, `function test_attr__enabled`, `function store_event`, `function test_attr__open`, `function evsel__no_extra_fini`, `function evsel__object_config`, `function __evsel__sample_size`, `function id`, `function position`, `function evsel__calc_id_pos`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.