Commit 472cc83c3296cdc9248f1afbcfae8bba0f6f9707

Authored by Arnaldo Carvalho de Melo
1 parent 73bdc7159b

perf buildid-cache: Don't use globals where not needed to

Some variables were global but used in just one function, so move it to
where it belongs.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-6i7lqzm4hmkg35o1370lb7w4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Showing 1 changed file with 26 additions and 32 deletions Inline Diff

tools/perf/builtin-buildid-cache.c
1 /* 1 /*
2 * builtin-buildid-cache.c 2 * builtin-buildid-cache.c
3 * 3 *
4 * Builtin buildid-cache command: Manages build-id cache 4 * Builtin buildid-cache command: Manages build-id cache
5 * 5 *
6 * Copyright (C) 2010, Red Hat Inc. 6 * Copyright (C) 2010, Red Hat Inc.
7 * Copyright (C) 2010, Arnaldo Carvalho de Melo <acme@redhat.com> 7 * Copyright (C) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
8 */ 8 */
9 #include "builtin.h" 9 #include "builtin.h"
10 #include "perf.h" 10 #include "perf.h"
11 #include "util/cache.h" 11 #include "util/cache.h"
12 #include "util/debug.h" 12 #include "util/debug.h"
13 #include "util/header.h" 13 #include "util/header.h"
14 #include "util/parse-options.h" 14 #include "util/parse-options.h"
15 #include "util/strlist.h" 15 #include "util/strlist.h"
16 #include "util/symbol.h" 16 #include "util/symbol.h"
17 17
18 static char const *add_name_list_str, *remove_name_list_str;
19
20 static const char * const buildid_cache_usage[] = {
21 "perf buildid-cache [<options>]",
22 NULL
23 };
24
25 static const struct option buildid_cache_options[] = {
26 OPT_STRING('a', "add", &add_name_list_str,
27 "file list", "file(s) to add"),
28 OPT_STRING('r', "remove", &remove_name_list_str, "file list",
29 "file(s) to remove"),
30 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
31 OPT_END()
32 };
33
34 static int build_id_cache__add_file(const char *filename, const char *debugdir) 18 static int build_id_cache__add_file(const char *filename, const char *debugdir)
35 { 19 {
36 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 20 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
37 u8 build_id[BUILD_ID_SIZE]; 21 u8 build_id[BUILD_ID_SIZE];
38 int err; 22 int err;
39 23
40 if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) { 24 if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) {
41 pr_debug("Couldn't read a build-id in %s\n", filename); 25 pr_debug("Couldn't read a build-id in %s\n", filename);
42 return -1; 26 return -1;
43 } 27 }
44 28
45 build_id__sprintf(build_id, sizeof(build_id), sbuild_id); 29 build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
46 err = build_id_cache__add_s(sbuild_id, debugdir, filename, 30 err = build_id_cache__add_s(sbuild_id, debugdir, filename,
47 false, false); 31 false, false);
48 if (verbose) 32 if (verbose)
49 pr_info("Adding %s %s: %s\n", sbuild_id, filename, 33 pr_info("Adding %s %s: %s\n", sbuild_id, filename,
50 err ? "FAIL" : "Ok"); 34 err ? "FAIL" : "Ok");
51 return err; 35 return err;
52 } 36 }
53 37
54 static int build_id_cache__remove_file(const char *filename __maybe_unused, 38 static int build_id_cache__remove_file(const char *filename,
55 const char *debugdir __maybe_unused) 39 const char *debugdir)
56 { 40 {
57 u8 build_id[BUILD_ID_SIZE]; 41 u8 build_id[BUILD_ID_SIZE];
58 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 42 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
59 43
60 int err; 44 int err;
61 45
62 if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) { 46 if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) {
63 pr_debug("Couldn't read a build-id in %s\n", filename); 47 pr_debug("Couldn't read a build-id in %s\n", filename);
64 return -1; 48 return -1;
65 } 49 }
66 50
67 build_id__sprintf(build_id, sizeof(build_id), sbuild_id); 51 build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
68 err = build_id_cache__remove_s(sbuild_id, debugdir); 52 err = build_id_cache__remove_s(sbuild_id, debugdir);
69 if (verbose) 53 if (verbose)
70 pr_info("Removing %s %s: %s\n", sbuild_id, filename, 54 pr_info("Removing %s %s: %s\n", sbuild_id, filename,
71 err ? "FAIL" : "Ok"); 55 err ? "FAIL" : "Ok");
72 56
73 return err; 57 return err;
74 } 58 }
75 59
76 static int __cmd_buildid_cache(void) 60 int cmd_buildid_cache(int argc, const char **argv,
61 const char *prefix __maybe_unused)
77 { 62 {
78 struct strlist *list; 63 struct strlist *list;
79 struct str_node *pos; 64 struct str_node *pos;
80 char debugdir[PATH_MAX]; 65 char debugdir[PATH_MAX];
66 char const *add_name_list_str = NULL,
67 *remove_name_list_str = NULL;
68 const struct option buildid_cache_options[] = {
69 OPT_STRING('a', "add", &add_name_list_str,
70 "file list", "file(s) to add"),
71 OPT_STRING('r', "remove", &remove_name_list_str, "file list",
72 "file(s) to remove"),
73 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
74 OPT_END()
75 };
76 const char * const buildid_cache_usage[] = {
77 "perf buildid-cache [<options>]",
78 NULL
79 };
81 80
81 argc = parse_options(argc, argv, buildid_cache_options,
82 buildid_cache_usage, 0);
83
84 if (symbol__init() < 0)
85 return -1;
86
87 setup_pager();
88
82 snprintf(debugdir, sizeof(debugdir), "%s", buildid_dir); 89 snprintf(debugdir, sizeof(debugdir), "%s", buildid_dir);
83 90
84 if (add_name_list_str) { 91 if (add_name_list_str) {
85 list = strlist__new(true, add_name_list_str); 92 list = strlist__new(true, add_name_list_str);
86 if (list) { 93 if (list) {
87 strlist__for_each(pos, list) 94 strlist__for_each(pos, list)
88 if (build_id_cache__add_file(pos->s, debugdir)) { 95 if (build_id_cache__add_file(pos->s, debugdir)) {
89 if (errno == EEXIST) { 96 if (errno == EEXIST) {
90 pr_debug("%s already in the cache\n", 97 pr_debug("%s already in the cache\n",
91 pos->s); 98 pos->s);
92 continue; 99 continue;
93 } 100 }
94 pr_warning("Couldn't add %s: %s\n", 101 pr_warning("Couldn't add %s: %s\n",
95 pos->s, strerror(errno)); 102 pos->s, strerror(errno));
96 } 103 }
97 104
98 strlist__delete(list); 105 strlist__delete(list);
99 } 106 }
100 } 107 }
101 108
102 if (remove_name_list_str) { 109 if (remove_name_list_str) {
103 list = strlist__new(true, remove_name_list_str); 110 list = strlist__new(true, remove_name_list_str);
104 if (list) { 111 if (list) {
105 strlist__for_each(pos, list) 112 strlist__for_each(pos, list)
106 if (build_id_cache__remove_file(pos->s, debugdir)) { 113 if (build_id_cache__remove_file(pos->s, debugdir)) {
107 if (errno == ENOENT) { 114 if (errno == ENOENT) {
108 pr_debug("%s wasn't in the cache\n", 115 pr_debug("%s wasn't in the cache\n",
109 pos->s); 116 pos->s);
110 continue; 117 continue;
111 } 118 }
112 pr_warning("Couldn't remove %s: %s\n", 119 pr_warning("Couldn't remove %s: %s\n",