tools/perf/bench/inject-buildid.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/inject-buildid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/inject-buildid.c- Extension
.c- Size
- 11467 bytes
- Lines
- 487
- 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
stdlib.hstddef.hftw.hfcntl.herrno.hunistd.hpthread.hsys/mman.hsys/wait.hlinux/kernel.hlinux/time64.hlinux/list.hlinux/err.hlinux/zalloc.hinternal/lib.hsubcmd/parse-options.hbench.hutil/data.hutil/stat.hutil/debug.hutil/symbol.hutil/session.hutil/build-id.hutil/sample.hutil/synthetic-events.h
Detected Declarations
struct bench_datastruct bench_dsofunction needfunction collect_dsofunction release_dsofunction dso_map_addrfunction synthesize_attrfunction synthesize_forkfunction synthesize_mmapfunction synthesize_samplefunction synthesize_flushfunction setup_injectionfunction inject_build_idfunction do_inject_loopfunction do_inject_loopsfunction bench_inject_build_id
Annotated Snippet
struct bench_data {
int pid;
int input_pipe[2];
int output_pipe[2];
pthread_t th;
};
struct bench_dso {
struct list_head list;
char *name;
int ino;
};
static int nr_dsos;
static struct bench_dso *dsos;
extern int main(int argc, const char **argv);
static const struct option options[] = {
OPT_UINTEGER('i', "iterations", &iterations,
"Number of iterations used to compute average (default: 100)"),
OPT_UINTEGER('m', "nr-mmaps", &nr_mmaps,
"Number of mmap events for each iteration (default: 100)"),
OPT_UINTEGER('n', "nr-samples", &nr_samples,
"Number of sample events per mmap event (default: 100)"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show iteration count, DSO name, etc)"),
OPT_END()
};
static const char *const bench_usage[] = {
"perf bench internals inject-build-id <options>",
NULL
};
/*
* Helper for collect_dso that adds the given file as a dso to dso_list
* if it contains a build-id. Stops after collecting 4 times more than
* we need (for MMAP2 events).
*/
static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
int typeflag, struct FTW *ftwbuf __maybe_unused)
{
struct bench_dso *dso = &dsos[nr_dsos];
struct build_id bid = { .size = 0, };
if (typeflag == FTW_D || typeflag == FTW_SL)
return 0;
if (filename__read_build_id(fpath, &bid) < 0)
return 0;
dso->name = realpath(fpath, NULL);
if (dso->name == NULL)
return -1;
dso->ino = nr_dsos++;
pr_debug2(" Adding DSO: %s\n", fpath);
/* stop if we collected enough DSOs */
if ((unsigned int)nr_dsos == DSO_MMAP_RATIO * nr_mmaps)
return 1;
return 0;
}
static void collect_dso(void)
{
dsos = calloc(nr_mmaps * DSO_MMAP_RATIO, sizeof(*dsos));
if (dsos == NULL) {
printf(" Memory allocation failed\n");
exit(1);
}
if (nftw("/usr/lib/", add_dso, 10, FTW_PHYS) < 0)
return;
pr_debug(" Collected %d DSOs\n", nr_dsos);
}
static void release_dso(void)
{
int i;
for (i = 0; i < nr_dsos; i++) {
struct bench_dso *dso = &dsos[i];
zfree(&dso->name);
}
free(dsos);
Annotation
- Immediate include surface: `stdlib.h`, `stddef.h`, `ftw.h`, `fcntl.h`, `errno.h`, `unistd.h`, `pthread.h`, `sys/mman.h`.
- Detected declarations: `struct bench_data`, `struct bench_dso`, `function need`, `function collect_dso`, `function release_dso`, `function dso_map_addr`, `function synthesize_attr`, `function synthesize_fork`, `function synthesize_mmap`, `function synthesize_sample`.
- 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.