Received: from eggs.gnu.org ([2001:4830:134:3::10]:60097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKtYp-0002ta-Fu for qemu-devel@nongnu.org; Fri, 22 Aug 2014 14:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKtYh-00053X-7k for qemu-devel@nongnu.org; Fri, 22 Aug 2014 14:27:39 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:36779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKtYg-00051q-SP for qemu-devel@nongnu.org; Fri, 22 Aug 2014 14:27:31 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20140821175235.12061.22630.stgit@fimbulvetr.bsc.es> <20140822131802.GA14126@stefanha-thinkpad.redhat.com> Date: Fri, 22 Aug 2014 20:27:27 +0200 In-Reply-To: <20140822131802.GA14126@stefanha-thinkpad.redhat.com> (Stefan Hajnoczi's message of "Fri, 22 Aug 2014 14:18:02 +0100") Message-ID: <87mwawl6r4.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3] trace: [qmp] Add QAPI/QMP commands to query and control event tracing state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Michael Roth , Markus Armbruster , qemu-devel@nongnu.org, Luiz Capitulino Stefan Hajnoczi writes: > On Thu, Aug 21, 2014 at 07:52:37PM +0200, Llu=C3=ADs Vilanova wrote: >> Also removes old "trace-event", "trace-file" and "info trace-events" HMP >> commands. > Is this commit description correct? I think we don't want to remove > HMP commands. It is "legacy" but users may still rely on HMP. It's > certainly used for ad-hoc debugging. The description is a leftover from a previous version. >> diff --git a/monitor.c b/monitor.c >> index cdbaa60..0f605f5 100644 >> --- a/monitor.c >> +++ b/monitor.c >> @@ -887,19 +887,8 @@ static void do_trace_event_set_state(Monitor *mon, = const QDict *qdict) >> const char *tp_name =3D qdict_get_str(qdict, "name"); >> bool new_state =3D qdict_get_bool(qdict, "option"); >>=20 >> - bool found =3D false; >> - TraceEvent *ev =3D NULL; >> - while ((ev =3D trace_event_pattern(tp_name, ev)) !=3D NULL) { >> - found =3D true; >> - if (!trace_event_get_state_static(ev)) { >> - monitor_printf(mon, "event \"%s\" is not traceable\n", tp_n= ame); >> - } else { >> - trace_event_set_state_dynamic(ev, new_state); >> - } >> - } >> - if (!trace_event_is_pattern(tp_name) && !found) { >> - monitor_printf(mon, "unknown event name \"%s\"\n", tp_name); >> - } >> + /* TODO: should propagate QMP errors to HMP */ >> + qmp_trace_event_set_state(tp_name, new_state, true, true, NULL); > The TODO can be resolved with: > if (errp) { > monitor_printf(mon, "%s", error_get_pretty(errp)); > error_free(errp); > } Thanks. >> +TraceEventStateList *qmp_trace_event_get_state(const char *name, Error = **errp) >> +{ >> + TraceEventStateList dummy =3D {}; >> + TraceEventStateList *prev =3D &dummy; >> + >> + bool found =3D false; >> + TraceEvent *ev =3D NULL; >> + while ((ev =3D trace_event_pattern(name, ev)) !=3D NULL) { >> + found =3D true; >> + TraceEventStateList *elem =3D g_malloc0(sizeof(*elem)); >> + elem->value =3D g_malloc0(sizeof(*elem->value)); >> + elem->value->name =3D g_strdup(trace_event_get_name(ev)); >> + elem->value->sstatic =3D trace_event_get_state_static(ev); >> + elem->value->sdynamic =3D trace_event_get_state_dynamic(ev); >> + prev->next =3D elem; >> + prev =3D elem; >> + } >> + if (!found && !trace_event_is_pattern(name)) { >> + error_setg(errp, "unknown event \"%s\"\n", name); > \n is not needed in error_setg() message. Please remove it. > There are more instances below. Ok. >> + } >> + >> + return dummy.next; >> +} >> + >> +void qmp_trace_event_set_state(const char *name, bool state, bool has_k= eepgoing, >> + bool keepgoing, Error **errp) >> +{ >> + bool error =3D false; >> + bool found =3D false; >> + TraceEvent *ev =3D NULL; >> + >> + /* Check all selected events are dynamic */ >> + while ((ev =3D trace_event_pattern(name, ev)) !=3D NULL) { >> + found =3D true; >> + if (!trace_event_get_state_static(ev)) { >> + error_setg(errp, "cannot set dynamic tracing state for \"%s= \"\n", >> + trace_event_get_name(ev)); > error_setg() can only be called once. Calling it with non-NULL errp > produces an assertion failure. > Maybe this approach can be used instead: > while ((ev =3D trace_event_pattern(name, ev)) !=3D NULL) { > found =3D true; > if (!(has_keepgoing && keepgoing) && > !trace_event_get_state_static(ev)) { > error_setg(errp, "cannot set dynamic tracing state for \"%s\"", > trace_event_get_name(ev)); > return; > } > } > The bool error variable can be dropped. Ok. >> + if (!(has_keepgoing && keepgoing)) { >> + error =3D true; >> + } >> + break; >> + } >> + } >> + if (error) { >> + return; >> + } >> + if (!found && !trace_event_is_pattern(name)) { >> + error_setg(errp, "unknown event \"%s\"\n", name); >> + return; >> + } >> + >> + if (error) { >> + return; >> + } > This condition has already been checked above. This if statement can be > dropped. Copy/paste is the root of many evils... Thanks, Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth