@@ -51,6 +51,9 @@ void free_record(struct tep_record *record);
void tracecmd_set_quiet(int quiet);
int tracecmd_get_quiet(void);
+void tracecmd_set_debug(bool debug);
+bool tracecmd_get_debug(void);
+
struct tracecmd_input;
struct tracecmd_output;
@@ -32,7 +32,7 @@ static inline void dprint(const char *fmt, ...)
{
va_list ap;
- if (!debug)
+ if (!tracecmd_get_debug())
return;
va_start(ap, fmt);
@@ -351,7 +351,7 @@ static int tracecmd_msg_recv_wait(int fd, struct tracecmd_msg *msg)
pfd.fd = fd;
pfd.events = POLLIN;
- ret = poll(&pfd, 1, debug ? -1 : msg_wait_to);
+ ret = poll(&pfd, 1, tracecmd_get_debug() ? -1 : msg_wait_to);
if (ret < 0)
return -errno;
else if (ret == 0)
@@ -29,6 +29,7 @@
int tracecmd_disable_sys_plugins;
int tracecmd_disable_plugins;
static int tracecmd_quiet;
+static bool tracecmd_debug;
static struct registered_plugin_options {
struct registered_plugin_options *next;
@@ -117,6 +118,26 @@ int tracecmd_get_quiet(void)
return tracecmd_quiet;
}
+/**
+ * tracecmd_set_quiet - Set if to print output to the screen
+ * @quiet: If non zero, print no output to the screen
+ *
+ */
+void tracecmd_set_debug(bool debug)
+{
+ tracecmd_debug = debug;
+}
+
+/**
+ * tracecmd_get_quiet - Get if to print output to the screen
+ * Returns non zero, if no output to the screen should be printed
+ *
+ */
+bool tracecmd_get_debug(void)
+{
+ return tracecmd_debug;
+}
+
void trace_util_free_plugin_options_list(char **list)
{
tracecmd_free_list(list);
@@ -12,8 +12,6 @@
#include "trace-cmd.h"
#include "event-utils.h"
-extern int debug;
-
/* fix stupid glib guint64 typecasts and printf formats */
typedef unsigned long long u64;
@@ -16,8 +16,6 @@
int silence_warnings;
int show_status;
-int debug;
-
void warning(const char *fmt, ...)
{
va_list ap;
@@ -427,7 +427,7 @@ void trace_list(int argc, char **argv)
break;
case '-':
if (strcmp(argv[i], "--debug") == 0) {
- debug = true;
+ tracecmd_set_debug(true);
break;
}
fprintf(stderr, "list: invalid option -- '%s'\n",
@@ -717,7 +717,7 @@ static int do_fork(int cfd)
pid_t pid;
/* in debug mode, we do not fork off children */
- if (debug)
+ if (tracecmd_get_debug())
return 0;
pid = fork();
@@ -769,7 +769,7 @@ static int do_connection(int cfd, struct sockaddr_storage *peer_addr,
tracecmd_msg_handle_close(msg_handle);
- if (!debug)
+ if (!tracecmd_get_debug())
exit(0);
return 0;
@@ -910,7 +910,7 @@ static void do_listen(char *port)
struct addrinfo *result, *rp;
int sfd, s;
- if (!debug)
+ if (!tracecmd_get_debug())
signal_setup(SIGCHLD, sigstub);
make_pid_file();
@@ -1009,7 +1009,7 @@ void trace_listen(int argc, char **argv)
daemon = 1;
break;
case OPT_debug:
- debug = 1;
+ tracecmd_set_debug(true);
break;
default:
usage(argv);
@@ -782,10 +782,10 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)
cpu, record->missed_events);
else if (record->missed_events < 0)
trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n", cpu);
- if (buffer_breaks || debug) {
+ if (buffer_breaks || tracecmd_get_debug()) {
if (tracecmd_record_at_buffer_start(handle, record)) {
trace_seq_printf(&s, "CPU:%d [SUBBUFFER START]", cpu);
- if (debug)
+ if (tracecmd_get_debug())
trace_seq_printf(&s, " [%lld:0x%llx]",
tracecmd_page_ts(handle, record),
record->offset & ~(page_size - 1));
@@ -816,7 +816,7 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)
tep_print_event(pevent, &s, record, use_trace_clock);
if (s.len && *(s.buffer + s.len - 1) == '\n')
s.len--;
- if (debug) {
+ if (tracecmd_get_debug()) {
struct kbuffer *kbuf;
struct kbuffer_raw_info info;
void *page;
@@ -1616,7 +1616,7 @@ void trace_report (int argc, char **argv)
break;
case OPT_debug:
buffer_breaks = 1;
- debug = 1;
+ tracecmd_set_debug(true);
break;
case OPT_profile:
profile = 1;
@@ -4902,7 +4902,7 @@ static void parse_record_options(int argc,
no_filter = true;
break;
case OPT_debug:
- debug = 1;
+ tracecmd_set_debug(true);
break;
case OPT_module:
if (ctx->instance->filter_mod)
A trace-cmd global variable "debug" is used from libtracecmd and should be defined there. A new library APIs are implemented to access it: void tracecmd_set_debug(bool debug); bool tracecmd_get_debug(void); Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- include/trace-cmd/trace-cmd.h | 3 +++ lib/trace-cmd/trace-msg.c | 4 ++-- lib/trace-cmd/trace-util.c | 21 +++++++++++++++++++++ tracecmd/include/trace-local.h | 2 -- tracecmd/trace-cmd.c | 2 -- tracecmd/trace-list.c | 2 +- tracecmd/trace-listen.c | 8 ++++---- tracecmd/trace-read.c | 8 ++++---- tracecmd/trace-record.c | 2 +- 9 files changed, 36 insertions(+), 16 deletions(-)