From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: amit.shah@redhat.com, quintela@redhat.com, qemu-devel@nongnu.org,
armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] Rolling statistics utilities
Date: Mon, 2 Mar 2015 10:00:35 +0000 [thread overview]
Message-ID: <20150302100035.GC2292@work-vm> (raw)
In-Reply-To: <54F0D951.3010601@redhat.com>
* Eric Blake (eblake@redhat.com) wrote:
> 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?
Ah, because I didn't know about that; useful.
> 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.
Right; I'd got this far, tried to glue it into the 'info' commands
and realised it needed to return soemthing more QAPI friendly;
but thought it best to see if people liked the general idea before attacking
that.
I'm not sure; but I think the approach would be to have a QAPI
type to hold the same data (Lets say a RollingStats type)
and then have a rstats_copy_to_rolling_stats function
that, under lock, copied the data out, that way the QAPI
type doesn't need to worry about the lock and neither does
anything outside this code.
Dave
>
> --
> Eric Blake eblake redhat com +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2015-03-02 10:00 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
2015-03-02 10:00 ` Dr. David Alan Gilbert [this message]
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=20150302100035.GC2292@work-vm \
--to=dgilbert@redhat.com \
--cc=amit.shah@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@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).