From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRRur-0000iB-RX for qemu-devel@nongnu.org; Fri, 27 Feb 2015 15:53:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRRum-00060E-DX for qemu-devel@nongnu.org; Fri, 27 Feb 2015 15:53:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRRum-000606-66 for qemu-devel@nongnu.org; Fri, 27 Feb 2015 15:53:40 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1RKrdW3006605 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 27 Feb 2015 15:53:39 -0500 Message-ID: <54F0D951.3010601@redhat.com> Date: Fri, 27 Feb 2015 13:53:37 -0700 From: Eric Blake MIME-Version: 1.0 References: <1425064012-23155-1-git-send-email-dgilbert@redhat.com> <1425064012-23155-2-git-send-email-dgilbert@redhat.com> In-Reply-To: <1425064012-23155-2-git-send-email-dgilbert@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PAAEo5GQx3pxKoEDT3Jn5QOPQcc8IrSIO" Subject: Re: [Qemu-devel] [PATCH 1/2] Rolling statistics utilities List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" , qemu-devel@nongnu.org Cc: amit.shah@redhat.com, armbru@redhat.com, quintela@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PAAEo5GQx3pxKoEDT3Jn5QOPQcc8IrSIO Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/27/2015 12:06 PM, Dr. David Alan Gilbert (git) wrote: > From: "Dr. David Alan Gilbert" >=20 > There are various places where it's useful to hold a series > of values that change over time and get summaries about them. >=20 > This provides: >=20 > - a count of the number of items > - min/max > - mean > - a weighted mean (where you can set the weight to determine > whether it changes quickly or slowly) > - the last 'n' values >=20 > Signed-off-by: Dr. David Alan Gilbert > --- > include/qemu/rolling-stats.h | 101 +++++++++++ > + > +/** > + * Return a string representing the RStats data, intended for JSON par= sing > + * > + * Returns: An allocated string the caller must free > + * or NULL on error > + * > + * e.g. > + * { "min": -3.57, "max": 126.3, "mean": 7.83, "weighted_mean": 8.5= 6, > + * "count": 5678, > + * "values": [ 4.3, 5.8, 1.2, 7.9, 10.3 ], > + * "tags": [ 458, 783, 950, 951, 952 ] } Looks useful at first glance. Maybe s/weighted_mean/weighted-mean/ since we favor - in new QMP. > + > + qemu_mutex_lock(&r->mutex); > + space =3D 60 /* for text */ + > + /* 4 double values (min/max/mean/weighted) + the stored > + * values, plus a normal guess for the size of them print= ed > + * with %g and some padding. I'm not sure of the worst c= ase. > + */ > + (4 + r->allocated) * 13 + > + /* and the count and tags as 64bit ints and some padding = */ > + (1 + r->allocated) * 23; > + space_left =3D space - 1; > + > + result =3D g_try_malloc(space); > + > + if (!result) { > + qemu_mutex_unlock(&r->mutex); > + return NULL; > + } > + > + current =3D result; > + tmp =3D snprintf(current, space_left, "Min/Max: %.8g, %.8g Mean: %= =2E8g " > + "(Weighted: %.8g) Count: %" PR= Iu64 > + " Values: ", Eww. Why pre-compute things for a possibly not-wide-enough snprintf, when you can instead use glib's g_string_printf that allocates the perfect size as it goes? For that matter, your cover letter comment about putting the struct in QAPI and letting the generated visitor automatically produce the JSON might make this simpler than building it by hand. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --PAAEo5GQx3pxKoEDT3Jn5QOPQcc8IrSIO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJU8NlRAAoJEKeha0olJ0Nqc+UIAJhdL//GZ/Buxs0Tpczvyba9 VPqVf/DuCrMQIsdhCCr2A6U6GkSbQSdTaQ4uTNaXMGx+HdwgOYjWD2urZTyjSrFx IlMeD+R7pM5qzcm5AhfNKOTaRxKqZ/6MM2wGc382e9T/AmEmxGDTH+8DXM+irCb1 L99tSpOsH/9bB5PrmPWPDx8vbSGJsyo5VBKItW9g4PJrOKXd2XpwR+m2+HvJtceO NGef6ozkocpnVD853lXMxLbDHdMvDa1uj1XBq3Lgk0KzNRpCanTXu8qPsQ1pqgiE +p9YWX2f2ZQCjGshMi4v4jR4gb1Km9f4ZGr2y50EB0WlvRp/4aATZz52DLbivu0= =cSLd -----END PGP SIGNATURE----- --PAAEo5GQx3pxKoEDT3Jn5QOPQcc8IrSIO--