perf buildid-cache: option -p does not delete anything
PATCH 1/1 perf buildid-cache: option -p does not delete anything
Command perf buildid-cache -p <path> should delete all entries in the buildid cache which start with path. However this does not happen.
When perf buildid-cache -p /usr/bin is invoked, tracing shows in detail functionbuild_id_cache__purge_path() is called and build_id_cache__list_build_ids() creates a list of file names
located in directory /usr/bin of the buildid-cache.build_id_cache__remove_s() is called for each name in the list
and tries to locate each file name
in directory .buildid/YY/ZZZ..ZZZ which fails becausebuild_id_cache__linkname() expects a buildid and gets a file name. The file name bash is treated as .buildid/ba/sh which does not exist.
Fix this by walking along the specified path and test for the object type. If it is a directory, scan this subdirectory. If this is a file, convert the file name to a buildid and call function build_id_cache__remove_file().
--- tools/perf/builtin-buildid-cache.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
tools/perf/builtin-buildid-cache.c +14 -2
@@ -8,6 +8,7 @@*/ #include <sys/types.h> #include <sys/time.h> +#include <sys/stat.h> #include <time.h> #include <dirent.h> #include <errno.h>
@@ -197,6 +198,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)int err; +//printf("%s filename:%s\n", __func__, filename); nsinfo__mountns_enter (nsi, &nsc); err =filename__read_build_id (filename, &build_id,sizeof (build_id));nsinfo__mountns_exit (&nsc);
@@ -224,8 +226,18 @@ static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) goto out;strlist__for_each_entry (pos, list) { - err =build_id_cache__remove_s (pos->s); -pr_debug ("Removing %s %s: %s\n" , pos->s, pathname, +char filename[PATH_MAX ]; +struct stat st; + +scnprintf (filename,sizeof (filename),"%s/%s" , + pathname, pos->s); +if (stat (filename, &st)) +continue ; +if (S_ISDIR (st.st_mode)) + err =build_id_cache__purge_path (filename, nsi); +else + err =build_id_cache__remove_file (filename, nsi); +pr_debug ("Removing %s %s: %s\n" , filename, pathname, err ?"FAIL" :"Ok" );if (err)break ;
Signature · 1 line
2.9.4