From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYZbK-0008C2-7a for qemu-devel@nongnu.org; Mon, 20 Jun 2011 04:12:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QYZbI-0006Df-J0 for qemu-devel@nongnu.org; Mon, 20 Jun 2011 04:12:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYZbI-0006DQ-04 for qemu-devel@nongnu.org; Mon, 20 Jun 2011 04:12:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5K8Cp7Q004987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 20 Jun 2011 04:12:51 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5K8Com2019669 for ; Mon, 20 Jun 2011 04:12:50 -0400 From: Avi Kivity Date: Mon, 20 Jun 2011 11:12:47 +0300 Message-Id: <1308557567-27600-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH v2] Optimize screendump List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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; } -- 1.7.5.3