Received: from eggs.gnu.org ([208.118.235.92]:36483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Se8Hy-00006b-8o for qemu-devel@nongnu.org; Mon, 11 Jun 2012 13:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Se8Hw-0006DV-5m for qemu-devel@nongnu.org; Mon, 11 Jun 2012 13:20:25 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:50730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Se8Hv-0006Cj-Qi for qemu-devel@nongnu.org; Mon, 11 Jun 2012 13:20:24 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20120508143813.18271.15731.stgit@fimbulvetr.bsc.es> <20120508143837.18271.22124.stgit@fimbulvetr.bsc.es> <87liju5gg0.fsf@fimbulvetr.bsc.es> Date: Mon, 11 Jun 2012 20:20:17 +0300 In-Reply-To: <87liju5gg0.fsf@fimbulvetr.bsc.es> (=?utf-8?Q?=22Llu=C3=ADs?= Vilanova"'s message of "Mon, 11 Jun 2012 12:46:39 +0300") Message-ID: <87ipexu5ny.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 v4 4/7] trace: [monitor] Use new event control interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org Llu=C3=ADs Vilanova writes: > Stefan Hajnoczi writes: >> On Tue, May 8, 2012 at 3:38 PM, Llu=C3=ADs Vilanova wrote: >>> Signed-off-by: Llu=C3=ADs Vilanova >>> --- >>> =C2=A0monitor.c | =C2=A0 15 ++++++++++++--- >>> =C2=A01 file changed, 12 insertions(+), 3 deletions(-) >>>=20 >>> diff --git a/monitor.c b/monitor.c >>> index 8946a10..86c2538 100644 >>> --- a/monitor.c >>> +++ b/monitor.c >>> @@ -625,10 +625,19 @@ static void do_trace_event_set_state(Monitor *mon= , const QDict *qdict) >>> =C2=A0{ >>> =C2=A0 =C2=A0 const char *tp_name =3D qdict_get_str(qdict, "name"); >>> =C2=A0 =C2=A0 bool new_state =3D qdict_get_bool(qdict, "option"); >>> - =C2=A0 =C2=A0int ret =3D trace_event_set_state(tp_name, new_state); >>>=20 >>> - =C2=A0 =C2=A0if (!ret) { >>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0monitor_printf(mon, "unknown event name \"= %s\"\n", tp_name); >>> + =C2=A0 =C2=A0if (trace_event_is_pattern(tp_name)) { >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0TraceEvent *ev =3D NULL; >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0while ((ev =3D trace_event_pattern(tp_name= , ev)) !=3D NULL) { >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0trace_event_set_state_dynami= c(ev, new_state); >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>> + =C2=A0 =C2=A0} else { >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0TraceEvent *ev =3D trace_event_name(tp_nam= e); >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ev =3D=3D NULL) { >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0monitor_printf(mon, "unknown= event name \"%s\"\n", tp_name); >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0trace_event_set_state_dynami= c(ev, new_state); >>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> Why check for a pattern and split the code in two? How about just: >> while ((ev =3D trace_event_pattern(tp_name, ev)) !=3D NULL) { >> ... >> } >> That should cover both the single trace event name case and the wildcard= case. > That's true... it's just that somehow I thought it was abusive to use pat= tern > matching on a string without patterns :) When going through the code to add your comments I realized why it made sen= se to use 'trace_event_name' instead of 'trace_event_pattern'. In the case the string contains no pattern, not finding a result is an erro= r in 'trace_backend_init_events' (when reading the list of events given in the commandline file), as well as in 'do_trace_event_set_state' (when setting t= he state from the monitor, although here the error is not fatal). In comparison, setting by pattern never fails. 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