tools/testing/selftests/rseq/rseq-slice-hist.py
Source file repositories/reference/linux-study-clean/tools/testing/selftests/rseq/rseq-slice-hist.py
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/rseq/rseq-slice-hist.py- Extension
.py- Size
- 3629 bytes
- Lines
- 133
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
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.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/python3
#
# trace-cmd record -e hrtimer_start -e hrtimer_cancel -e hrtimer_expire_entry -- $cmd
#
from tracecmd import *
def load_kallsyms(file_path='/proc/kallsyms'):
"""
Parses /proc/kallsyms into a dictionary.
Returns: { address_int: symbol_name }
"""
kallsyms_map = {}
try:
with open(file_path, 'r') as f:
for line in f:
# The format is: [address] [type] [name] [module]
parts = line.split()
if len(parts) < 3:
continue
addr = int(parts[0], 16)
name = parts[2]
kallsyms_map[addr] = name
except PermissionError:
print(f"Error: Permission denied reading {file_path}. Try running with sudo.")
except FileNotFoundError:
print(f"Error: {file_path} not found.")
return kallsyms_map
ksyms = load_kallsyms()
# pending[timer_ptr] = {'ts': timestamp, 'comm': comm}
pending = {}
# histograms[comm][bucket] = count
histograms = {}
class OnlineHarmonicMean:
def __init__(self):
self.n = 0 # Count of elements
self.S = 0.0 # Cumulative sum of reciprocals
def update(self, x):
if x == 0:
raise ValueError("Harmonic mean is undefined for zero.")
self.n += 1
self.S += 1.0 / x
return self.n / self.S
@property
def mean(self):
return self.n / self.S if self.n > 0 else 0
ohms = {}
def handle_start(record):
func_name = ksyms[record.num_field("function")]
if "rseq_slice_expired" in func_name:
timer_ptr = record.num_field("hrtimer")
pending[timer_ptr] = {
'ts': record.ts,
'comm': record.comm
}
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
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.