xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #67: xpra-mmap-zerocopy.patch

File xpra-mmap-zerocopy.patch, 2.7 KB (added by Antoine Martin, 10 years ago)

patch for measuring the improvement using zerocopy

  • xpra/client.py

     
    201201
    202202    def draw(self, x, y, width, height, coding, img_data, rowstride):
    203203        gc = self._backing.new_gc()
     204        log.info("draw(%s,%s,%s,%s,%s,...)", x, y, width, height, coding)
    204205        if coding == "mmap":
    205206            assert self._client.supports_mmap
    206207            log("drawing from mmap: %s", img_data)
    207             data = ""
    208208            import ctypes
    209209            data_start = ctypes.c_uint.from_buffer(self._client.mmap, 0)
    210             for offset, length in img_data:
    211                 self._client.mmap.seek(offset)
    212                 data += self._client.mmap.read(length)
     210            if len(img_data)==1:
     211                #construct an array directly from the mmap zone:
     212                ts = time.time()
     213                start = time.time()
     214                offset, length = img_data[0]
     215                arraytype = ctypes.c_char * length
     216                data = arraytype.from_buffer(self._client.mmap, offset)
     217                end = time.time()
     218                log.info("drawing directly from mmap, array took=%s", int(100000*(end-start))/100.0)
     219                start = time.time()
     220                self._backing.draw_rgb_image(gc, x, y, width, height, gtk.gdk.RGB_DITHER_NONE, data, rowstride)
     221                end = time.time()
     222                ps = int(length/(end-ts)/1024/1024)
     223                log.info("actual drawing took=%s", int(100000*(end-start))/100.0)
     224                log.info("Mpixels/s=%s", ps)
    213225                data_start.value = offset+length
    214             self._backing.draw_rgb_image(gc, x, y, width, height, gtk.gdk.RGB_DITHER_NONE, data, rowstride)
     226            else:
     227                ts = time.time()
     228                start = time.time()
     229                data = ""
     230                pixels = 0
     231                for offset, length in img_data:
     232                    self._client.mmap.seek(offset)
     233                    data += self._client.mmap.read(length)
     234                    data_start.value = offset+length
     235                    pixels += length
     236                end = time.time()
     237                log.info("drawing from mmap group: %s, took=%s", img_data, int(100000*(end-start))/100.0)
     238                start = time.time()
     239                self._backing.draw_rgb_image(gc, x, y, width, height, gtk.gdk.RGB_DITHER_NONE, data, rowstride)
     240                end = time.time()
     241                ps = int(pixels/(end-ts)/1024/1024)
     242                log.info("actual drawing took=%s", int(100000*(end-start))/100.0)
     243                log.info("Mpixels/s=%s", ps)
    215244        elif coding == "rgb24":
    216245            if rowstride>0:
    217246                assert len(img_data) == rowstride * height