From: Eric Blake <eblake@redhat.com>
To: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>,
qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, armbru@redhat.com, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] Rolling statistics utilities
Date: Fri, 27 Feb 2015 13:53:37 -0700 [thread overview]
Message-ID: <54F0D951.3010601@redhat.com> (raw)
In-Reply-To: <1425064012-23155-2-git-send-email-dgilbert@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2534 bytes --]
On 02/27/2015 12:06 PM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> There are various places where it's useful to hold a series
> of values that change over time and get summaries about them.
>
> This provides:
>
> - 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
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> include/qemu/rolling-stats.h | 101 +++++++++++
> +
> +/**
> + * Return a string representing the RStats data, intended for JSON parsing
> + *
> + * 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.56,
> + * "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 = 60 /* for text */ +
> + /* 4 double values (min/max/mean/weighted) + the stored
> + * values, plus a normal guess for the size of them printed
> + * with %g and some padding. I'm not sure of the worst case.
> + */
> + (4 + r->allocated) * 13 +
> + /* and the count and tags as 64bit ints and some padding */
> + (1 + r->allocated) * 23;
> + space_left = space - 1;
> +
> + result = g_try_malloc(space);
> +
> + if (!result) {
> + qemu_mutex_unlock(&r->mutex);
> + return NULL;
> + }
> +
> + current = result;
> + tmp = snprintf(current, space_left, "Min/Max: %.8g, %.8g Mean: %.8g "
> + "(Weighted: %.8g) Count: %" PRIu64
> + " 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-02-27 20:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-27 19:06 [Qemu-devel] [PATCH 0/2] RFC: Rolling statistics Dr. David Alan Gilbert (git)
2015-02-27 19:06 ` [Qemu-devel] [PATCH 1/2] Rolling statistics utilities Dr. David Alan Gilbert (git)
2015-02-27 20:53 ` Eric Blake [this message]
2015-03-02 10:00 ` Dr. David Alan Gilbert
2015-02-27 19:06 ` [Qemu-devel] [PATCH 2/2] Tests for rolling statistics code Dr. David Alan Gilbert (git)
2015-03-02 9:50 ` [Qemu-devel] [PATCH 0/2] RFC: Rolling statistics Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54F0D951.3010601@redhat.com \
--to=eblake@redhat.com \
--cc=amit.shah@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).