Received: from eggs.gnu.org ([208.118.235.92]:44532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Se1D1-000808-P6 for qemu-devel@nongnu.org; Mon, 11 Jun 2012 05:46:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Se1Cw-0007LM-UN for qemu-devel@nongnu.org; Mon, 11 Jun 2012 05:46:51 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:41818 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Se1Cw-0007Kk-J9 for qemu-devel@nongnu.org; Mon, 11 Jun 2012 05:46:46 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20120508143813.18271.15731.stgit@fimbulvetr.bsc.es> <20120508143837.18271.22124.stgit@fimbulvetr.bsc.es> Date: Mon, 11 Jun 2012 12:46:39 +0300 In-Reply-To: (Stefan Hajnoczi's message of "Mon, 11 Jun 2012 10:35:07 +0100") Message-ID: <87liju5gg0.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 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_dynamic= (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_name= ); >> + =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_dynamic= (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 patte= rn matching on a string without patterns :) 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