qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] Optimize screendump


From: Jan Kiszka
Subject: Re: [Qemu-devel] [PATCH v2] Optimize screendump
Date: Mon, 20 Jun 2011 14:33:23 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

On 2011-06-20 10:12, 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 <address@hidden>
> ---
> 
> 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;
>  }

Unrelated to this patch, but why is this function located in vga.c and
not in console.c?

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



reply via email to

[Prev in Thread] Current Thread [Next in Thread]