tools/perf/bench/uprobe.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/uprobe.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/uprobe.c- Extension
.c- Size
- 5454 bytes
- Lines
- 214
- 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
../perf.h../util/util.hsubcmd/parse-options.h../builtin.hbench.hlinux/compiler.hlinux/time64.hinttypes.hstdio.hsys/time.hsys/types.htime.hunistd.hstdlib.hbpf_skel/bench_uprobe.skel.h
Detected Declarations
enum bench_uprobefunction bench_uprobe__setup_bpf_skelfunction bench_uprobe__teardown_bpf_skelfunction bench_uprobe__setup_bpf_skelfunction bench_uprobe__teardown_bpf_skelfunction bench_uprobe_format__default_fprintffunction bench_uprobefunction bench_uprobe_baselinefunction bench_uprobe_emptyfunction bench_uprobe_trace_printkfunction bench_uprobe_empty_retfunction bench_uprobe_trace_printk_ret
Annotated Snippet
static int bench_uprobe__setup_bpf_skel(enum bench_uprobe bench __maybe_unused) { return 0; }
static void bench_uprobe__teardown_bpf_skel(void) {};
#endif
static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp)
{
static u64 baseline, previous;
s64 diff_to_baseline = diff - baseline,
diff_to_previous = diff - previous;
int printed = fprintf(fp, "# Executed %'d %s calls\n", loops, name);
printed += fprintf(fp, " %14s: %'" PRIu64 " %ss", "Total time", diff, unit);
if (baseline) {
printed += fprintf(fp, " %s%'" PRId64 " to baseline", diff_to_baseline > 0 ? "+" : "", diff_to_baseline);
if (previous != baseline)
fprintf(stdout, " %s%'" PRId64 " to previous", diff_to_previous > 0 ? "+" : "", diff_to_previous);
}
printed += fprintf(fp, "\n\n %'.3f %ss/op", (double)diff / (double)loops, unit);
if (baseline) {
printed += fprintf(fp, " %'.3f %ss/op to baseline", (double)diff_to_baseline / (double)loops, unit);
if (previous != baseline)
printed += fprintf(fp, " %'.3f %ss/op to previous", (double)diff_to_previous / (double)loops, unit);
} else {
baseline = diff;
}
fputc('\n', fp);
previous = diff;
return printed + 1;
}
static int bench_uprobe(int argc, const char **argv, enum bench_uprobe bench)
{
const char *name = "usleep(1000)", *unit = "usec";
struct timespec start, end;
u64 diff;
int i;
argc = parse_options(argc, argv, options, bench_uprobe_usage, 0);
if (bench != BENCH_UPROBE__BASELINE && bench_uprobe__setup_bpf_skel(bench) < 0)
return 0;
clock_gettime(CLOCK_REALTIME, &start);
for (i = 0; i < loops; i++) {
usleep(USEC_PER_MSEC);
}
clock_gettime(CLOCK_REALTIME, &end);
diff = end.tv_sec * NSEC_PER_SEC + end.tv_nsec - (start.tv_sec * NSEC_PER_SEC + start.tv_nsec);
diff /= NSEC_PER_USEC;
switch (bench_format) {
case BENCH_FORMAT_DEFAULT:
bench_uprobe_format__default_fprintf(name, unit, diff, stdout);
break;
case BENCH_FORMAT_SIMPLE:
printf("%" PRIu64 "\n", diff);
break;
default:
/* reaching here is something of a disaster */
fprintf(stderr, "Unknown format:%d\n", bench_format);
exit(1);
}
if (bench != BENCH_UPROBE__BASELINE)
bench_uprobe__teardown_bpf_skel();
return 0;
}
int bench_uprobe_baseline(int argc, const char **argv)
{
return bench_uprobe(argc, argv, BENCH_UPROBE__BASELINE);
}
int bench_uprobe_empty(int argc, const char **argv)
{
return bench_uprobe(argc, argv, BENCH_UPROBE__EMPTY);
Annotation
- Immediate include surface: `../perf.h`, `../util/util.h`, `subcmd/parse-options.h`, `../builtin.h`, `bench.h`, `linux/compiler.h`, `linux/time64.h`, `inttypes.h`.
- Detected declarations: `enum bench_uprobe`, `function bench_uprobe__setup_bpf_skel`, `function bench_uprobe__teardown_bpf_skel`, `function bench_uprobe__setup_bpf_skel`, `function bench_uprobe__teardown_bpf_skel`, `function bench_uprobe_format__default_fprintf`, `function bench_uprobe`, `function bench_uprobe_baseline`, `function bench_uprobe_empty`, `function bench_uprobe_trace_printk`.
- 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.