Skip to contentSkip to conversation

perf: buildid: Print error for creating folder failure

PATCH New Leo Yan 1 participant 1 message Nov 14, 2024 perf events

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/1 perf: buildid: Print error for creating folder failure

The mkdir_p() function will fail to create a buildid cache folder if the folder name is not an absolute path. As a result, the cache folder is empty after recording.

Print an error to remind users to use an absolute path name or check permissions. Update the documentation to reflect the requirement of using an absolute path name.

After:

  # perf --buildid-dir debug_dir record -- test_program
    ...
    Failed to create build_id cache folder: debug_dir/[kernel.kallsyms]/5c81911cab18f69bab96f8a1fae64a9f1d83b104.
      Use an absolute path name or check permissions.
---
 tools/perf/Documentation/perf-config.txt | 2 ++
 tools/perf/Documentation/perf.txt        | 4 ++--
 tools/perf/util/build-id.c               | 6 +++++-
 3 files changed, 9 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-config.txt +2 -0
index 379f9d7a8ab1..26d9b1dd2e8c 100644
@@ -236,6 +236,8 @@ buildid.*::
 		cache location, or to disable it altogether. If you want to disable it,
 		set buildid.dir to /dev/null. The default is $HOME/.debug
 
+		This option must be an absolute path name.
+
 buildid-cache.*::
 	buildid-cache.debuginfod=URLs
 		Specify debuginfod URLs to be used when retrieving perf.data binaries,
tools/perf/Documentation/perf.txt +2 -2
index cbcc2e4d557e..14c79bd7820a 100644
@@ -37,8 +37,8 @@ OPTIONS
         Do not set pager.
 
 --buildid-dir::
-        Setup buildid cache directory. It has higher priority
-        than buildid.dir config file option.
+        Setup buildid cache directory with an absolute path name.
+        It has higher priority than buildid.dir config file option.
 
 --list-cmds::
         List the most commonly used perf commands.
tools/perf/util/build-id.c +5 -1
index 8982f68e7230..a05d45ac1c87 100644
@@ -637,8 +637,12 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam
 		if (unlink(dir_name))
 			goto out_free;
 
-	if (mkdir_p(dir_name, 0755))
+	if (mkdir_p(dir_name, 0755)) {
+		pr_err("Failed to create build_id cache folder: %s.\n"
+		       "  Use an absolute path name or check permissions.\n",
+		       dir_name);
 		goto out_free;
+	}
 
 	/* Save the allocated buildid dirname */
 	if (asprintf(&filename, "%s/%s", dir_name,
Signature · 1 line
2.25.1