aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/probe-event.c
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2010-03-16 18:06:05 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-17 06:32:31 -0400
commitf4d7da499e4fc1fdff8f26fdeb1a058d475a7a6c (patch)
tree5ca14cb193ccc56c675a95ab8b97d6515575c83d /tools/perf/util/probe-event.c
parent016f262e4fb10c6ecff709317098912f94a21efa (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>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r--tools/perf/util/probe-event.c24
1 files changed, 16 insertions, 8 deletions
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
52bool 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
433static int open_kprobe_events(int flags, int mode) 435static 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
593static void get_new_event_name(char *buf, size_t len, const char *base, 601static 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