Commit 89c69c0e authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar

perf: Use eprintf() for debug messages in perf-probe

Replace debug() macro with eprintf() and add -v option for
showing those messages in perf-probe.
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20091017000810.16556.38013.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 074fc0e4
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "perf.h" #include "perf.h"
#include "builtin.h" #include "builtin.h"
#include "util/util.h" #include "util/util.h"
#include "util/event.h"
#include "util/debug.h"
#include "util/parse-options.h" #include "util/parse-options.h"
#include "util/parse-events.h" /* For debugfs_path */ #include "util/parse-events.h" /* For debugfs_path */
#include "util/probe-finder.h" #include "util/probe-finder.h"
...@@ -76,7 +78,7 @@ static int parse_probepoint(const struct option *opt __used, ...@@ -76,7 +78,7 @@ static int parse_probepoint(const struct option *opt __used,
if (!str) /* The end of probe points */ if (!str) /* The end of probe points */
return 0; return 0;
debug("Probe-define(%d): %s\n", session.nr_probe, str); eprintf("probe-definition(%d): %s\n", session.nr_probe, str);
if (++session.nr_probe == MAX_PROBES) if (++session.nr_probe == MAX_PROBES)
semantic_error("Too many probes"); semantic_error("Too many probes");
...@@ -101,7 +103,7 @@ static int parse_probepoint(const struct option *opt __used, ...@@ -101,7 +103,7 @@ static int parse_probepoint(const struct option *opt __used,
die("strndup"); die("strndup");
if (++argc == MAX_PROBE_ARGS) if (++argc == MAX_PROBE_ARGS)
semantic_error("Too many arguments"); semantic_error("Too many arguments");
debug("argv[%d]=%s\n", argc, argv[argc - 1]); eprintf("argv[%d]=%s\n", argc, argv[argc - 1]);
} }
} while (*str != '\0'); } while (*str != '\0');
if (argc < 2) if (argc < 2)
...@@ -131,7 +133,7 @@ static int parse_probepoint(const struct option *opt __used, ...@@ -131,7 +133,7 @@ static int parse_probepoint(const struct option *opt __used,
pp->line = atoi(ptr); pp->line = atoi(ptr);
if (!pp->file || !pp->line) if (!pp->file || !pp->line)
semantic_error("Failed to parse line."); semantic_error("Failed to parse line.");
debug("file:%s line:%d\n", pp->file, pp->line); eprintf("file:%s line:%d\n", pp->file, pp->line);
} else { } else {
/* Function name */ /* Function name */
ptr = strchr(arg, '+'); ptr = strchr(arg, '+');
...@@ -148,7 +150,7 @@ static int parse_probepoint(const struct option *opt __used, ...@@ -148,7 +150,7 @@ static int parse_probepoint(const struct option *opt __used,
pp->file = strdup(ptr); pp->file = strdup(ptr);
} }
pp->function = strdup(arg); pp->function = strdup(arg);
debug("symbol:%s file:%s offset:%d\n", eprintf("symbol:%s file:%s offset:%d\n",
pp->function, pp->file, pp->offset); pp->function, pp->file, pp->offset);
} }
free(argv[1]); free(argv[1]);
...@@ -173,7 +175,7 @@ static int parse_probepoint(const struct option *opt __used, ...@@ -173,7 +175,7 @@ static int parse_probepoint(const struct option *opt __used,
session.need_dwarf = 1; session.need_dwarf = 1;
} }
debug("%d arguments\n", pp->nr_args); eprintf("%d arguments\n", pp->nr_args);
return 0; return 0;
} }
...@@ -186,7 +188,7 @@ static int open_default_vmlinux(void) ...@@ -186,7 +188,7 @@ static int open_default_vmlinux(void)
ret = uname(&uts); ret = uname(&uts);
if (ret) { if (ret) {
debug("uname() failed.\n"); eprintf("uname() failed.\n");
return -errno; return -errno;
} }
session.release = uts.release; session.release = uts.release;
...@@ -194,11 +196,12 @@ static int open_default_vmlinux(void) ...@@ -194,11 +196,12 @@ static int open_default_vmlinux(void)
ret = snprintf(fname, MAX_PATH_LEN, ret = snprintf(fname, MAX_PATH_LEN,
default_search_path[i], session.release); default_search_path[i], session.release);
if (ret >= MAX_PATH_LEN || ret < 0) { if (ret >= MAX_PATH_LEN || ret < 0) {
debug("Filename(%d,%s) is too long.\n", i, uts.release); eprintf("Filename(%d,%s) is too long.\n", i,
uts.release);
errno = E2BIG; errno = E2BIG;
return -E2BIG; return -E2BIG;
} }
debug("try to open %s\n", fname); eprintf("try to open %s\n", fname);
fd = open(fname, O_RDONLY); fd = open(fname, O_RDONLY);
if (fd >= 0) if (fd >= 0)
break; break;
...@@ -213,6 +216,8 @@ static const char * const probe_usage[] = { ...@@ -213,6 +216,8 @@ static const char * const probe_usage[] = {
}; };
static const struct option options[] = { static const struct option options[] = {
OPT_BOOLEAN('v', "verbose", &verbose,
"be more verbose (show parsed arguments, etc)"),
#ifndef NO_LIBDWARF #ifndef NO_LIBDWARF
OPT_STRING('k', "vmlinux", &session.vmlinux, "file", OPT_STRING('k', "vmlinux", &session.vmlinux, "file",
"vmlinux/module pathname"), "vmlinux/module pathname"),
...@@ -336,7 +341,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ...@@ -336,7 +341,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
ret = find_probepoint(fd, pp); ret = find_probepoint(fd, pp);
if (ret <= 0) if (ret <= 0)
die("No probe point found.\n"); die("No probe point found.\n");
debug("probe event %s found\n", session.events[j]); eprintf("probe event %s found\n", session.events[j]);
} }
close(fd); close(fd);
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <ctype.h> #include <ctype.h>
#include "event.h"
#include "debug.h"
#include "util.h" #include "util.h"
#include "probe-finder.h" #include "probe-finder.h"
...@@ -134,7 +136,7 @@ static Dwarf_Unsigned die_get_fileno(Dwarf_Die cu_die, const char *fname) ...@@ -134,7 +136,7 @@ static Dwarf_Unsigned die_get_fileno(Dwarf_Die cu_die, const char *fname)
dwarf_dealloc(__dw_debug, srcs, DW_DLA_LIST); dwarf_dealloc(__dw_debug, srcs, DW_DLA_LIST);
} }
if (found) if (found)
debug("found fno: %d\n", (int)found); eprintf("found fno: %d\n", (int)found);
return found; return found;
} }
...@@ -440,7 +442,7 @@ static void find_variable(Dwarf_Die sp_die, struct probe_finder *pf) ...@@ -440,7 +442,7 @@ static void find_variable(Dwarf_Die sp_die, struct probe_finder *pf)
return ; return ;
} }
debug("Searching '%s' variable in context.\n", pf->var); eprintf("Searching '%s' variable in context.\n", pf->var);
/* Search child die for local variables and parameters. */ /* Search child die for local variables and parameters. */
ret = search_die_from_children(sp_die, variable_callback, pf); ret = search_die_from_children(sp_die, variable_callback, pf);
if (!ret) if (!ret)
...@@ -550,7 +552,7 @@ static void find_by_line(Dwarf_Die cu_die, struct probe_finder *pf) ...@@ -550,7 +552,7 @@ static void find_by_line(Dwarf_Die cu_die, struct probe_finder *pf)
ret = dwarf_lineaddr(lines[i], &addr, &__dw_error); ret = dwarf_lineaddr(lines[i], &addr, &__dw_error);
ERR_IF(ret != DW_DLV_OK); ERR_IF(ret != DW_DLV_OK);
debug("Probe point found: 0x%llx\n", addr); eprintf("Probe point found: 0x%llx\n", addr);
pf->addr = addr; pf->addr = addr;
/* Search a real subprogram including this line, */ /* Search a real subprogram including this line, */
ret = search_die_from_children(cu_die, probeaddr_callback, pf); ret = search_die_from_children(cu_die, probeaddr_callback, pf);
...@@ -581,7 +583,7 @@ static int probefunc_callback(struct die_link *dlink, void *data) ...@@ -581,7 +583,7 @@ static int probefunc_callback(struct die_link *dlink, void *data)
&pf->inl_offs, &pf->inl_offs,
&__dw_error); &__dw_error);
ERR_IF(ret != DW_DLV_OK); ERR_IF(ret != DW_DLV_OK);
debug("inline definition offset %lld\n", eprintf("inline definition offset %lld\n",
pf->inl_offs); pf->inl_offs);
return 0; return 0;
} }
...@@ -597,7 +599,7 @@ static int probefunc_callback(struct die_link *dlink, void *data) ...@@ -597,7 +599,7 @@ static int probefunc_callback(struct die_link *dlink, void *data)
/* Get probe address */ /* Get probe address */
pf->addr = die_get_entrypc(dlink->die); pf->addr = die_get_entrypc(dlink->die);
pf->addr += pp->offset; pf->addr += pp->offset;
debug("found inline addr: 0x%llx\n", pf->addr); eprintf("found inline addr: 0x%llx\n", pf->addr);
/* Inlined function. Get a real subprogram */ /* Inlined function. Get a real subprogram */
for (lk = dlink->parent; lk != NULL; lk = lk->parent) { for (lk = dlink->parent; lk != NULL; lk = lk->parent) {
tag = 0; tag = 0;
......
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
#define _stringify(n) #n #define _stringify(n) #n
#define stringify(n) _stringify(n) #define stringify(n) _stringify(n)
#ifdef DEBUG
#define debug(fmt ...) \
fprintf(stderr, "DBG(" __FILE__ ":" stringify(__LINE__) "): " fmt)
#else
#define debug(fmt ...) do {} while (0)
#endif
#define ERR_IF(cnd) \ #define ERR_IF(cnd) \
do { if (cnd) { \ do { if (cnd) { \
fprintf(stderr, "Error (" __FILE__ ":" stringify(__LINE__) \ fprintf(stderr, "Error (" __FILE__ ":" stringify(__LINE__) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment