tools/perf/builtin-buildid-cache.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-buildid-cache.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-buildid-cache.c- Extension
.c- Size
- 13478 bytes
- Lines
- 559
- 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
sys/types.hsys/time.htime.hdirent.herrno.hunistd.hbuiltin.hnamespaces.hutil/debug.hutil/header.hsubcmd/pager.hsubcmd/parse-options.hutil/strlist.hutil/build-id.hutil/session.hutil/dso.hutil/symbol.hutil/time-utils.hutil/util.hutil/probe-file.hutil/config.hlinux/string.hlinux/err.h
Detected Declarations
function Copyrightfunction build_id_cache__kcore_dirfunction same_kallsyms_relocfunction build_id_cache__kcore_existingfunction build_id_cache__add_kcorefunction build_id_cache__add_filefunction build_id_cache__remove_filefunction build_id_cache__purge_pathfunction strlist__for_each_entryfunction build_id_cache__purge_allfunction strlist__for_each_entryfunction dso__missing_buildid_cachefunction build_id_cache__fprintf_missingfunction build_id_cache__update_filefunction build_id_cache__show_allfunction perf_buildid_cache_configfunction cmd_buildid_cache
Annotated Snippet
same_kallsyms_reloc(from_dir, to_subdir)) {
strlcpy(to_dir, to_subdir, to_dir_sz);
ret = 0;
break;
}
}
closedir(d);
return ret;
}
static int build_id_cache__add_kcore(const char *filename, bool force)
{
char dir[32], sbuildid[SBUILD_ID_SIZE];
char from_dir[PATH_MAX], to_dir[PATH_MAX];
char *p;
strlcpy(from_dir, filename, sizeof(from_dir));
p = strrchr(from_dir, '/');
if (!p || strcmp(p + 1, "kcore"))
return -1;
*p = '\0';
if (build_id_cache__kcore_buildid(from_dir, sbuildid, sizeof(sbuildid)) < 0)
return -1;
scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s",
buildid_dir, DSO__NAME_KCORE, sbuildid);
if (!force &&
!build_id_cache__kcore_existing(from_dir, to_dir, sizeof(to_dir))) {
pr_debug("same kcore found in %s\n", to_dir);
return 0;
}
if (build_id_cache__kcore_dir(dir, sizeof(dir)))
return -1;
scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s/%s",
buildid_dir, DSO__NAME_KCORE, sbuildid, dir);
if (mkdir_p(to_dir, 0755))
return -1;
if (kcore_copy(from_dir, to_dir)) {
/* Remove YYYYmmddHHMMSShh directory */
if (!rmdir(to_dir)) {
p = strrchr(to_dir, '/');
if (p)
*p = '\0';
/* Try to remove buildid directory */
if (!rmdir(to_dir)) {
p = strrchr(to_dir, '/');
if (p)
*p = '\0';
/* Try to remove [kernel.kcore] directory */
rmdir(to_dir);
}
}
return -1;
}
pr_debug("kcore added to build-id cache directory %s\n", to_dir);
return 0;
}
static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
{
char sbuild_id[SBUILD_ID_SIZE];
struct build_id bid = { .size = 0, };
int err;
struct nscookie nsc;
nsinfo__mountns_enter(nsi, &nsc);
err = filename__read_build_id(filename, &bid);
nsinfo__mountns_exit(&nsc);
if (err < 0) {
pr_debug("Couldn't read a build-id in %s\n", filename);
return -1;
}
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
err = build_id_cache__add_s(sbuild_id, filename, nsi,
false, false);
pr_debug("Adding %s %s: %s\n", sbuild_id, filename,
err ? "FAIL" : "Ok");
return err;
Annotation
- Immediate include surface: `sys/types.h`, `sys/time.h`, `time.h`, `dirent.h`, `errno.h`, `unistd.h`, `builtin.h`, `namespaces.h`.
- Detected declarations: `function Copyright`, `function build_id_cache__kcore_dir`, `function same_kallsyms_reloc`, `function build_id_cache__kcore_existing`, `function build_id_cache__add_kcore`, `function build_id_cache__add_file`, `function build_id_cache__remove_file`, `function build_id_cache__purge_path`, `function strlist__for_each_entry`, `function build_id_cache__purge_all`.
- 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.