Patchwork trace: print a warning if user tries to enable an unknown trace event

login
register
mail settings
Submitter Blue Swirl
Date Oct. 9, 2010, 3:48 p.m.
Message ID <AANLkTimKwWnBh_wY7CM9mHJvFo2gDvhrog2RUwEDhyen@mail.gmail.com>
Download mbox | patch
Permalink /patch/67324/
State New
Headers show

Comments

Blue Swirl - Oct. 9, 2010, 3:48 p.m.
There was no warning if a bad trace event name was given to
'trace-event' command, thus the user could think that the command
was successful even if this was not the case.

Print a warning if the user tries to enable a trace event which is not
known.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 monitor.c     |    6 +++++-
 simpletrace.c |    4 +++-
 simpletrace.h |    2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

-void st_change_trace_event_state(const char *tname, bool tstate);
+bool st_change_trace_event_state(const char *tname, bool tstate);
 void st_print_trace_file_status(FILE *stream, int
(*stream_printf)(FILE *stream, const char *fmt, ...));
 void st_set_trace_file_enabled(bool enable);
 bool st_set_trace_file(const char *file);
Stefan Hajnoczi - Oct. 11, 2010, 9:25 a.m.
On Sat, Oct 09, 2010 at 03:48:18PM +0000, Blue Swirl wrote:
> There was no warning if a bad trace event name was given to
> 'trace-event' command, thus the user could think that the command
> was successful even if this was not the case.
> 
> Print a warning if the user tries to enable a trace event which is not
> known.
> 
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
>  monitor.c     |    6 +++++-
>  simpletrace.c |    4 +++-
>  simpletrace.h |    2 +-
>  3 files changed, 9 insertions(+), 3 deletions(-)

Acked-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Patch

diff --git a/monitor.c b/monitor.c
index fbb678d..260cc02 100644
--- a/monitor.c
+++ b/monitor.c
@@ -549,7 +549,11 @@  static void do_change_trace_event_state(Monitor
*mon, const QDict *qdict)
 {
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
-    st_change_trace_event_state(tp_name, new_state);
+    int ret = st_change_trace_event_state(tp_name, new_state);
+
+    if (!ret) {
+        monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+    }
 }

 static void do_trace_file(Monitor *mon, const QDict *qdict)
diff --git a/simpletrace.c b/simpletrace.c
index f849e42..deb1e07 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -246,12 +246,14 @@  static TraceEvent*
find_trace_event_by_name(const char *tname)
     return NULL; /* indicates end of list reached without a match */
 }

-void st_change_trace_event_state(const char *tname, bool tstate)
+bool st_change_trace_event_state(const char *tname, bool tstate)
 {
     TraceEvent *tp;

     tp = find_trace_event_by_name(tname);
     if (tp) {
         tp->state = tstate;
+        return true;
     }
+    return false;
 }
diff --git a/simpletrace.h b/simpletrace.h
index cf35897..72614ec 100644
--- a/simpletrace.h
+++ b/simpletrace.h
@@ -31,7 +31,7 @@  void trace5(TraceEventID event, uint64_t x1,
uint64_t x2, uint64_t x3, uint64_t
 void trace6(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t
x3, uint64_t x4, uint64_t x5, uint64_t x6);
 void st_print_trace(FILE *stream, int (*stream_printf)(FILE *stream,
const char *fmt, ...));
 void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE
*stream, const char *fmt, ...));