diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2010-03-16 18:06:05 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-17 06:32:31 -0400 |
commit | f4d7da499e4fc1fdff8f26fdeb1a058d475a7a6c (patch) | |
tree | 5ca14cb193ccc56c675a95ab8b97d6515575c83d | |
parent | 016f262e4fb10c6ecff709317098912f94a21efa (diff) |
perf probe: Add --dry-run option
Add --dry-run option for debugging and testing.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20100316220605.32050.6571.stgit@localhost6.localdomain6>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | tools/perf/Documentation/perf-probe.txt | 5 | ||||
-rw-r--r-- | tools/perf/builtin-probe.c | 1 | ||||
-rw-r--r-- | tools/perf/util/probe-event.c | 24 | ||||
-rw-r--r-- | tools/perf/util/probe-event.h | 2 |
4 files changed, 24 insertions, 8 deletions
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 34202b1be0bb..0f944b3be9e9 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -57,6 +57,11 @@ OPTIONS | |||
57 | --force:: | 57 | --force:: |
58 | Forcibly add events with existing name. | 58 | Forcibly add events with existing name. |
59 | 59 | ||
60 | -n:: | ||
61 | --dry-run:: | ||
62 | Dry run. With this option, --add and --del doesn't execute actual | ||
63 | adding and removal operations. | ||
64 | |||
60 | PROBE SYNTAX | 65 | PROBE SYNTAX |
61 | ------------ | 66 | ------------ |
62 | Probe points are defined by following syntax. | 67 | Probe points are defined by following syntax. |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index f577e1410362..a1a2891ca66f 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -175,6 +175,7 @@ static const struct option options[] = { | |||
175 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", | 175 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", |
176 | "Show source code lines.", opt_show_lines), | 176 | "Show source code lines.", opt_show_lines), |
177 | #endif | 177 | #endif |
178 | OPT__DRY_RUN(&probe_event_dry_run), | ||
178 | OPT_END() | 179 | OPT_END() |
179 | }; | 180 | }; |
180 | 181 | ||
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 1e60a659578b..ac41578a3552 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -49,6 +49,8 @@ | |||
49 | #define MAX_PROBE_ARGS 128 | 49 | #define MAX_PROBE_ARGS 128 |
50 | #define PERFPROBE_GROUP "probe" | 50 | #define PERFPROBE_GROUP "probe" |
51 | 51 | ||
52 | bool probe_event_dry_run; /* Dry run flag */ | ||
53 | |||
52 | #define semantic_error(msg ...) die("Semantic error :" msg) | 54 | #define semantic_error(msg ...) die("Semantic error :" msg) |
53 | 55 | ||
54 | /* If there is no space to write, returns -E2BIG. */ | 56 | /* If there is no space to write, returns -E2BIG. */ |
@@ -430,7 +432,7 @@ error: | |||
430 | return ret; | 432 | return ret; |
431 | } | 433 | } |
432 | 434 | ||
433 | static int open_kprobe_events(int flags, int mode) | 435 | static int open_kprobe_events(bool readwrite) |
434 | { | 436 | { |
435 | char buf[PATH_MAX]; | 437 | char buf[PATH_MAX]; |
436 | int ret; | 438 | int ret; |
@@ -439,7 +441,11 @@ static int open_kprobe_events(int flags, int mode) | |||
439 | if (ret < 0) | 441 | if (ret < 0) |
440 | die("Failed to make kprobe_events path."); | 442 | die("Failed to make kprobe_events path."); |
441 | 443 | ||
442 | ret = open(buf, flags, mode); | 444 | if (readwrite && !probe_event_dry_run) |
445 | ret = open(buf, O_RDWR, O_APPEND); | ||
446 | else | ||
447 | ret = open(buf, O_RDONLY, 0); | ||
448 | |||
443 | if (ret < 0) { | 449 | if (ret < 0) { |
444 | if (errno == ENOENT) | 450 | if (errno == ENOENT) |
445 | die("kprobe_events file does not exist -" | 451 | die("kprobe_events file does not exist -" |
@@ -535,7 +541,7 @@ void show_perf_probe_events(void) | |||
535 | setup_pager(); | 541 | setup_pager(); |
536 | memset(&pp, 0, sizeof(pp)); | 542 | memset(&pp, 0, sizeof(pp)); |
537 | 543 | ||
538 | fd = open_kprobe_events(O_RDONLY, 0); | 544 | fd = open_kprobe_events(false); |
539 | rawlist = get_trace_kprobe_event_rawlist(fd); | 545 | rawlist = get_trace_kprobe_event_rawlist(fd); |
540 | close(fd); | 546 | close(fd); |
541 | 547 | ||
@@ -585,9 +591,11 @@ static void write_trace_kprobe_event(int fd, const char *buf) | |||
585 | int ret; | 591 | int ret; |
586 | 592 | ||
587 | pr_debug("Writing event: %s\n", buf); | 593 | pr_debug("Writing event: %s\n", buf); |
588 | ret = write(fd, buf, strlen(buf)); | 594 | if (!probe_event_dry_run) { |
589 | if (ret <= 0) | 595 | ret = write(fd, buf, strlen(buf)); |
590 | die("Failed to write event: %s", strerror(errno)); | 596 | if (ret <= 0) |
597 | die("Failed to write event: %s", strerror(errno)); | ||
598 | } | ||
591 | } | 599 | } |
592 | 600 | ||
593 | static void get_new_event_name(char *buf, size_t len, const char *base, | 601 | static void get_new_event_name(char *buf, size_t len, const char *base, |
@@ -630,7 +638,7 @@ static void __add_trace_kprobe_events(struct probe_point *probes, | |||
630 | struct strlist *namelist; | 638 | struct strlist *namelist; |
631 | bool allow_suffix; | 639 | bool allow_suffix; |
632 | 640 | ||
633 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 641 | fd = open_kprobe_events(true); |
634 | /* Get current event names */ | 642 | /* Get current event names */ |
635 | namelist = get_perf_event_names(fd, false); | 643 | namelist = get_perf_event_names(fd, false); |
636 | 644 | ||
@@ -814,7 +822,7 @@ void del_trace_kprobe_events(struct strlist *dellist) | |||
814 | struct str_node *ent; | 822 | struct str_node *ent; |
815 | struct strlist *namelist; | 823 | struct strlist *namelist; |
816 | 824 | ||
817 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 825 | fd = open_kprobe_events(true); |
818 | /* Get current event names */ | 826 | /* Get current event names */ |
819 | namelist = get_perf_event_names(fd, true); | 827 | namelist = get_perf_event_names(fd, true); |
820 | 828 | ||
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 3865e163bb59..703b8876dfb1 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -5,6 +5,8 @@ | |||
5 | #include "probe-finder.h" | 5 | #include "probe-finder.h" |
6 | #include "strlist.h" | 6 | #include "strlist.h" |
7 | 7 | ||
8 | extern bool probe_event_dry_run; | ||
9 | |||
8 | extern void parse_line_range_desc(const char *arg, struct line_range *lr); | 10 | extern void parse_line_range_desc(const char *arg, struct line_range *lr); |
9 | extern void parse_perf_probe_event(const char *str, struct probe_point *pp, | 11 | extern void parse_perf_probe_event(const char *str, struct probe_point *pp, |
10 | bool *need_dwarf); | 12 | bool *need_dwarf); |