tools/perf/util/session.c
Source file repositories/reference/linux-study-clean/tools/perf/util/session.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/session.c- Extension
.c- Size
- 84022 bytes
- Lines
- 3058
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hsignal.hinttypes.hlinux/err.hlinux/kernel.hlinux/zalloc.hapi/fs/fs.hbyteswap.hunistd.hsys/types.hsys/mman.hperf/cpumap.hperf/event.hmap_symbol.hbranch.hdebug.hdwarf-regs.henv.hevlist.hevsel.hmemswap.hmap.hsymbol.hsession.htool.hperf_regs.hasm/bug.hauxtrace.hthread.hthread-stack.hsample-raw.hstat.h
Detected Declarations
struct deferred_eventstruct readerstruct readerstruct perf_session__e_machine_cb_argsfunction perf_session__openfunction perf_session__set_id_hdr_sizefunction perf_session__create_kernel_mapsfunction perf_session__destroy_kernel_mapsfunction perf_session__has_comm_execfunction evlist__for_each_entryfunction perf_session__set_comm_execfunction ordered_events__deliver_eventfunction perf_decomp__release_eventsfunction perf_session__deletefunction swap_sample_id_allfunction perf_event__all64_swapfunction perf_event__comm_swapfunction perf_event__mmap_swapfunction perf_event__mmap2_swapfunction perf_event__task_swapfunction perf_event__read_swapfunction perf_event__aux_swapfunction perf_event__itrace_start_swapfunction perf_event__switch_swapfunction perf_event__text_poke_swapfunction perf_event__throttle_swapfunction perf_event__namespaces_swapfunction perf_event__cgroup_swapfunction revbytefunction swap_bitfieldfunction perf_event__attr_swapfunction perf_event__hdr_attr_swapfunction perf_event__event_update_swapfunction perf_event__event_type_swapfunction perf_event__tracing_data_swapfunction perf_event__auxtrace_info_swapfunction perf_event__auxtrace_swapfunction perf_event__auxtrace_error_swapfunction perf_event__thread_map_swapfunction perf_event__cpu_map_swapfunction perf_event__stat_config_swapfunction perf_event__stat_swapfunction perf_event__stat_round_swapfunction perf_event__time_conv_swapfunction perf_event__schedstat_cpu_swapfunction perf_event__process_finished_roundfunction perf_session__queue_eventfunction callchain__lbr_callstack_printf
Annotated Snippet
event->context_switch.next_prev_pid =
bswap_32(event->context_switch.next_prev_pid);
event->context_switch.next_prev_tid =
bswap_32(event->context_switch.next_prev_tid);
}
if (sample_id_all)
swap_sample_id_all(event, &event->context_switch + 1);
}
static void perf_event__text_poke_swap(union perf_event *event, bool sample_id_all)
{
event->text_poke.addr = bswap_64(event->text_poke.addr);
event->text_poke.old_len = bswap_16(event->text_poke.old_len);
event->text_poke.new_len = bswap_16(event->text_poke.new_len);
if (sample_id_all) {
size_t len = sizeof(event->text_poke.old_len) +
sizeof(event->text_poke.new_len) +
event->text_poke.old_len +
event->text_poke.new_len;
void *data = &event->text_poke.old_len;
data += PERF_ALIGN(len, sizeof(u64));
swap_sample_id_all(event, data);
}
}
static void perf_event__throttle_swap(union perf_event *event,
bool sample_id_all)
{
event->throttle.time = bswap_64(event->throttle.time);
event->throttle.id = bswap_64(event->throttle.id);
event->throttle.stream_id = bswap_64(event->throttle.stream_id);
if (sample_id_all)
swap_sample_id_all(event, &event->throttle + 1);
}
static void perf_event__namespaces_swap(union perf_event *event,
bool sample_id_all)
{
u64 i;
event->namespaces.pid = bswap_32(event->namespaces.pid);
event->namespaces.tid = bswap_32(event->namespaces.tid);
event->namespaces.nr_namespaces = bswap_64(event->namespaces.nr_namespaces);
for (i = 0; i < event->namespaces.nr_namespaces; i++) {
struct perf_ns_link_info *ns = &event->namespaces.link_info[i];
ns->dev = bswap_64(ns->dev);
ns->ino = bswap_64(ns->ino);
}
if (sample_id_all)
swap_sample_id_all(event, &event->namespaces.link_info[i]);
}
static void perf_event__cgroup_swap(union perf_event *event, bool sample_id_all)
{
event->cgroup.id = bswap_64(event->cgroup.id);
if (sample_id_all) {
void *data = &event->cgroup.path;
data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
swap_sample_id_all(event, data);
}
}
static u8 revbyte(u8 b)
{
int rev = (b >> 4) | ((b & 0xf) << 4);
rev = ((rev & 0xcc) >> 2) | ((rev & 0x33) << 2);
rev = ((rev & 0xaa) >> 1) | ((rev & 0x55) << 1);
return (u8) rev;
}
/*
* XXX this is hack in attempt to carry flags bitfield
* through endian village. ABI says:
*
* Bit-fields are allocated from right to left (least to most significant)
* on little-endian implementations and from left to right (most to least
* significant) on big-endian implementations.
*
* The above seems to be byte specific, so we need to reverse each
* byte of the bitfield. 'Internet' also says this might be implementation
* specific and we probably need proper fix and carry perf_event_attr
Annotation
- Immediate include surface: `errno.h`, `signal.h`, `inttypes.h`, `linux/err.h`, `linux/kernel.h`, `linux/zalloc.h`, `api/fs/fs.h`, `byteswap.h`.
- Detected declarations: `struct deferred_event`, `struct reader`, `struct reader`, `struct perf_session__e_machine_cb_args`, `function perf_session__open`, `function perf_session__set_id_hdr_size`, `function perf_session__create_kernel_maps`, `function perf_session__destroy_kernel_maps`, `function perf_session__has_comm_exec`, `function evlist__for_each_entry`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.