perf buildid-cache: Add clean command
Jiri Olsa
reviewercover perf buildid-cache: Add clean command
hi,
adding 'perf buildid-cache clean' command to allow removal files from '~/.debug` cache plus other fixes.
Basically the clean command allows to display/remove cache files/sizes like:
Display cache files older than 3 days:
$ perf buildid-cache clean 3d
Remove cache files older than 3 days:
$ perf buildid-cache clean 3d -r
Total cache removal:
$ perf buildid-cache clean -r
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200M
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_buildid_cache_clean
thanks,
jirka
---
Jiri Olsa (8):
perf tools: Use single strcmp call instead of two perf tools: Remove extra debugdir variables
perf tools: Add --buildid-dir option to set cache directory perf buildid-cache: Add clean command
perf buildid-cache: Add automated tests
perf buildid cache: Fix -a segfault
perf buildid-cache: Fix kallsyms removal
perf buildid-cache: Try to remove empty directories
tools/perf/Documentation/perf-buildid-cache.txt | 59 +++++++++++ tools/perf/Documentation/perf.txt | 4 + tools/perf/Makefile.perf | 7 +- tools/perf/builtin-buildid-cache.c | 501 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- tools/perf/perf.c | 14 ++- tools/perf/tests/buildid-cache.c | 88 ++++++++++++++++ tools/perf/tests/buildid-cache.sh | 60 +++++++++++ tools/perf/tests/builtin-test.c | 8 ++ tools/perf/tests/tests.h | 1 + tools/perf/util/build-id.c | 53 ++++++++-- tools/perf/util/config.c | 10 +- tools/perf/util/util.h | 2 +- 12 files changed, 781 insertions(+), 26 deletions(-) create mode 100644 tools/perf/tests/buildid-cache.c create mode 100755 tools/perf/tests/buildid-cache.sh
Jiri Olsa
reviewerPATCH 1/8 perf tools: Use single strcmp call instead of two
There's no need to use 2 strcmp calls, one is enough.
--- tools/perf/util/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/config.c +1 -1
@@ -522,7 +522,7 @@ static int buildid_dir_command_config(const char *var, const char *value,const char *v;/* same dir for all commands */ -if (!prefixcmp (var,"buildid." ) && !strcmp (var +8 ,"dir" )) { +if (!strcmp (var,"buildid.dir" )) { v =perf_config_dirname (var, value);if (!v)return -1 ;
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf tools: Use single strcmp call instead of two
perf tools: Use single strcmp call instead of two
Commit-ID: cfd31d85bb42b96449157bd57c638dc779070753 Gitweb: http://git.kernel.org/tip/cfd31d85bb42b96449157bd57c638dc779070753 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 1 Dec 2014 20:06:22 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 9 Dec 2014 09:14:33 -0300
perf tools: Use single strcmp call instead of two
There's no need to use 2 strcmp calls, one is enough.
--- tools/perf/util/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/config.c +1 -1
@@ -522,7 +522,7 @@ static int buildid_dir_command_config(const char *var, const char *value,const char *v;/* same dir for all commands */ -if (!prefixcmp (var,"buildid." ) && !strcmp (var +8 ,"dir" )) { +if (!strcmp (var,"buildid.dir" )) { v =perf_config_dirname (var, value);if (!v)return -1 ;
Jiri Olsa
reviewerPATCH 2/8 perf tools: Remove extra debugdir variables
In reply to Jiri OlsaThere's no need to copy over the buildid_dir into separate variable with no change.
This is leftover from commit:
45de34bbe3e1 perf buildid: add perfconfig option to specify buildid cache dir
that added global buildid_dir variable that holds cache directory, but did not cleanup the debugdir copies.
--- tools/perf/builtin-buildid-cache.c | 11 ++++------- tools/perf/util/build-id.c | 9 +++------ 2 files changed, 7 insertions(+), 13 deletions(-)
tools/perf/builtin-buildid-cache.c +4 -7
@@ -285,7 +285,6 @@ int cmd_buildid_cache(int argc, const char **argv,struct str_node *pos;int ret =0 ;bool force = false; -char debugdir[PATH_MAX ];char const *add_name_list_str =NULL , *remove_name_list_str =NULL , *missing_filename = NULL,
@@ -335,13 +334,11 @@ int cmd_buildid_cache(int argc, const char **argv,setup_pager (); -snprintf (debugdir,sizeof (debugdir),"%s" , buildid_dir); -if (add_name_list_str) { list =strlist__new (true, add_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__add_file (pos->s, debugdir)) { +if (build_id_cache__add_file (pos->s, buildid_dir)) {if (errno ==EEXIST ) {pr_debug ("%s already in the cache\n" , pos->s);
@@ -359,7 +356,7 @@ int cmd_buildid_cache(int argc, const char **argv, list =strlist__new (true, remove_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__remove_file (pos->s, debugdir)) { +if (build_id_cache__remove_file (pos->s, buildid_dir)) {if (errno ==ENOENT ) {pr_debug ("%s wasn't in the cache\n" , pos->s);
@@ -380,7 +377,7 @@ int cmd_buildid_cache(int argc, const char **argv, list =strlist__new (true, update_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__update_file (pos->s, debugdir)) { +if (build_id_cache__update_file (pos->s, buildid_dir)) {if (errno ==ENOENT ) {pr_debug ("%s wasn't in the cache\n" , pos->s);
@@ -395,7 +392,7 @@ int cmd_buildid_cache(int argc, const char **argv, }if (kcore_filename && -build_id_cache__add_kcore (kcore_filename, debugdir, force)) +build_id_cache__add_kcore (kcore_filename, buildid_dir, force))pr_warning ("Couldn't add %s\n" , kcore_filename); out:
tools/perf/util/build-id.c +3 -6
@@ -410,21 +410,18 @@ int perf_session__cache_build_ids(struct perf_session *session) {struct rb_node *nd;int ret; -char debugdir[PATH_MAX ];if (no_buildid_cache)return 0 ; -snprintf (debugdir,sizeof (debugdir),"%s" , buildid_dir); - -if (mkdir (debugdir,0755 ) !=0 && errno !=EEXIST ) +if (mkdir (buildid_dir,0755 ) !=0 && errno !=EEXIST )return -1 ; - ret =machine__cache_build_ids (&session->machines.host, debugdir); + ret =machine__cache_build_ids (&session->machines.host, buildid_dir);for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); - ret |=machine__cache_build_ids (pos, debugdir); + ret |=machine__cache_build_ids (pos, buildid_dir); }return ret ?-1 :0 ; }
Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf buildid-cache: Remove extra debugdir variables
perf buildid-cache: Remove extra debugdir variables
Commit-ID: 498922adf1173ddeebd155f82646d4a9d518d606 Gitweb: http://git.kernel.org/tip/498922adf1173ddeebd155f82646d4a9d518d606 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 1 Dec 2014 20:06:23 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 9 Dec 2014 09:14:34 -0300
perf buildid-cache: Remove extra debugdir variables
There's no need to copy over the buildid_dir into separate variable with no change.
This is leftover from commit:
45de34bbe3e1 perf buildid: add perfconfig option to specify buildid cache dir
that added global buildid_dir variable that holds cache directory, but did not cleanup the debugdir copies.
--- tools/perf/builtin-buildid-cache.c | 11 ++++------- tools/perf/util/build-id.c | 9 +++------ 2 files changed, 7 insertions(+), 13 deletions(-)
tools/perf/builtin-buildid-cache.c +4 -7
@@ -285,7 +285,6 @@ int cmd_buildid_cache(int argc, const char **argv,struct str_node *pos;int ret =0 ;bool force = false; -char debugdir[PATH_MAX ];char const *add_name_list_str =NULL , *remove_name_list_str =NULL , *missing_filename = NULL,
@@ -335,13 +334,11 @@ int cmd_buildid_cache(int argc, const char **argv,setup_pager (); -snprintf (debugdir,sizeof (debugdir),"%s" , buildid_dir); -if (add_name_list_str) { list =strlist__new (true, add_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__add_file (pos->s, debugdir)) { +if (build_id_cache__add_file (pos->s, buildid_dir)) {if (errno ==EEXIST ) {pr_debug ("%s already in the cache\n" , pos->s);
@@ -359,7 +356,7 @@ int cmd_buildid_cache(int argc, const char **argv, list =strlist__new (true, remove_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__remove_file (pos->s, debugdir)) { +if (build_id_cache__remove_file (pos->s, buildid_dir)) {if (errno ==ENOENT ) {pr_debug ("%s wasn't in the cache\n" , pos->s);
@@ -380,7 +377,7 @@ int cmd_buildid_cache(int argc, const char **argv, list =strlist__new (true, update_name_list_str);if (list) {strlist__for_each (pos, list) -if (build_id_cache__update_file (pos->s, debugdir)) { +if (build_id_cache__update_file (pos->s, buildid_dir)) {if (errno ==ENOENT ) {pr_debug ("%s wasn't in the cache\n" , pos->s);
@@ -395,7 +392,7 @@ int cmd_buildid_cache(int argc, const char **argv, }if (kcore_filename && -build_id_cache__add_kcore (kcore_filename, debugdir, force)) +build_id_cache__add_kcore (kcore_filename, buildid_dir, force))pr_warning ("Couldn't add %s\n" , kcore_filename); out:
tools/perf/util/build-id.c +3 -6
@@ -410,21 +410,18 @@ int perf_session__cache_build_ids(struct perf_session *session) {struct rb_node *nd;int ret; -char debugdir[PATH_MAX ];if (no_buildid_cache)return 0 ; -snprintf (debugdir,sizeof (debugdir),"%s" , buildid_dir); - -if (mkdir (debugdir,0755 ) !=0 && errno !=EEXIST ) +if (mkdir (buildid_dir,0755 ) !=0 && errno !=EEXIST )return -1 ; - ret =machine__cache_build_ids (&session->machines.host, debugdir); + ret =machine__cache_build_ids (&session->machines.host, buildid_dir);for (nd =rb_first (&session->machines.guests); nd; nd =rb_next (nd)) { struct machine *pos = rb_entry(nd, struct machine, rb_node); - ret |=machine__cache_build_ids (pos, debugdir); + ret |=machine__cache_build_ids (pos, buildid_dir); }return ret ?-1 :0 ; }
Jiri Olsa
reviewerPATCH 3/8 perf tools: Add --buildid-dir option to set cache directory
In reply to Jiri OlsaAdding --buildid-dir to be able to set specific cache directory. It's going to be handy for buildid tests coming in shortly.
--- tools/perf/Documentation/perf.txt | 4 ++++ tools/perf/perf.c | 14 ++++++++++++-- tools/perf/util/config.c | 8 +++++--- tools/perf/util/util.h | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf.txt +4 -0
@@ -18,6 +18,10 @@ OPTIONS --debug verbose # sets verbose = 1 --debug verbose=2 # sets verbose = 2 +--buildid-dir:: + Setup buildid cache directory. It has higher priority than + buildid.dir config file option. + DESCRIPTION ----------- Performance counters for Linux are a new kernel-based subsystem
tools/perf/perf.c +12 -2
@@ -200,6 +200,16 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged =1 ; (*argv)++; (*argc)--; + }else if (!strcmp (cmd,"--buildid-dir" )) { +if (*argc <2 ) { +fprintf (stderr,"No directory given for --buildid-dir.\n" ); +usage (perf_usage_string); + } +set_buildid_dir ((*argv)[1 ]); +if (envchanged) + *envchanged =1 ; + (*argv)++; + (*argc)--; }else if (!prefixcmp (cmd,CMD_DEBUGFS_DIR )) {perf_debugfs_set_path (cmd +strlen (CMD_DEBUGFS_DIR ));fprintf (stderr,"dir: %s\n" , debugfs_mountpoint);
@@ -499,7 +509,7 @@ int main(int argc, const char **argv) }if (!prefixcmp (cmd,"trace" )) {#ifdef HAVE_LIBAUDIT_SUPPORT -set_buildid_dir (); +set_buildid_dir (NULL );setup_path (); argv[0 ] ="trace" ;return cmd_trace (argc, argv,NULL );
@@ -514,7 +524,7 @@ int main(int argc, const char **argv) argc--;handle_options (&argv, &argc,NULL );commit_pager_choice (); -set_buildid_dir (); +set_buildid_dir (NULL );if (argc >0 ) {if (!prefixcmp (argv[0 ],"--" ))
tools/perf/util/config.c +5 -3
@@ -539,12 +539,14 @@ static void check_buildid_dir_config(void)perf_config (buildid_dir_command_config, &c); } -void set_buildid_dir (void ) +void set_buildid_dir (const char *dir) { - buildid_dir[0 ] ='\0' ; +if (dir) +scnprintf (buildid_dir,MAXPATHLEN -1 ,"%s" , dir);/* try config file */ -check_buildid_dir_config (); +if (buildid_dir[0 ] =='\0' ) +check_buildid_dir_config ();/* default to $HOME/.debug */ if (buildid_dir[0 ] =='\0' ) {
tools/perf/util/util.h +1 -1
@@ -153,7 +153,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern int prefixcmp (const char *str,const char *prefix); -extern void set_buildid_dir (void ); +extern void set_buildid_dir (const char *dir);static inline const char *skip_prefix (const char *str,const char *prefix) {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
AppliedRe: [PATCH 3/8] perf tools: Add --buildid-dir option to set cache directory
Em Mon, Dec 01, 2014 at 08:06:24PM +0100, Jiri Olsa escreveu:
Quoted 3 lines
Adding --buildid-dir to be able to set specific cache directory. It's going to be handy for buildid tests coming in shortly.
Thanks, applied.
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf tools: Add --buildid-dir option to set cache directory
In reply to Jiri Olsaperf tools: Add --buildid-dir option to set cache directory
Commit-ID: 99ce8e9fce99147f865cda8a8e471900518c9a49 Gitweb: http://git.kernel.org/tip/99ce8e9fce99147f865cda8a8e471900518c9a49 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 1 Dec 2014 20:06:24 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 9 Dec 2014 09:14:35 -0300
perf tools: Add --buildid-dir option to set cache directory
Adding --buildid-dir to be able to set specific cache directory. It's going to be handy for buildid tests coming in shortly.
--- tools/perf/Documentation/perf.txt | 4 ++++ tools/perf/perf.c | 14 ++++++++++++-- tools/perf/util/config.c | 8 +++++--- tools/perf/util/util.h | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf.txt +4 -0
@@ -18,6 +18,10 @@ OPTIONS --debug verbose # sets verbose = 1 --debug verbose=2 # sets verbose = 2 +--buildid-dir:: + Setup buildid cache directory. It has higher priority than + buildid.dir config file option. + DESCRIPTION ----------- Performance counters for Linux are a new kernel-based subsystem
tools/perf/perf.c +12 -2
@@ -200,6 +200,16 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged =1 ; (*argv)++; (*argc)--; + }else if (!strcmp (cmd,"--buildid-dir" )) { +if (*argc <2 ) { +fprintf (stderr,"No directory given for --buildid-dir.\n" ); +usage (perf_usage_string); + } +set_buildid_dir ((*argv)[1 ]); +if (envchanged) + *envchanged =1 ; + (*argv)++; + (*argc)--; }else if (!prefixcmp (cmd,CMD_DEBUGFS_DIR )) {perf_debugfs_set_path (cmd +strlen (CMD_DEBUGFS_DIR ));fprintf (stderr,"dir: %s\n" , debugfs_mountpoint);
@@ -499,7 +509,7 @@ int main(int argc, const char **argv) }if (!prefixcmp (cmd,"trace" )) {#ifdef HAVE_LIBAUDIT_SUPPORT -set_buildid_dir (); +set_buildid_dir (NULL );setup_path (); argv[0 ] ="trace" ;return cmd_trace (argc, argv,NULL );
@@ -514,7 +524,7 @@ int main(int argc, const char **argv) argc--;handle_options (&argv, &argc,NULL );commit_pager_choice (); -set_buildid_dir (); +set_buildid_dir (NULL );if (argc >0 ) {if (!prefixcmp (argv[0 ],"--" ))
tools/perf/util/config.c +5 -3
@@ -539,12 +539,14 @@ static void check_buildid_dir_config(void)perf_config (buildid_dir_command_config, &c); } -void set_buildid_dir (void ) +void set_buildid_dir (const char *dir) { - buildid_dir[0 ] ='\0' ; +if (dir) +scnprintf (buildid_dir,MAXPATHLEN -1 ,"%s" , dir);/* try config file */ -check_buildid_dir_config (); +if (buildid_dir[0 ] =='\0' ) +check_buildid_dir_config ();/* default to $HOME/.debug */ if (buildid_dir[0 ] =='\0' ) {
tools/perf/util/util.h +1 -1
@@ -153,7 +153,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))extern void set_die_routine (void (*routine)(const char *err,va_list params)NORETURN );extern int prefixcmp (const char *str,const char *prefix); -extern void set_buildid_dir (void ); +extern void set_buildid_dir (const char *dir);static inline const char *skip_prefix (const char *str,const char *prefix) {
Jiri Olsa
reviewerPATCH 4/8 perf buildid-cache: Add clean command
In reply to Jiri OlsaThe 'perf buildid-cache clean' command provides means to clean the cache directory. Unless the '-r' option is specified it displays the contents (with size) of the cache. You can also specify time or size limit as a cache filer (see CLEAN LIMIT section).
User can specify size or time limit as a filter to display cache files. The syntax of the limit is, time:
$ perf buildid-cache clean 1d # displays files older than 1 day $ perf buildid-cache clean 4w # displays files older than 4 weeks $ perf buildid-cache clean 2m # displays files older than 2 months $ perf buildid-cache clean 1y # displays files older than 1 year
or size:
$ perf buildid-cache clean 100B # displays files with size >= 100 B $ perf buildid-cache clean 4K # displays files with size >= 4 KB $ perf buildid-cache clean 2M # displays files with size >= 2 MB $ perf buildid-cache clean 1G # displays files with size >= 1 GB
Few examples:
Display cache files older than 3 days and sort them by time:
$ perf buildid-cache clean --time 3d
Total cache removal:
$ perf buildid-cache clean -r
Remove items older than 2 weeks
$ perf buildid-cache clean -r 2w
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200M
--- tools/perf/Documentation/perf-buildid-cache.txt | 59 +++ tools/perf/builtin-buildid-cache.c | 454 +++++++++++++++++++++++- 2 files changed, 512 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +59 -0
@@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] 'perf buildid-cache <options>' +'perf buildid-cache <options> clean [<options>] [limit] DESCRIPTION -----------
@@ -16,6 +17,11 @@ This command manages the build-id cache. It can add and remove files to/from the cache. In the future it should as well purge older entries, set upper limits for the space used by the cache, etc. +The 'perf buildid-cache clean' command provides means to clean the cache +directory. Unless the '-r' option is specified it displays the contents +(with size) of the cache. You can also specify time or size limit as +a cache filer (see CLEAN LIMIT section). + OPTIONS ------- -a::
@@ -48,6 +54,59 @@ OPTIONS --verbose:: Be more verbose. + +CLEAN OPTIONS +------------- +-a:: +--all:: + Display each cache file separately. + +-r:: +--remove:: + Remove all files displayed. + +--size:: + Sort files by size (default). + +--time:: + Sort files by time. + +-v:: +--verbose:: + Be more verbose. + + +CLEAN LIMIT +----------- +User can specify size or time limit as a filter to display cache files. +The syntax of the limit is, time: + $ perf buildid-cache clean 1d # displays files older than 1 day + $ perf buildid-cache clean 4w # displays files older than 4 weeks + $ perf buildid-cache clean 2m # displays files older than 2 months + $ perf buildid-cache clean 1y # displays files older than 1 year + +or size: + $ perf buildid-cache clean 100B # displays files with size >= 100 B + $ perf buildid-cache clean 4K # displays files with size >= 4 KB + $ perf buildid-cache clean 2M # displays files with size >= 2 MB + $ perf buildid-cache clean 1G # displays files with size >= 1 GB + + +EXAMPLES +-------- +Display cache files older than 3 days and sort them by time: +$ perf buildid-cache clean --time 3d + +Total cache removal: +$ perf buildid-cache clean -r + +Remove items older than 2 weeks +$ perf buildid-cache clean -r 2w + +Remove and display items bigger than 200M +$ perf buildid-cache clean -r -a 200M + + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-buildid-list[1]
tools/perf/builtin-buildid-cache.c +453 -1
480 lines not on this page · raw message
Signature · 1 line
1.9.3
Jiri Olsa
reviewerPATCH 5/8 perf buildid-cache: Add automated tests
In reply to Jiri OlsaAdding automated test for buildid-cache command/processing.
--- tools/perf/Makefile.perf | 7 +++- tools/perf/tests/buildid-cache.c | 88 +++++++++++++++++++++++++++++++++++++++ tools/perf/tests/buildid-cache.sh | 60 ++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 8 ++++ tools/perf/tests/tests.h | 1 + 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/buildid-cache.c create mode 100755 tools/perf/tests/buildid-cache.sh
tools/perf/Makefile.perf +6 -1
@@ -447,6 +447,7 @@ endif LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o LIB_OBJS += $(OUTPUT)tests/switch-tracking.o +LIB_OBJS += $(OUTPUT)tests/buildid-cache.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
@@ -699,6 +700,9 @@ $(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \ $< +$(OUTPUT)tests/buildid-cache.o: tests/buildid-cache.c $(OUTPUT)PERF-CFLAGS + $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) '-DBINDIR="$(bindir_SQ)"' $< + $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \ -DPYTHONPATH='"$(OUTPUT)python"' \
@@ -944,7 +948,8 @@ endif $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ - $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' + $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ + $(INSTALL) tests/buildid-cache.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests' install: install-bin try-install-man install-traceevent-plugins
tools/perf/tests/buildid-cache.c new file +88 -0
88 lines not on this page · raw message
tools/perf/tests/buildid-cache.sh new file +60 -0
60 lines not on this page · raw message
tools/perf/tests/builtin-test.c +8 -0
@@ -167,6 +167,14 @@ static struct test { .func = test__fdarray__add, }, { + .desc = "Add fd to a fdarray, making it autogrow", + .func = test__fdarray__add, + }, + { + .desc = "Test buildid cache", + .func = test__buildid_cache, + }, + { .func = NULL, }, };
tools/perf/tests/tests.h +1 -0
@@ -51,6 +51,7 @@ int test__hists_cumulate(void);int test__switch_tracking (void );int test__fdarray__filter (void );int test__fdarray__add (void ); +int test__buildid_cache (void );#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.9.3
Re: [PATCH 5/8] perf buildid-cache: Add automated tests
Em Mon, Dec 01, 2014 at 08:06:26PM +0100, Jiri Olsa escreveu:
Quoted 1 line
Adding automated test for buildid-cache command/processing.
Does it only work if one is in the tools/perf/ directory? Why not remove that './' from './perf' and ditch that fallback mechanism (BINDIR).
If all you want to make sure is that the binary used is the one just built and not the system one, then you can make sure that in your PATH the directory with the development one is comes first, right?
I.e. no need for that fallbacking mechanism, etc.
- Arnaldo
Quoted 246 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/Makefile.perf | 7 +++- tools/perf/tests/buildid-cache.c | 88 +++++++++++++++++++++++++++++++++++++++ tools/perf/tests/buildid-cache.sh | 60 ++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 8 ++++ tools/perf/tests/tests.h | 1 + 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/buildid-cache.c create mode 100755 tools/perf/tests/buildid-cache.shtools/perf/Makefile.perf +6
-1@@ -447,6 +447,7 @@ endif LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o LIB_OBJS += $(OUTPUT)tests/switch-tracking.o +LIB_OBJS += $(OUTPUT)tests/buildid-cache.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o@@ -699,6 +700,9 @@ $(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \ $< +$(OUTPUT)tests/buildid-cache.o: tests/buildid-cache.c $(OUTPUT)PERF-CFLAGS + $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) '-DBINDIR="$(bindir_SQ)"' $< + $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \ -DPYTHONPATH='"$(OUTPUT)python"' \@@ -944,7 +948,8 @@ endif $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ - $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' + $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ + $(INSTALL) tests/buildid-cache.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests' install: install-bin try-install-man install-traceevent-pluginstools/perf/tests/buildid-cache.c new file +88
-0@@ -0,0 +1,88 @@ +#include <api/fs/fs.h> +#include "tests.h" +#include "symbol.h" +#include "build-id.h" +#include "debug.h" +#include "exec_cmd.h" + +static int add_kernel (void ) +{ +char path[PATH_MAX ]; +u8 build_id[BUILD_ID_SIZE ]; +char sbuild_id[BUILD_ID_SIZE *2 +1 ]; +int ret; + +sprintf (path,"%s/kernel/notes" ,sysfs__mountpoint ()); + + ret =sysfs__read_build_id (path, build_id,sizeof (build_id)); +TEST_ASSERT_VAL ("failed to get kernel buildid" , !ret); + +build_id__sprintf (build_id,sizeof (build_id), sbuild_id); + +return build_id_cache__add_s (sbuild_id, buildid_dir, +"[kernel.kallsyms]" , true, false); +} + +static int __run_script (const char *script,const char *perf,char *cache) +{ +char cmd[PATH_MAX *3 +5 ]; + +scnprintf (cmd,sizeof (cmd),"%s/buildid-cache.sh %s %s %d" , + script, perf, cache, verbose); +return system (cmd); +} + +static int run_script (char *cache) +{ +struct stat st; +char path_perf[PATH_MAX ]; +char path_script[PATH_MAX ]; + +/* First try development tree tests. */ +if (!lstat ("./tests" , &st)) +return __run_script ("./tests" ,"./perf" , cache); + +/* Then installed path. */ +snprintf (path_script,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); + +if (!lstat (path_script, &st) && !lstat (path_perf, &st)) +return __run_script (path_script, path_perf, cache); + +fprintf (stderr," (omitted)" ); +return 0 ; +} + +static int __test__buildid_cache (char *cache) +{ +set_buildid_dir (cache); + +/* +* Adding [kernel.kallsyms] entry, because we will test +* its removal via perf buildid-cache clean in the +* script part. +* NOTE it's not possible to add [kernel.kallsyms] entry +* by script at the moment. +*/ +TEST_ASSERT_VAL ("failed to add [kernel.kallsyms] buildid" , + !add_kernel ()); + +TEST_ASSERT_VAL ("script failed" , !run_script (cache)); +return 0 ; +} + +int test__buildid_cache (void ) +{ +char cache[50 ]; + +/* +* The directory removal is done within +* __test__buildid_cache function. +*/ +snprintf (cache,sizeof (cache),"/tmp/perf-XXXXXX" ); +TEST_ASSERT_VAL ("failed to make temp directory" ,mkdtemp (cache)); + +pr_debug ("buildid cache directory: %s\n" , cache); + +return __test__buildid_cache (cache); +}tools/perf/tests/buildid-cache.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh + +perf=$1 +cache=$2 +verbose=$3 + +function pr_debug +{ + if [ "$verbose" -gt "0" ]; then + echo "$@" + fi +} + +function run_perf +{ + $perf --no-pager --buildid-dir $cache $@ +} + +# Remove prepared '[kernel.kallsyms]' via 1 byte clean limit +run_perf buildid-cache clean -a -r 1B 2>/dev/null +dir="$cache/[kernel.kallsyms]" +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to remove [kernel.kallsyms] cache files" + exit 1 +fi + +# add perf binary +run_perf buildid-cache -a $perf 2>/dev/null +dir_perf=$cache/`realpath $perf` +if [ ! -d $dir_perf ]; then + pr_debug "Failed to add perf binary into cache" + exit 1 +fi + +# remove perf binary +run_perf buildid-cache -r $perf 2>/dev/null +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to remove perf binary from cache" + exit 1 +fi + +# add perf binary +run_perf buildid-cache -a $perf 2>/dev/null +# add sh binary +run_perf buildid-cache -a `realpath /bin/sh` 2>/dev/null +dir_sh=$cache/`realpath /bin/sh` +if [ ! -d $dir_perf -o ! -d $dir_sh ]; then + pr_debug "Failed to add perf/sh binary into cache" + exit 1 +fi + +# clean all +run_perf buildid-cache clean -r 2>/dev/null +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to cleanup the cache" + exit 1 +fi + +# last command, $cache directory should be empty +rmdir $cachetools/perf/tests/builtin-test.c +8
-0@@ -167,6 +167,14 @@ static struct test { .func = test__fdarray__add, }, { + .desc = "Add fd to a fdarray, making it autogrow", + .func = test__fdarray__add, + }, + { + .desc = "Test buildid cache", + .func = test__buildid_cache, + }, + { .func = NULL, }, };tools/perf/tests/tests.h +1
-0@@ -51,6 +51,7 @@ int test__hists_cumulate(void);int test__switch_tracking (void );int test__fdarray__filter (void );int test__fdarray__add (void ); +int test__buildid_cache (void );#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)#ifdef HAVE_DWARF_UNWIND_SUPPORT Signature · 1 line
1.9.3
Re: [PATCH 5/8] perf buildid-cache: Add automated tests
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Mon, Dec 01, 2014 at 08:06:26PM +0100, Jiri Olsa escreveu:
Quoted 1 line
Adding automated test for buildid-cache command/processing.
Does it only work if one is in the
tools/perf/directory? Why not remove that './' from './perf' and ditch that fallback mechanism (BINDIR).If all you want to make sure is that the binary used is the one just built and not the system one, then you can make sure that in your PATH the directory with the development one is comes first, right?
I.e. no need for that fallbacking mechanism, etc.
well it's done the same way 'perf test attr' is done, because both needs external script.. I did it only to fit my needs.. from my POV I'm either in the:
1) - $SRC/tools/perf - developing perf
or
2) - anywhere else - not developing perf ;-)
in case 1) I need perf to run the in tree version of the script and
in case 2) it runs the installed version of the script
jirka
Quoted 249 lines
- Arnaldo
Quoted 246 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/Makefile.perf | 7 +++- tools/perf/tests/buildid-cache.c | 88 +++++++++++++++++++++++++++++++++++++++ tools/perf/tests/buildid-cache.sh | 60 ++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 8 ++++ tools/perf/tests/tests.h | 1 + 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/buildid-cache.c create mode 100755 tools/perf/tests/buildid-cache.shtools/perf/Makefile.perf +6
-1@@ -447,6 +447,7 @@ endif LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o LIB_OBJS += $(OUTPUT)tests/switch-tracking.o +LIB_OBJS += $(OUTPUT)tests/buildid-cache.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o@@ -699,6 +700,9 @@ $(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \ $< +$(OUTPUT)tests/buildid-cache.o: tests/buildid-cache.c $(OUTPUT)PERF-CFLAGS + $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) '-DBINDIR="$(bindir_SQ)"' $< + $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \ -DPYTHONPATH='"$(OUTPUT)python"' \@@ -944,7 +948,8 @@ endif $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ - $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr' + $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ + $(INSTALL) tests/buildid-cache.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests' install: install-bin try-install-man install-traceevent-pluginstools/perf/tests/buildid-cache.c new file +88
-0@@ -0,0 +1,88 @@ +#include <api/fs/fs.h> +#include "tests.h" +#include "symbol.h" +#include "build-id.h" +#include "debug.h" +#include "exec_cmd.h" + +static int add_kernel (void ) +{ +char path[PATH_MAX ]; +u8 build_id[BUILD_ID_SIZE ]; +char sbuild_id[BUILD_ID_SIZE *2 +1 ]; +int ret; + +sprintf (path,"%s/kernel/notes" ,sysfs__mountpoint ()); + + ret =sysfs__read_build_id (path, build_id,sizeof (build_id)); +TEST_ASSERT_VAL ("failed to get kernel buildid" , !ret); + +build_id__sprintf (build_id,sizeof (build_id), sbuild_id); + +return build_id_cache__add_s (sbuild_id, buildid_dir, +"[kernel.kallsyms]" , true, false); +} + +static int __run_script (const char *script,const char *perf,char *cache) +{ +char cmd[PATH_MAX *3 +5 ]; + +scnprintf (cmd,sizeof (cmd),"%s/buildid-cache.sh %s %s %d" , + script, perf, cache, verbose); +return system (cmd); +} + +static int run_script (char *cache) +{ +struct stat st; +char path_perf[PATH_MAX ]; +char path_script[PATH_MAX ]; + +/* First try development tree tests. */ +if (!lstat ("./tests" , &st)) +return __run_script ("./tests" ,"./perf" , cache); + +/* Then installed path. */ +snprintf (path_script,PATH_MAX ,"%s/tests" ,perf_exec_path ()); +snprintf (path_perf,PATH_MAX ,"%s/perf" ,BINDIR ); + +if (!lstat (path_script, &st) && !lstat (path_perf, &st)) +return __run_script (path_script, path_perf, cache); + +fprintf (stderr," (omitted)" ); +return 0 ; +} + +static int __test__buildid_cache (char *cache) +{ +set_buildid_dir (cache); + +/* +* Adding [kernel.kallsyms] entry, because we will test +* its removal via perf buildid-cache clean in the +* script part. +* NOTE it's not possible to add [kernel.kallsyms] entry +* by script at the moment. +*/ +TEST_ASSERT_VAL ("failed to add [kernel.kallsyms] buildid" , + !add_kernel ()); + +TEST_ASSERT_VAL ("script failed" , !run_script (cache)); +return 0 ; +} + +int test__buildid_cache (void ) +{ +char cache[50 ]; + +/* +* The directory removal is done within +* __test__buildid_cache function. +*/ +snprintf (cache,sizeof (cache),"/tmp/perf-XXXXXX" ); +TEST_ASSERT_VAL ("failed to make temp directory" ,mkdtemp (cache)); + +pr_debug ("buildid cache directory: %s\n" , cache); + +return __test__buildid_cache (cache); +}tools/perf/tests/buildid-cache.sh new file +60
-0@@ -0,0 +1,60 @@ +#!/bin/sh + +perf=$1 +cache=$2 +verbose=$3 + +function pr_debug +{ + if [ "$verbose" -gt "0" ]; then + echo "$@" + fi +} + +function run_perf +{ + $perf --no-pager --buildid-dir $cache $@ +} + +# Remove prepared '[kernel.kallsyms]' via 1 byte clean limit +run_perf buildid-cache clean -a -r 1B 2>/dev/null +dir="$cache/[kernel.kallsyms]" +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to remove [kernel.kallsyms] cache files" + exit 1 +fi + +# add perf binary +run_perf buildid-cache -a $perf 2>/dev/null +dir_perf=$cache/`realpath $perf` +if [ ! -d $dir_perf ]; then + pr_debug "Failed to add perf binary into cache" + exit 1 +fi + +# remove perf binary +run_perf buildid-cache -r $perf 2>/dev/null +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to remove perf binary from cache" + exit 1 +fi + +# add perf binary +run_perf buildid-cache -a $perf 2>/dev/null +# add sh binary +run_perf buildid-cache -a `realpath /bin/sh` 2>/dev/null +dir_sh=$cache/`realpath /bin/sh` +if [ ! -d $dir_perf -o ! -d $dir_sh ]; then + pr_debug "Failed to add perf/sh binary into cache" + exit 1 +fi + +# clean all +run_perf buildid-cache clean -r 2>/dev/null +if [ "$(ls -A $cache)" ]; then + pr_debug "Failed to cleanup the cache" + exit 1 +fi + +# last command, $cache directory should be empty +rmdir $cachetools/perf/tests/builtin-test.c +8
-0@@ -167,6 +167,14 @@ static struct test { .func = test__fdarray__add, }, { + .desc = "Add fd to a fdarray, making it autogrow", + .func = test__fdarray__add, + }, + { + .desc = "Test buildid cache", + .func = test__buildid_cache, + }, + { .func = NULL, }, };tools/perf/tests/tests.h +1
-0@@ -51,6 +51,7 @@ int test__hists_cumulate(void);int test__switch_tracking (void );int test__fdarray__filter (void );int test__fdarray__add (void ); +int test__buildid_cache (void );#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)#ifdef HAVE_DWARF_UNWIND_SUPPORT Signature · 1 line
1.9.3
Jiri Olsa
reviewerPATCH 6/8 perf buildid cache: Fix -a segfault
In reply to Jiri OlsaThe kcore_filename is uninitialized and trash value could trigger build_id_cache__add_kcore function ending up with segfault.
--- tools/perf/builtin-buildid-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-buildid-cache.c +1 -1
@@ -737,7 +737,7 @@ int cmd_buildid_cache(int argc, const char **argv, *remove_name_list_str =NULL , *missing_filename =NULL , *update_name_list_str =NULL , - *kcore_filename; + *kcore_filename =NULL ;char sbuf[STRERR_BUFSIZE ];struct perf_data_file file = {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
AppliedRe: [PATCH 6/8] perf buildid cache: Fix -a segfault
Em Mon, Dec 01, 2014 at 08:06:27PM +0100, Jiri Olsa escreveu:
Quoted 3 lines
The
kcore_filenameis uninitialized and trash value could triggerbuild_id_cache__add_kcorefunction ending up with segfault.
Applied
Quoted 30 lines
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-buildid-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-buildid-cache.c +1
-1@@ -737,7 +737,7 @@ int cmd_buildid_cache(int argc, const char **argv, *remove_name_list_str =NULL , *missing_filename =NULL , *update_name_list_str =NULL , - *kcore_filename; + *kcore_filename =NULL ;char sbuf[STRERR_BUFSIZE ];struct perf_data_file file = {Signature · 1 line
1.9.3
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf buildid cache: Fix -a segfault related to kcore handling
In reply to Jiri Olsaperf buildid cache: Fix -a segfault related to kcore handling
Commit-ID: eec5a688f426d6fe4097feb0b916ad41803d2ebb Gitweb: http://git.kernel.org/tip/eec5a688f426d6fe4097feb0b916ad41803d2ebb Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 1 Dec 2014 20:06:27 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 9 Dec 2014 09:14:34 -0300
perf buildid cache: Fix -a segfault related to kcore handling
The kcore_filename is uninitialized and trash value could trigger build_id_cache__add_kcore function ending up with segfault.
--- tools/perf/builtin-buildid-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-buildid-cache.c +1 -1
@@ -289,7 +289,7 @@ int cmd_buildid_cache(int argc, const char **argv, *remove_name_list_str =NULL , *missing_filename =NULL , *update_name_list_str =NULL , - *kcore_filename; + *kcore_filename =NULL ;char sbuf[STRERR_BUFSIZE ];struct perf_data_file file = {
Jiri Olsa
reviewerPATCH 7/8 perf buildid-cache: Fix kallsyms removal
In reply to Jiri OlsaAdd support to remove '[kernel.kallsyms]' file. Currently the removal fails because buildid read fails (obviously on kallsyms file).
However the file name itself holds the buildid which is used in the .build-id link. Adding check to detect the '[kernel.kallsyms]' removal and using the filename as the buildid.
--- tools/perf/builtin-buildid-cache.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
tools/perf/builtin-buildid-cache.c +32 -2
@@ -207,6 +207,25 @@ static int build_id_cache__add_file(const char *filename, const char *debugdir)return err; } +/* +* Takes basename from @filename argument and +* copy that into @buf. +*/ +static int scnprintf_base (char *buf,int size,const char *filename) +{ +char *base =strrchr (filename,'/' ); + +if (!base++) +return -1 ; + +return scnprintf (buf, size, base,strlen (base)); +} + +static bool is_kallsyms_file (const char *filename) +{ +return strstr (filename,"kernel.kallsyms" ); +} +static int build_id_cache__remove_file (const char *filename,const char *debugdir) {
@@ -217,10 +236,21 @@ static int build_id_cache__remove_file(const char *filename,if (filename__read_build_id (filename, &build_id,sizeof (build_id)) <0 ) {pr_debug ("Couldn't read a build-id in %s\n" , filename); -return -1 ; + +if (!is_kallsyms_file (filename)) +return -1 ; + +pr_debug ("Detected [kernel.kallsyms] file, trying basename as buildid.\n" ); + +if (scnprintf_base (sbuild_id,sizeof (sbuild_id), + filename) <0 ) { +pr_debug ("failed to get build-id\n" ); +return -1 ; + } + }else { +build_id__sprintf (build_id,sizeof (build_id), sbuild_id); } -build_id__sprintf (build_id,sizeof (build_id), sbuild_id); err =build_id_cache__remove_s (sbuild_id, debugdir);if (verbose) pr_info("Removing %s %s: %s\n", sbuild_id, filename,
Signature · 1 line
1.9.3
Jiri Olsa
reviewerPATCH 8/8 perf buildid-cache: Try to remove empty directories
In reply to Jiri OlsaThe cache removal routine only removes files leaving directories untouched. Adding code that tries to remove directories up to the 'buildid_dir' level.
--- tools/perf/util/build-id.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
tools/perf/util/build-id.c +43 -1
@@ -329,11 +329,41 @@ static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size, is_kallsyms, is_vdso); } +/* +* Tries to remove directory of the file given in +* the @file parameter. It might change the string +* pointed to by the @file pointer. +*/ +static void try_remove_dir (char *file,const char *debugdir) +{ +char *dir =dirname (file); + +while (dir) { +char *slash; + +if (!strcmp (dir, debugdir)) +return ; + +pr_debug ("try_remove_dir %s\n" , dir); + +/* We dont care if it failes, we tried.. */ +if (rmdir (dir)) +return ; + + slash =strrchr (dir,'/' ); +if (!slash) +return ; + + *slash =0 ; + } +} +int build_id_cache__remove_s (const char *sbuild_id,const char *debugdir) {const size_t size =PATH_MAX ;char *filename =zalloc (size), - *linkname =zalloc (size); + *linkname =zalloc (size), + *build_id_link =NULL ;int err =-1 ;if (filename ==NULL || linkname ==NULL )
@@ -351,6 +381,10 @@ int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir)if (unlink (linkname)) goto out_free; + build_id_link =strdup (linkname); +if (!build_id_link) + goto out_free; +/* * Since the link is relative, we must make it absolute: */
@@ -360,10 +394,18 @@ int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir)if (unlink (linkname)) goto out_free; +/* +* The order matters here, because linkname path +* is based on build_id_link path. +*/ +try_remove_dir (linkname, debugdir); +try_remove_dir (build_id_link, debugdir); + err =0 ; out_free:free (filename);free (linkname); +free (build_id_link);return err; }
Signature · 1 line
1.9.3
Em Mon, Dec 01, 2014 at 08:06:21PM +0100, Jiri Olsa escreveu:
Quoted 9 lines
hi,
adding 'perf buildid-cache clean' command to allow removal files from '~/.debug` cache plus other fixes.Basically the clean command allows to display/remove cache files/sizes like:
Display cache files older than 3 days:
$ perf buildid-cache clean 3d
This is confusing, I went on parsing and the above command meant: clean the files that are 3 days or older.
Right now we have:
usage: perf buildid-cache [<options>]
-a, --add <file list>
file(s) to add
-k, --kcore <file> kcore file to add
-r, --remove <file list>
file(s) to remove
-M, --missing <file> to find missing build ids in the cache
-f, --force don't complain, do it
-u, --update <file list>
file(s) to update
-v, --verbose be more verbose[acme@sandy wb]$
If we keep the way it is, I think it would be clearer to add a -l/--list command and that would:
perf buildid-cache --list # list all the files in the cache perf buildid-cache --list 3d # list 3 days old files perf buildid-cache --list +3d # list files 3 days or more older perf buildid-cache --list -3d # list files up to 3 days old
And all these would print the sum of the matching files, i.e. the space those files use in the filesystem.
Quoted 2 lines
Remove cache files older than 3 days:
$ perf buildid-cache clean 3d -r
perf buildid-cache --remove [-+]Nd # Same semantics as above
Quoted 3 lines
Total cache removal:
$ perf buildid-cache clean -r
perf buildid-cache --remove '*'
Quoted 2 lines
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200M
But yeah, perhaps we could switch to having subcommands and add:
perf buildid-cache [add|remove|update|list]
What do you think?
Also in this process, we should rename buildid-cache to a shorter form, 'cache', i.e. 'perf cache', or we can leave this for later, for Masami's patchkit we discussed recently.
- Arnaldo
Quoted 46 lines
Also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_buildid_cache_cleanthanks,
jirkaCc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Stephane Eranian <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Jiri Olsa <[email protected]>---
Jiri Olsa (8):
perf tools: Use single strcmp call instead of two perf tools: Remove extra debugdir variables
perf tools: Add --buildid-dir option to set cache directory perf buildid-cache: Add clean command
perf buildid-cache: Add automated tests
perf buildid cache: Fix -a segfault
perf buildid-cache: Fix kallsyms removal
perf buildid-cache: Try to remove empty directoriestools/perf/Documentation/perf-buildid-cache.txt | 59 +++++++++++ tools/perf/Documentation/perf.txt | 4 + tools/perf/Makefile.perf | 7 +- tools/perf/builtin-buildid-cache.c | 501 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- tools/perf/perf.c | 14 ++- tools/perf/tests/buildid-cache.c | 88 ++++++++++++++++ tools/perf/tests/buildid-cache.sh | 60 +++++++++++ tools/perf/tests/builtin-test.c | 8 ++ tools/perf/tests/tests.h | 1 + tools/perf/util/build-id.c | 53 ++++++++-- tools/perf/util/config.c | 10 +- tools/perf/util/util.h | 2 +- 12 files changed, 781 insertions(+), 26 deletions(-) create mode 100644 tools/perf/tests/buildid-cache.c create mode 100755 tools/perf/tests/buildid-cache.sh
On Mon, Dec 01, 2014 at 08:29:19PM -0200, Arnaldo Carvalho de Melo wrote:
SNIP
Quoted 9 lines
[acme@sandy wb]$
If we keep the way it is, I think it would be clearer to add a -l/--list command and that would:
perf buildid-cache --list # list all the files in the cache perf buildid-cache --list 3d # list 3 days old files perf buildid-cache --list +3d # list files 3 days or more older perf buildid-cache --list -3d # list files up to 3 days old
ok, I was up to old files (and big files) removal only.. not sure the other way will be actually needed.. but it's easy enought to add
Quoted 7 lines
And all these would print the sum of the matching files, i.e. the space those files use in the filesystem.
Quoted 2 lines
Remove cache files older than 3 days:
$ perf buildid-cache clean 3d -r
Quoted 7 lines
perf buildid-cache --remove [-+]Nd # Same semantics as aboveQuoted 3 lines
Total cache removal:
$ perf buildid-cache clean -rperf buildid-cache --remove '*'
hum, maybe '--removal all' might be better
Quoted 9 lines
Quoted 3 lines
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200MBut yeah, perhaps we could switch to having subcommands and add:
perf buildid-cache [add|remove|update|list]
What do you think?
yep, those commands seem nicer..
let's see of there're other comments and I'll come up with new interface after..
thanks,
jirka
Em Tue, Dec 02, 2014 at 01:25:18PM +0100, Jiri Olsa escreveu:
Quoted 9 lines · Arnaldo Carvalho de Melo
SNIP
Quoted 4 lines
[acme@sandy wb]$
If we keep the way it is, I think it would be clearer to add a -l/--list command and that would:
Quoted 8 lines
Quoted 4 lines
perf buildid-cache --list # list all the files in the cache perf buildid-cache --list 3d # list 3 days old files perf buildid-cache --list +3d # list files 3 days or more older perf buildid-cache --list -3d # list files up to 3 days oldok, I was up to old files (and big files) removal only.. not sure the other way will be actually needed.. but it's easy enought to add
Right, I was thinking something along the lines of checking how much space would be needed if I wanted to keep X days of cache, not how much space I would free if I purged files older than Y days.
Quoted 9 lines
Quoted 9 lines
And all these would print the sum of the matching files, i.e. the space those files use in the filesystem.
Quoted 2 lines
Remove cache files older than 3 days:
$ perf buildid-cache clean 3d -rperf buildid-cache --remove [-+]Nd # Same semantics as aboveQuoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Total cache removal:
$ perf buildid-cache clean -rperf buildid-cache --remove '*'
hum, maybe '--removal all' might be better
Humm, lemme see how ccache does this operation... That would be an existing cache management workflow that we could reuse:
[acme@zoo linux]$ ccache --help
Usage:
ccache [options]
ccache compiler [compiler options]
compiler [compiler options] (via symbolic link)
Options:
-c, --cleanup delete old files and recalculate size counters
(normally not needed as this is done automatically)
-C, --clear clear the cache completely
-F, --max-files=N set maximum number of files in cache to N (use 0 for
no limit)
-M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no
limit; available suffixes: G, M and K; default
suffix: G)
-s, --show-stats show statistics summary
-z, --zero-stats zero statistics counters
-h, --help print this help text
-V, --version print version and copyright information
See also <http://ccache.samba.org>.
[acme@zoo linux]$
So, there you go, the 'clear' keywoard being used for doing what you called 'removeall' and I called --remove '*'. Perhaps asking if the user really wants to do that while, just like with the time limited 'remove' operations showing how much space it will release (albeit that could take some time to calculate...)?
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200MBut yeah, perhaps we could switch to having subcommands and add:
Quoted 8 lines
Quoted 3 lines
perf buildid-cache [add|remove|update|list]
What do you think?
yep, those commands seem nicer..
let's see of there're other comments and I'll come up with new interface after..
Ok!
- Arnaldo
Namhyung Kim
maintainerHi Arnaldo and Jiri,
Quoted 15 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 02, 2014 at 01:25:18PM +0100, Jiri Olsa escreveu:
Quoted 13 lines · Arnaldo Carvalho de Melo
SNIP
Quoted 9 lines
[acme@sandy wb]$
If we keep the way it is, I think it would be clearer to add a -l/--list command and that would:
perf buildid-cache --list # list all the files in the cache perf buildid-cache --list 3d # list 3 days old files perf buildid-cache --list +3d # list files 3 days or more older perf buildid-cache --list -3d # list files up to 3 days old
Quoted 7 lines
Quoted 3 lines
ok, I was up to old files (and big files) removal only.. not sure the other way will be actually needed.. but it's easy enought to add
Right, I was thinking something along the lines of checking how much space would be needed if I wanted to keep X days of cache, not how much space I would free if I purged files older than Y days.
Btw, which timestamp do you use for the checking? It'd be great if we can use atime but some system might use the noatime..
Quoted 43 lines
Quoted 11 lines
Quoted 11 lines
And all these would print the sum of the matching files, i.e. the space those files use in the filesystem.
Quoted 2 lines
Remove cache files older than 3 days:
$ perf buildid-cache clean 3d -rperf buildid-cache --remove [-+]Nd # Same semantics as aboveQuoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Total cache removal:
$ perf buildid-cache clean -rperf buildid-cache --remove '*'
hum, maybe '--removal all' might be better
Humm, lemme see how ccache does this operation... That would be an existing cache management workflow that we could reuse:
[acme@zoo linux]$ ccache --help
Usage:
ccache [options]
ccache compiler [compiler options]
compiler [compiler options] (via symbolic link)Options:
-c, --cleanup delete old files and recalculate size counters
(normally not needed as this is done automatically)
-C, --clear clear the cache completely
-F, --max-files=N set maximum number of files in cache to N (use 0 for
no limit)
-M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no
limit; available suffixes: G, M and K; default
suffix: G)
-s, --show-stats show statistics summary
-z, --zero-stats zero statistics counters-h, --help print this help text
-V, --version print version and copyright information
Quoted 8 lines
See also <http://ccache.samba.org>.
[acme@zoo linux]$So, there you go, the 'clear' keywoard being used for doing what you called 'removeall' and I called --remove '*'. Perhaps asking if the user really wants to do that while, just like with the time limited 'remove' operations showing how much space it will release (albeit that could take some time to calculate...)?
Yeah, I think we also need to have the stats option/command. And some kind of cache management policies too - like max size and max days? - so that it can trigger auto cleanup.. ;-)
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200MBut yeah, perhaps we could switch to having subcommands and add:
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
perf buildid-cache [add|remove|update|list]
What do you think?
yep, those commands seem nicer..
let's see of there're other comments and I'll come up with new interface after..
I also like the subcommand style.. What about git-like format to specify time range?
perf buildid-cache list --since '3 days ago'
perf buildidi-cache remove --before '1 month ago'
Thanks,
Namhyung
Quoted 23 lines · Namhyung Kim
Hi Arnaldo and Jiri,
Quoted 19 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 02, 2014 at 01:25:18PM +0100, Jiri Olsa escreveu:
Quoted 17 lines · Arnaldo Carvalho de Melo
SNIP
Quoted 9 lines
[acme@sandy wb]$
If we keep the way it is, I think it would be clearer to add a -l/--list command and that would:
perf buildid-cache --list # list all the files in the cache perf buildid-cache --list 3d # list 3 days old files perf buildid-cache --list +3d # list files 3 days or more older perf buildid-cache --list -3d # list files up to 3 days oldok, I was up to old files (and big files) removal only.. not sure the other way will be actually needed.. but it's easy enought to add
Quoted 6 lines
Quoted 3 lines
Right, I was thinking something along the lines of checking how much space would be needed if I wanted to keep X days of cache, not how much space I would free if I purged files older than Y days.
Btw, which timestamp do you use for the checking? It'd be great if we can use atime but some system might use the noatime..
I used atime.. will need to check, I wasnt aware of this
SNIP
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 4 lines
Remove and display items bigger than 200M
$ perf buildid-cache clean -r -a 200MBut yeah, perhaps we could switch to having subcommands and add:
perf buildid-cache [add|remove|update|list]
What do you think?
yep, those commands seem nicer..
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
let's see of there're other comments and I'll come up with new interface after..
I also like the subcommand style.. What about git-like format to specify time range?
perf buildid-cache list --since '3 days ago'
perf buildidi-cache remove --before '1 month ago'
yea, thats more readable, I'll check git sources.. hopefully they use this in some steal-able way ;-)
jirka