[Spice-devel] [PATCH 07/10] worker: move some compress stats to display

Frediano Ziglio fziglio at redhat.com
Thu Nov 5 05:23:10 PST 2015


From: Marc-André Lureau <marcandre.lureau at gmail.com>

---
 server/display-channel.c | 100 +++++++++++++++++++++++++++++++++++++++++++
 server/display-channel.h |   4 ++
 server/red_worker.c      | 108 ++---------------------------------------------
 3 files changed, 108 insertions(+), 104 deletions(-)

diff --git a/server/display-channel.c b/server/display-channel.c
index 3dc5a94..5deab13 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -16,6 +16,106 @@
 */
 #include "display-channel.h"
 
+void display_channel_compress_stats_reset(DisplayChannel *display_channel)
+{
+    spice_return_if_fail(display_channel);
+
+#ifdef COMPRESS_STAT
+    stat_reset(&worker->display_channel->quic_stat);
+    stat_reset(&worker->display_channel->lz_stat);
+    stat_reset(&worker->display_channel->glz_stat);
+    stat_reset(&worker->display_channel->jpeg_stat);
+    stat_reset(&worker->display_channel->zlib_glz_stat);
+    stat_reset(&worker->display_channel->jpeg_alpha_stat);
+    stat_reset(&worker->display_channel->lz4_stat);
+#endif
+}
+
+void display_channel_compress_stats_print(const DisplayChannel *display_channel)
+{
+    spice_return_if_fail(display_channel);
+
+#ifdef COMPRESS_STAT
+    uint64_t glz_enc_size;
+
+    glz_enc_size = display_channel->enable_zlib_glz_wrap ?
+                       display_channel->zlib_glz_stat.comp_size :
+                       display_channel->glz_stat.comp_size;
+
+    spice_info("==> Compression stats for display %u", display_channel->common.id);
+    spice_info("Method   \t  count  \torig_size(MB)\tenc_size(MB)\tenc_time(s)");
+    spice_info("QUIC     \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->quic_stat.count,
+               stat_byte_to_mega(display_channel->quic_stat.orig_size),
+               stat_byte_to_mega(display_channel->quic_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->quic_stat.total)
+               );
+    spice_info("GLZ      \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->glz_stat.count,
+               stat_byte_to_mega(display_channel->glz_stat.orig_size),
+               stat_byte_to_mega(display_channel->glz_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->glz_stat.total)
+               );
+    spice_info("ZLIB GLZ \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->zlib_glz_stat.count,
+               stat_byte_to_mega(display_channel->zlib_glz_stat.orig_size),
+               stat_byte_to_mega(display_channel->zlib_glz_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->zlib_glz_stat.total)
+               );
+    spice_info("LZ       \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->lz_stat.count,
+               stat_byte_to_mega(display_channel->lz_stat.orig_size),
+               stat_byte_to_mega(display_channel->lz_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->lz_stat.total)
+               );
+    spice_info("JPEG     \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->jpeg_stat.count,
+               stat_byte_to_mega(display_channel->jpeg_stat.orig_size),
+               stat_byte_to_mega(display_channel->jpeg_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->jpeg_stat.total)
+               );
+    spice_info("JPEG-RGBA\t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->jpeg_alpha_stat.count,
+               stat_byte_to_mega(display_channel->jpeg_alpha_stat.orig_size),
+               stat_byte_to_mega(display_channel->jpeg_alpha_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->jpeg_alpha_stat.total)
+               );
+    spice_info("LZ4      \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->lz4_stat.count,
+               stat_byte_to_mega(display_channel->lz4_stat.orig_size),
+               stat_byte_to_mega(display_channel->lz4_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->lz4_stat.total)
+               );
+    spice_info("-------------------------------------------------------------------");
+    spice_info("Total    \t%8d\t%13.2f\t%12.2f\t%12.2f",
+               display_channel->lz_stat.count + display_channel->glz_stat.count +
+                                                display_channel->quic_stat.count +
+                                                display_channel->jpeg_stat.count +
+                                                display_channel->lz4_stat.count +
+                                                display_channel->jpeg_alpha_stat.count,
+               stat_byte_to_mega(display_channel->lz_stat.orig_size +
+                                 display_channel->glz_stat.orig_size +
+                                 display_channel->quic_stat.orig_size +
+                                 display_channel->jpeg_stat.orig_size +
+                                 display_channel->lz4_stat.orig_size +
+                                 display_channel->jpeg_alpha_stat.orig_size),
+               stat_byte_to_mega(display_channel->lz_stat.comp_size +
+                                 glz_enc_size +
+                                 display_channel->quic_stat.comp_size +
+                                 display_channel->jpeg_stat.comp_size +
+                                 display_channel->lz4_stat.comp_size +
+                                 display_channel->jpeg_alpha_stat.comp_size),
+               stat_cpu_time_to_sec(display_channel->lz_stat.total +
+                                    display_channel->glz_stat.total +
+                                    display_channel->zlib_glz_stat.total +
+                                    display_channel->quic_stat.total +
+                                    display_channel->jpeg_stat.total +
+                                    display_channel->lz4_stat.total +
+                                    display_channel->jpeg_alpha_stat.total)
+               );
+#endif
+}
+
 DisplayChannelClient *dcc_new(DisplayChannel *display,
                               RedClient *client, RedsStream *stream,
                               int mig_target,
diff --git a/server/display-channel.h b/server/display-channel.h
index d6d65e0..2f9b33b 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -328,6 +328,7 @@ MonitorsConfig*            monitors_config_new                       (QXLHead *h
 MonitorsConfig *           monitors_config_ref                       (MonitorsConfig *config);
 void                       monitors_config_unref                     (MonitorsConfig *config);
 
+/* TODO: move to .c */
 struct DisplayChannel {
     CommonChannel common; // Must be the first thing
 
@@ -360,4 +361,7 @@ struct DisplayChannel {
 #endif
 };
 
+void                       display_channel_compress_stats_print      (const DisplayChannel *display);
+void                       display_channel_compress_stats_reset      (DisplayChannel *display);
+
 #endif /* DISPLAY_CHANNEL_H_ */
diff --git a/server/red_worker.c b/server/red_worker.c
index b7de808..2ec05f1 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -602,95 +602,6 @@ void drawable_pipe_item_unref(DrawablePipeItem *dpi)
     free(dpi);
 }
 
-
-#ifdef COMPRESS_STAT
-static void print_compress_stats(DisplayChannel *display_channel)
-{
-    uint64_t glz_enc_size;
-
-    if (!display_channel) {
-        return;
-    }
-
-    glz_enc_size = display_channel->enable_zlib_glz_wrap ?
-                       display_channel->zlib_glz_stat.comp_size :
-                       display_channel->glz_stat.comp_size;
-
-    spice_info("==> Compression stats for display %u", display_channel->common.base.id);
-    spice_info("Method   \t  count  \torig_size(MB)\tenc_size(MB)\tenc_time(s)");
-    spice_info("QUIC     \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->quic_stat.count,
-               stat_byte_to_mega(display_channel->quic_stat.orig_size),
-               stat_byte_to_mega(display_channel->quic_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->quic_stat.total)
-               );
-    spice_info("GLZ      \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->glz_stat.count,
-               stat_byte_to_mega(display_channel->glz_stat.orig_size),
-               stat_byte_to_mega(display_channel->glz_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->glz_stat.total)
-               );
-    spice_info("ZLIB GLZ \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->zlib_glz_stat.count,
-               stat_byte_to_mega(display_channel->zlib_glz_stat.orig_size),
-               stat_byte_to_mega(display_channel->zlib_glz_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->zlib_glz_stat.total)
-               );
-    spice_info("LZ       \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->lz_stat.count,
-               stat_byte_to_mega(display_channel->lz_stat.orig_size),
-               stat_byte_to_mega(display_channel->lz_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->lz_stat.total)
-               );
-    spice_info("JPEG     \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->jpeg_stat.count,
-               stat_byte_to_mega(display_channel->jpeg_stat.orig_size),
-               stat_byte_to_mega(display_channel->jpeg_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->jpeg_stat.total)
-               );
-    spice_info("JPEG-RGBA\t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->jpeg_alpha_stat.count,
-               stat_byte_to_mega(display_channel->jpeg_alpha_stat.orig_size),
-               stat_byte_to_mega(display_channel->jpeg_alpha_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->jpeg_alpha_stat.total)
-               );
-    spice_info("LZ4      \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->lz4_stat.count,
-               stat_byte_to_mega(display_channel->lz4_stat.orig_size),
-               stat_byte_to_mega(display_channel->lz4_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->lz4_stat.total)
-               );
-    spice_info("-------------------------------------------------------------------");
-    spice_info("Total    \t%8d\t%13.2f\t%12.2f\t%12.2f",
-               display_channel->lz_stat.count + display_channel->glz_stat.count +
-                                                display_channel->quic_stat.count +
-                                                display_channel->jpeg_stat.count +
-                                                display_channel->lz4_stat.count +
-                                                display_channel->jpeg_alpha_stat.count,
-               stat_byte_to_mega(display_channel->lz_stat.orig_size +
-                                 display_channel->glz_stat.orig_size +
-                                 display_channel->quic_stat.orig_size +
-                                 display_channel->jpeg_stat.orig_size +
-                                 display_channel->lz4_stat.orig_size +
-                                 display_channel->jpeg_alpha_stat.orig_size),
-               stat_byte_to_mega(display_channel->lz_stat.comp_size +
-                                 glz_enc_size +
-                                 display_channel->quic_stat.comp_size +
-                                 display_channel->jpeg_stat.comp_size +
-                                 display_channel->lz4_stat.comp_size +
-                                 display_channel->jpeg_alpha_stat.comp_size),
-               stat_cpu_time_to_sec(display_channel->lz_stat.total +
-                                    display_channel->glz_stat.total +
-                                    display_channel->zlib_glz_stat.total +
-                                    display_channel->quic_stat.total +
-                                    display_channel->jpeg_stat.total +
-                                    display_channel->lz4_stat.total +
-                                    display_channel->jpeg_alpha_stat.total)
-               );
-}
-
-#endif
-
 QXLInstance* red_worker_get_qxl(RedWorker *worker)
 {
     spice_return_val_if_fail(worker != NULL, NULL);
@@ -7941,9 +7852,7 @@ static void display_channel_client_on_disconnect(RedChannelClient *rcc)
     worker = common->worker;
     display_channel = (DisplayChannel *)rcc->channel;
     spice_assert(display_channel == worker->display_channel);
-#ifdef COMPRESS_STAT
-    print_compress_stats(display_channel);
-#endif
+    display_channel_compress_stats_print(display_channel);
     pixmap_cache_unref(dcc->pixmap_cache);
     dcc->pixmap_cache = NULL;
     red_release_glz(dcc);
@@ -9949,18 +9858,9 @@ void handle_dev_set_compression(void *opaque, void *payload)
     default:
         spice_warning("ic invalid");
     }
-#ifdef COMPRESS_STAT
-    print_compress_stats(worker->display_channel);
-    if (worker->display_channel) {
-        stat_reset(&worker->display_channel->quic_stat);
-        stat_reset(&worker->display_channel->lz_stat);
-        stat_reset(&worker->display_channel->glz_stat);
-        stat_reset(&worker->display_channel->jpeg_stat);
-        stat_reset(&worker->display_channel->zlib_glz_stat);
-        stat_reset(&worker->display_channel->jpeg_alpha_stat);
-        stat_reset(&worker->display_channel->lz4_stat);
-    }
-#endif
+
+    display_channel_compress_stats_print(worker->display_channel);
+    display_channel_compress_stats_reset(worker->display_channel);
 }
 
 void handle_dev_set_streaming_video(void *opaque, void *payload)
-- 
2.4.3



More information about the Spice-devel mailing list