[Spice-devel] [PATCH v2 spice 11/11] server/red_worker.c: add stream stats for debugging

Yonit Halperin yhalperi at redhat.com
Tue Apr 17 03:12:36 PDT 2012


---
 server/red_worker.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index 6c86ba8..b55860b 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -80,6 +80,7 @@
 #include "main_channel.h"
 #include "spice_timer_queue.h"
 
+//#define STREAM_STATS
 //#define COMPRESS_STAT
 //#define DUMP_BITMAP
 //#define PIPE_DEBUG
@@ -403,6 +404,15 @@ typedef struct StreamAgent {
     uint64_t last_send_time;
     MJpegEncoder *mjpeg_encoder;
     DisplayChannelClient *dcc;
+
+#ifdef STREAM_STATS
+   uint64_t num_drops_pipe;
+   uint64_t num_drops_fps;
+   uint64_t total_frames_sent;
+   uint64_t start_mm_time;
+   uint64_t end_mm_time;
+   uint64_t size_sent;
+#endif
 } StreamAgent;
 
 typedef struct StreamClipItem {
@@ -2519,6 +2529,22 @@ static void red_stop_stream(RedWorker *worker, Stream *stream)
         StreamAgent *stream_agent;
 
         stream_agent = &dcc->stream_agents[stream - worker->streams_buf];
+#ifdef STREAM_STATS
+        if (1) {
+            float passed_mm_time = (stream_agent->end_mm_time - stream_agent->start_mm_time) / 1000.0;
+            spice_debug("stream %ld (%dx%d): frames %lu, drops %lu (pipe %lu, fps %lu), last_fps %d, avg_fps %.2f,"
+                       "passed mm %.2f (sec), size %.2f (KB) %.2f (Mbps) %.2f (KBpf)",
+                       stream_agent - dcc->stream_agents, stream->width, stream->height,
+                       stream_agent->total_frames_sent, stream_agent->num_drops_pipe + stream_agent->num_drops_fps,
+                       stream_agent->num_drops_pipe, stream_agent->num_drops_fps,
+                       mjpeg_encoder_get_fps(stream_agent->mjpeg_encoder),
+                       stream_agent->total_frames_sent / passed_mm_time,
+                       passed_mm_time,
+                       stream_agent->size_sent / 1000.0,
+                       ((stream_agent->size_sent * 8.0) / (1000.0 * 1000))  / passed_mm_time,
+                       stream_agent->size_sent / 1000.0 / stream_agent->total_frames_sent);
+        }
+#endif
         region_clear(&stream_agent->vis_region);
         if (stream_agent->mjpeg_encoder) {
             mjpeg_encoder_destroy(stream_agent->mjpeg_encoder);
@@ -2774,6 +2800,18 @@ static void red_display_create_stream(DisplayChannelClient *dcc, Stream *stream)
     mjpeg_cbs.get_bit_rate = red_stream_mjpeg_encoder_get_bit_rate;
     agent->mjpeg_encoder = mjpeg_encoder_new(&mjpeg_cbs, agent);
     agent->dcc = dcc;
+#ifdef STREAM_STATS
+    agent->total_frames_sent = 0;
+    agent->num_drops_pipe = 0;
+    agent->num_drops_fps = 0;
+    agent->end_mm_time = 0;
+    if (stream->current) {
+        agent->start_mm_time = stream->current->red_drawable->mm_time;
+    } else {
+        agent->start_mm_time = 0;
+    }
+    agent->size_sent = 0;
+#endif
     red_channel_client_pipe_add(&dcc->common.base, &agent->create_item);
 }
 
@@ -2987,6 +3025,9 @@ static inline void pre_stream_item_swap(RedWorker *worker, Stream *stream)
 
         if (pipe_item_is_linked(&dpi->dpi_pipe_item)) {
             mjpeg_encoder_notify_frame_drop(agent->mjpeg_encoder);
+#ifdef STREAM_STATS
+            agent->num_drops_pipe++;
+#endif
         }
     }
 }
@@ -8116,6 +8157,9 @@ static inline int red_marshall_stream_data(RedChannelClient *rcc,
 
     fps = mjpeg_encoder_get_fps(agent->mjpeg_encoder);
     if (time_now - agent->last_send_time < (1000 * 1000 * 1000) / fps) {
+#ifdef STREAM_STATS
+        agent->num_drops_fps++;
+#endif
         return TRUE;
     }
 
@@ -8165,6 +8209,11 @@ static inline int red_marshall_stream_data(RedChannelClient *rcc,
     spice_marshaller_add_ref(base_marshaller,
                              dcc->send_data.stream_outbuf, n);
     agent->last_send_time = time_now;
+#ifdef STREAM_STATS
+    agent->total_frames_sent++;
+    agent->size_sent += n;
+    agent->end_mm_time = drawable->red_drawable->mm_time;
+#endif
     return TRUE;
 }
 
-- 
1.7.7.6



More information about the Spice-devel mailing list