qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 3/3] virtio-serial-bus: Add per-port stats for recei


From: Amit Shah
Subject: [Qemu-devel] [PATCH 3/3] virtio-serial-bus: Add per-port stats for received, sent, discarded bytes
Date: Wed, 14 Sep 2011 12:59:07 +0530

This commit adds port-specific stats for the number of bytes received,
sent and discarded.  They can be seen in the 'info qtree' monitor output
for the specific port.

This data can be used to check for data loss bugs (or disprove such
claims). It can also be used for accounting, if there's such a need.

The stats remain valid throughout the lifetime of the port. Unplugging a
port will reset the stats.  The numbers are not reset across port
opens/closes.

Signed-off-by: Amit Shah <address@hidden>
---
 hw/virtio-serial-bus.c |   24 ++++++++++++++++++++++--
 hw/virtio-serial.h     |   11 +++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 2c84398..deefda4 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -108,6 +108,7 @@ static size_t write_to_port(VirtIOSerialPort *port,
         offset += len;
 
         virtqueue_push(vq, &elem, len);
+        port->stats.bytes_sent += len;
     }
 
     virtio_notify(&port->vser->vdev, vq);
@@ -123,10 +124,24 @@ static void discard_vq_data(VirtIOSerialPort *port, 
VirtQueue *vq,
         return;
     }
     if (port && port->elem.out_num) {
+        port->stats.bytes_discarded += (iov_size(port->elem.out_sg,
+                                                 elem.out_num)
+                                        - iov_size(port->elem.out_sg,
+                                                   port->iov_idx)
+                                        - port->iov_offset);
         virtqueue_push(vq, &port->elem, 0);
         port->elem.out_num = 0;
     }
     while (virtqueue_pop(vq, &elem)) {
+        if (port) {
+            unsigned long size;
+
+            size = iov_size(elem.out_sg, elem.out_num);
+
+            /* We haven't counted these bytes in the received stats yet. */
+            port->stats.bytes_received += size;
+            port->stats.bytes_discarded += size;
+        }
         virtqueue_push(vq, &elem, 0);
     }
     virtio_notify(vdev, vq);
@@ -152,6 +167,8 @@ static void do_flush_queued_data(VirtIOSerialPort *port, 
VirtQueue *vq,
             }
             port->iov_idx = 0;
             port->iov_offset = 0;
+            port->stats.bytes_received += iov_size(port->elem.out_sg,
+                                                   port->elem.out_num);
         }
 
         for (i = port->iov_idx; i < port->elem.out_num; i++) {
@@ -684,11 +701,14 @@ static void virtser_bus_dev_print(Monitor *mon, 
DeviceState *qdev, int indent)
 {
     VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
 
-    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n",
+    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s, 
bytes_sent %lu, bytes_received %lu, bytes_discarded: %lu\n",
                    indent, "", port->id,
                    port->guest_connected ? "on" : "off",
                    port->host_connected ? "on" : "off",
-                   port->throttled ? "on" : "off");
+                   port->throttled ? "on" : "off",
+                   port->stats.bytes_sent,
+                   port->stats.bytes_received,
+                   port->stats.bytes_discarded);
 }
 
 /* This function is only used if a port id is not provided by the user */
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index ab13803..34d36d7 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -67,6 +67,10 @@ typedef struct VirtIOSerialBus VirtIOSerialBus;
 typedef struct VirtIOSerialPort VirtIOSerialPort;
 typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
 
+typedef struct {
+    unsigned long bytes_sent, bytes_received, bytes_discarded;
+} PortStats;
+
 /*
  * This is the state that's shared between all the ports.  Some of the
  * state is configurable via command-line options. Some of it can be
@@ -87,6 +91,13 @@ struct VirtIOSerialPort {
     VirtQueue *ivq, *ovq;
 
     /*
+     * Keep count of the bytes sent, received and discarded for
+     * this port for accounting and debugging purposes.  These
+     * counts are not reset across port open / close events.
+     */
+    PortStats stats;
+
+    /*
      * This name is sent to the guest and exported via sysfs.
      * The guest could create symlinks based on this information.
      * The name is in the reverse fqdn format, like org.qemu.console.0
-- 
1.7.6




reply via email to

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