aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/perf.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /tools/perf/perf.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'tools/perf/perf.c')
-rw-r--r--tools/perf/perf.c112
1 files changed, 44 insertions, 68 deletions
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 19fc7feb9d59..cd32c200cdb3 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -14,6 +14,7 @@
14#include "util/run-command.h" 14#include "util/run-command.h"
15#include "util/parse-events.h" 15#include "util/parse-events.h"
16#include "util/string.h" 16#include "util/string.h"
17#include "util/debugfs.h"
17 18
18const char perf_usage_string[] = 19const char perf_usage_string[] =
19 "perf [--version] [--help] COMMAND [ARGS]"; 20 "perf [--version] [--help] COMMAND [ARGS]";
@@ -47,7 +48,8 @@ int check_pager_config(const char *cmd)
47 return c.val; 48 return c.val;
48} 49}
49 50
50static void commit_pager_choice(void) { 51static void commit_pager_choice(void)
52{
51 switch (use_pager) { 53 switch (use_pager) {
52 case 0: 54 case 0:
53 setenv("PERF_PAGER", "cat", 1); 55 setenv("PERF_PAGER", "cat", 1);
@@ -69,7 +71,7 @@ static void set_debugfs_path(void)
69 "tracing/events"); 71 "tracing/events");
70} 72}
71 73
72static int handle_options(const char*** argv, int* argc, int* envchanged) 74static int handle_options(const char ***argv, int *argc, int *envchanged)
73{ 75{
74 int handled = 0; 76 int handled = 0;
75 77
@@ -89,8 +91,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
89 /* 91 /*
90 * Check remaining flags. 92 * Check remaining flags.
91 */ 93 */
92 if (!prefixcmp(cmd, "--exec-path")) { 94 if (!prefixcmp(cmd, CMD_EXEC_PATH)) {
93 cmd += 11; 95 cmd += strlen(CMD_EXEC_PATH);
94 if (*cmd == '=') 96 if (*cmd == '=')
95 perf_set_argv_exec_path(cmd + 1); 97 perf_set_argv_exec_path(cmd + 1);
96 else { 98 else {
@@ -108,7 +110,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
108 *envchanged = 1; 110 *envchanged = 1;
109 } else if (!strcmp(cmd, "--perf-dir")) { 111 } else if (!strcmp(cmd, "--perf-dir")) {
110 if (*argc < 2) { 112 if (*argc < 2) {
111 fprintf(stderr, "No directory given for --perf-dir.\n" ); 113 fprintf(stderr, "No directory given for --perf-dir.\n");
112 usage(perf_usage_string); 114 usage(perf_usage_string);
113 } 115 }
114 setenv(PERF_DIR_ENVIRONMENT, (*argv)[1], 1); 116 setenv(PERF_DIR_ENVIRONMENT, (*argv)[1], 1);
@@ -117,13 +119,13 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
117 (*argv)++; 119 (*argv)++;
118 (*argc)--; 120 (*argc)--;
119 handled++; 121 handled++;
120 } else if (!prefixcmp(cmd, "--perf-dir=")) { 122 } else if (!prefixcmp(cmd, CMD_PERF_DIR)) {
121 setenv(PERF_DIR_ENVIRONMENT, cmd + 10, 1); 123 setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1);
122 if (envchanged) 124 if (envchanged)
123 *envchanged = 1; 125 *envchanged = 1;
124 } else if (!strcmp(cmd, "--work-tree")) { 126 } else if (!strcmp(cmd, "--work-tree")) {
125 if (*argc < 2) { 127 if (*argc < 2) {
126 fprintf(stderr, "No directory given for --work-tree.\n" ); 128 fprintf(stderr, "No directory given for --work-tree.\n");
127 usage(perf_usage_string); 129 usage(perf_usage_string);
128 } 130 }
129 setenv(PERF_WORK_TREE_ENVIRONMENT, (*argv)[1], 1); 131 setenv(PERF_WORK_TREE_ENVIRONMENT, (*argv)[1], 1);
@@ -131,8 +133,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
131 *envchanged = 1; 133 *envchanged = 1;
132 (*argv)++; 134 (*argv)++;
133 (*argc)--; 135 (*argc)--;
134 } else if (!prefixcmp(cmd, "--work-tree=")) { 136 } else if (!prefixcmp(cmd, CMD_WORK_TREE)) {
135 setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1); 137 setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1);
136 if (envchanged) 138 if (envchanged)
137 *envchanged = 1; 139 *envchanged = 1;
138 } else if (!strcmp(cmd, "--debugfs-dir")) { 140 } else if (!strcmp(cmd, "--debugfs-dir")) {
@@ -146,8 +148,8 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
146 *envchanged = 1; 148 *envchanged = 1;
147 (*argv)++; 149 (*argv)++;
148 (*argc)--; 150 (*argc)--;
149 } else if (!prefixcmp(cmd, "--debugfs-dir=")) { 151 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
150 strncpy(debugfs_mntpt, cmd + 14, MAXPATHLEN); 152 strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN);
151 debugfs_mntpt[MAXPATHLEN - 1] = '\0'; 153 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
152 if (envchanged) 154 if (envchanged)
153 *envchanged = 1; 155 *envchanged = 1;
@@ -167,7 +169,7 @@ static int handle_alias(int *argcp, const char ***argv)
167{ 169{
168 int envchanged = 0, ret = 0, saved_errno = errno; 170 int envchanged = 0, ret = 0, saved_errno = errno;
169 int count, option_count; 171 int count, option_count;
170 const char** new_argv; 172 const char **new_argv;
171 const char *alias_command; 173 const char *alias_command;
172 char *alias_string; 174 char *alias_string;
173 175
@@ -209,11 +211,11 @@ static int handle_alias(int *argcp, const char ***argv)
209 if (!strcmp(alias_command, new_argv[0])) 211 if (!strcmp(alias_command, new_argv[0]))
210 die("recursive alias: %s", alias_command); 212 die("recursive alias: %s", alias_command);
211 213
212 new_argv = realloc(new_argv, sizeof(char*) * 214 new_argv = realloc(new_argv, sizeof(char *) *
213 (count + *argcp + 1)); 215 (count + *argcp + 1));
214 /* insert after command name */ 216 /* insert after command name */
215 memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp); 217 memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
216 new_argv[count+*argcp] = NULL; 218 new_argv[count + *argcp] = NULL;
217 219
218 *argv = new_argv; 220 *argv = new_argv;
219 *argcp += count - 1; 221 *argcp += count - 1;
@@ -284,17 +286,24 @@ static void handle_internal_command(int argc, const char **argv)
284{ 286{
285 const char *cmd = argv[0]; 287 const char *cmd = argv[0];
286 static struct cmd_struct commands[] = { 288 static struct cmd_struct commands[] = {
287 { "help", cmd_help, 0 }, 289 { "buildid-cache", cmd_buildid_cache, 0 },
288 { "list", cmd_list, 0 }, 290 { "buildid-list", cmd_buildid_list, 0 },
289 { "record", cmd_record, 0 }, 291 { "diff", cmd_diff, 0 },
290 { "report", cmd_report, 0 }, 292 { "help", cmd_help, 0 },
291 { "stat", cmd_stat, 0 }, 293 { "list", cmd_list, 0 },
292 { "timechart", cmd_timechart, 0 }, 294 { "record", cmd_record, 0 },
293 { "top", cmd_top, 0 }, 295 { "report", cmd_report, 0 },
294 { "annotate", cmd_annotate, 0 }, 296 { "bench", cmd_bench, 0 },
295 { "version", cmd_version, 0 }, 297 { "stat", cmd_stat, 0 },
296 { "trace", cmd_trace, 0 }, 298 { "timechart", cmd_timechart, 0 },
297 { "sched", cmd_sched, 0 }, 299 { "top", cmd_top, 0 },
300 { "annotate", cmd_annotate, 0 },
301 { "version", cmd_version, 0 },
302 { "trace", cmd_trace, 0 },
303 { "sched", cmd_sched, 0 },
304 { "probe", cmd_probe, 0 },
305 { "kmem", cmd_kmem, 0 },
306 { "lock", cmd_lock, 0 },
298 }; 307 };
299 unsigned int i; 308 unsigned int i;
300 static const char ext[] = STRIP_EXTENSION; 309 static const char ext[] = STRIP_EXTENSION;
@@ -382,45 +391,12 @@ static int run_argv(int *argcp, const char ***argv)
382/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */ 391/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
383static void get_debugfs_mntpt(void) 392static void get_debugfs_mntpt(void)
384{ 393{
385 FILE *file; 394 const char *path = debugfs_mount(NULL);
386 char fs_type[100];
387 char debugfs[MAXPATHLEN];
388
389 /*
390 * try the standard location
391 */
392 if (valid_debugfs_mount("/sys/kernel/debug/") == 0) {
393 strcpy(debugfs_mntpt, "/sys/kernel/debug/");
394 return;
395 }
396
397 /*
398 * try the sane location
399 */
400 if (valid_debugfs_mount("/debug/") == 0) {
401 strcpy(debugfs_mntpt, "/debug/");
402 return;
403 }
404 395
405 /* 396 if (path)
406 * give up and parse /proc/mounts 397 strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
407 */ 398 else
408 file = fopen("/proc/mounts", "r"); 399 debugfs_mntpt[0] = '\0';
409 if (file == NULL)
410 return;
411
412 while (fscanf(file, "%*s %"
413 STR(MAXPATHLEN)
414 "s %99s %*s %*d %*d\n",
415 debugfs, fs_type) == 2) {
416 if (strcmp(fs_type, "debugfs") == 0)
417 break;
418 }
419 fclose(file);
420 if (strcmp(fs_type, "debugfs") == 0) {
421 strncpy(debugfs_mntpt, debugfs, MAXPATHLEN);
422 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
423 }
424} 400}
425 401
426int main(int argc, const char **argv) 402int main(int argc, const char **argv)
@@ -469,15 +445,15 @@ int main(int argc, const char **argv)
469 445
470 /* 446 /*
471 * We use PATH to find perf commands, but we prepend some higher 447 * We use PATH to find perf commands, but we prepend some higher
472 * precidence paths: the "--exec-path" option, the PERF_EXEC_PATH 448 * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH
473 * environment, and the $(perfexecdir) from the Makefile at build 449 * environment, and the $(perfexecdir) from the Makefile at build
474 * time. 450 * time.
475 */ 451 */
476 setup_path(); 452 setup_path();
477 453
478 while (1) { 454 while (1) {
479 static int done_help = 0; 455 static int done_help;
480 static int was_alias = 0; 456 static int was_alias;
481 457
482 was_alias = run_argv(&argc, &argv); 458 was_alias = run_argv(&argc, &argv);
483 if (errno != ENOENT) 459 if (errno != ENOENT)