Ejemplo n.º 1
0
    def dataReceived(self, data):
        pyprofile.incr('vnc_proxy_server.data.sent.messages')
        pyprofile.incr('vnc_proxy_server.data.sent.bytes', len(data))

        self.buf.append(data)
        self.buf_len += len(data)
        self.flush()
Ejemplo n.º 2
0
    def __call__(self, img, available_at):
        # Choose the return value
        if len(self.deque) > 0 and self.deque[0].ready():
            last = self.deque.popleft()
            res = last.get()
            if res is not None:
                pyprofile.timing('vnc_env.diagnostics.async_decode.latency',
                                 time.time() - res['available_at'])
        else:
            res = False

        pyprofile.gauge('vnc_env.diagnostics.async_decode.queue_depth',
                        len(self.deque))

        # Just grayscale it by keeping only one component. Should be
        # good enough as this region is black and white anyway.
        grayscale = img[self.y:self.y + self.height,
                        self.x:self.x + self.width, 0]

        # Apply processing if needed
        match = np.array_equal(self._last_img, grayscale)
        if not match:
            pyprofile.incr('vnc_env.diagnostics.async_decode.schedule')
            # sneakily copy if numpy hasn't, so it can be cached
            self._last_img = np.ascontiguousarray(grayscale)
            async = self.qr_pool.apply_async(
                self.method, (self._last_img, time.time(), available_at))
            self.deque.append(async)
        else:
            pyprofile.incr('vnc_env.diagnostics.async_decode.cache_hit')

        return res
Ejemplo n.º 3
0
    def send_env_reward(self, reward, done, info, episode_id):
        pyprofile.incr('agent_conn.reward', reward)
        if done:
            pyprofile.incr('agent_conn.done')

        reactor.callFromThread(self._send_env_reward, reward, done, info,
                               episode_id)
Ejemplo n.º 4
0
 def sendMessage(self, data):
     pyprofile.incr('vnc_client.data.sent.messages')
     pyprofile.incr('vnc_client.data.sent.bytes',
                    len(data),
                    unit=pyprofile.BYTES)
     if self.transport:
         self.transport.write(data)
Ejemplo n.º 5
0
 def recv_DecodeZlib_value(self, block, x, y, width, height):
     pyprofile.incr('vncdriver.recv_rectangle.zlib_encoding.bytes',
                    len(block),
                    unit=pyprofile.BYTES)
     rectangle = server_messages.ZlibEncoding.parse_rectangle(
         self, x, y, width, height, block)
     self._rectangles.append(rectangle)
     self._process_rectangles()
Ejemplo n.º 6
0
    def recv_DecodeZlib(self, block, x, y, width, height):
        pyprofile.incr('vncdriver.recv_rectangle.zlib_encoding')
        pyprofile.incr('vncdriver.recv_rectangle.zlib_encoding.bytes',
                       len(block),
                       unit=pyprofile.BYTES)

        (length, ) = struct.unpack('!I', block)
        self.expect(self.recv_DecodeZlib_value, length, x, y, width, height)
Ejemplo n.º 7
0
    def recv_FramebufferUpdate(self, block):
        (number_of_rectangles, ) = struct.unpack('!xH', block)
        logger.debug('Receiving %d rectangles', number_of_rectangles)
        pyprofile.incr('vncdriver.framebuffer_update')
        pyprofile.incr('vncdriver.framebuffer_update.number_of_rectangles',
                       number_of_rectangles)
        self._remaining_rectangles = number_of_rectangles
        self._rectangles = []

        self._process_rectangles()
Ejemplo n.º 8
0
    def dataReceived(self, data):
        if self.expected is None:
            # We're in direct proxy mode
            self.proxyData(data)
            return

        pyprofile.incr('vnc_proxy_server.data.sent.messages')
        pyprofile.incr('vnc_proxy_server.data.sent.bytes', len(data))

        self.buf.append(data)
        self.buf_len += len(data)
        self.flush()
Ejemplo n.º 9
0
 def parse_rectangle(cls, client, x, y, width, height, data):
     decompressed = client.zlib_decompressor.decompress(data)
     logger.debug('[zlib] Decompressed from %s bytes -> %s bytes',
                  len(data), len(decompressed))
     pyprofile.incr(
         'vncdriver.recv_rectangle.zlib_encoding.decompressed_bytes',
         len(decompressed),
         unit=pyprofile.BYTES)
     data = np.frombuffer(decompressed, np.uint8).reshape(
         (height, width, 4))[:, :, [0, 1, 2]]
     encoding = cls(data)
     return Rectangle(x, y, width, height, encoding)
Ejemplo n.º 10
0
    def dataReceived(self, data):
        pyprofile.incr('vnc_client.data.received.messages')
        pyprofile.incr('vnc_client.data.received.bytes',
                       len(data),
                       unit=pyprofile.BYTES)

        self.buf.append(data)
        self.buf_len += len(data)
        logger.debug('Received data: %s bytes (brings us to %s total)',
                     len(data), self.buf_len)

        self.flush()
Ejemplo n.º 11
0
 def update_rectangle(self, x, y, width, height, data):
     bytes = data.tobytes()
     pyprofile.incr('vncdriver.pyglet_screen.blit')
     pyprofile.incr('vncdriver.pyglet_screen.blit.bytes',
                    len(bytes),
                    unit=pyprofile.BYTES)
     import pyglet
     image = pyglet.image.ImageData(width,
                                    height,
                                    'RGB',
                                    bytes,
                                    pitch=width * -3)
     self.texture.blit_into(image, x, self._height - height - y, 0)
     self._is_updated = True
Ejemplo n.º 12
0
    def parse_rectangle(cls, client, x, y, width, height, data):
        decompressed = client.zlib_decompressor.decompress(data)
        logger.debug('[zrle] Decompressed from %s bytes -> %s bytes',
                     len(data), len(decompressed))
        pyprofile.incr(
            'vncdriver.recv_rectangle.zrle_encoding.decompressed_bytes',
            len(decompressed),
            unit=pyprofile.BYTES)

        if client.framebuffer.bpp > 24:
            bytes_per_pixel = 3
        else:
            bytes_per_pixel = client.framebuffer.bypp

        buf = BytesIO(decompressed)
        data = cls._read(x, y, width, height, buf, bytes_per_pixel)
        encoding = cls(data)
        return Rectangle(x, y, width, height, encoding)
Ejemplo n.º 13
0
    def onMessage(self, payload, isBinary):
        if not self.factory.agent_conn.check_message(self):
            return

        assert not isBinary, "Binary websocket not supported"
        payload = ujson.loads(payload)

        context = {
            'start': time.time(),
            'conn': self,
        }
        latency = context['start'] - payload['headers']['sent_at']
        pyprofile.incr('rewarder_protocol.messages')
        pyprofile.incr('rewarder_protocol.messages.{}'.format(
            payload['method']))

        pyprofile.timing('rewarder_protocol.latency.rtt.skew_unadjusted',
                         2 * latency)
        if latency < 0:
            pyprofile.incr(
                'rewarder_protocol.latency.rtt.skew_unadjusted.negative')

        if payload['method'] == 'v0.env.reset':
            logger.info('Received reset message: %s', payload)
            self.factory.agent_conn.control_buffer.recv_rpc(context, payload)
        elif payload['method'] == 'v0.control.ping':
            logger.debug('Received ping message: %s', payload)
            parent_message_id = payload['headers']['message_id']
            headers = {'parent_message_id': parent_message_id}
            self.send_message('v0.reply.control.ping', {}, headers)
        else:
            logger.warn('Received unsupported message: %s', payload)