From: Anthony Liguori <anthony@codemonkey.ws>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] Optimize screendump
Date: Wed, 22 Jun 2011 07:58:19 -0500 [thread overview]
Message-ID: <4E01E6EB.2000801@codemonkey.ws> (raw)
In-Reply-To: <1308557567-27600-1-git-send-email-avi@redhat.com>
On 06/20/2011 03:12 AM, Avi Kivity wrote:
> When running kvm-autotest, fputc() is often the second highest (sometimes #1)
> function showing up in a profile. This is due to fputc() locking the file
> for every byte written.
>
> Optimize by buffering a line's worth of pixels and writing that out in a
> single call.
>
> Signed-off-by: Avi Kivity<avi@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
>
> v2: drop unportable fputc_unlocked
>
> hw/vga.c | 13 ++++++++++---
> 1 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/hw/vga.c b/hw/vga.c
> index d5bc582..97c96bf 100644
> --- a/hw/vga.c
> +++ b/hw/vga.c
> @@ -2349,15 +2349,19 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
> uint32_t v;
> int y, x;
> uint8_t r, g, b;
> + int ret;
> + char *linebuf, *pbuf;
>
> f = fopen(filename, "wb");
> if (!f)
> return -1;
> fprintf(f, "P6\n%d %d\n%d\n",
> ds->width, ds->height, 255);
> + linebuf = qemu_malloc(ds->width * 3);
> d1 = ds->data;
> for(y = 0; y< ds->height; y++) {
> d = d1;
> + pbuf = linebuf;
> for(x = 0; x< ds->width; x++) {
> if (ds->pf.bits_per_pixel == 32)
> v = *(uint32_t *)d;
> @@ -2369,13 +2373,16 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
> (ds->pf.gmax + 1);
> b = ((v>> ds->pf.bshift)& ds->pf.bmax) * 256 /
> (ds->pf.bmax + 1);
> - fputc(r, f);
> - fputc(g, f);
> - fputc(b, f);
> + *pbuf++ = r;
> + *pbuf++ = g;
> + *pbuf++ = b;
> d += ds->pf.bytes_per_pixel;
> }
> d1 += ds->linesize;
> + ret = fwrite(linebuf, 1, pbuf - linebuf, f);
> + (void)ret;
> }
> + qemu_free(linebuf);
> fclose(f);
> return 0;
> }
prev parent reply other threads:[~2011-06-22 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 8:12 [Qemu-devel] [PATCH v2] Optimize screendump Avi Kivity
2011-06-20 12:33 ` Jan Kiszka
2011-06-20 13:11 ` Avi Kivity
2011-06-22 21:22 ` Andreas Färber
2011-06-26 17:52 ` Blue Swirl
2011-06-20 15:39 ` Stefan Hajnoczi
2011-06-22 12:58 ` Anthony Liguori [this message]
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=4E01E6EB.2000801@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).