[Spice-devel,server,1/3] replay: learn how to count commands

Submitted by Uri Lublin on March 3, 2016, 9:58 a.m.

Details

Message ID 1456999132-5371-2-git-send-email-uril@redhat.com
State New
Headers show
Series "replay: add count and skip" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Uri Lublin March 3, 2016, 9:58 a.m.
---
 server/tests/replay.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch hide | download patch | download mbox

diff --git a/server/tests/replay.c b/server/tests/replay.c
index f3b670f..83411d3 100644
--- a/server/tests/replay.c
+++ b/server/tests/replay.c
@@ -47,6 +47,8 @@  static QXLWorker *qxl_worker = NULL;
 static gboolean started = FALSE;
 static QXLInstance display_sin = { 0, };
 static gint slow = 0;
+static gboolean do_count = 0;
+static guint ncommands = 0;
 static pid_t client_pid;
 static GMainLoop *loop = NULL;
 static GAsyncQueue *aqueue = NULL;
@@ -117,6 +119,10 @@  static gboolean fill_queue_idle(gpointer user_data)
             goto end;
         }
 
+        if (do_count) {
+            ncommands++;
+        }
+
         if (slow)
             g_usleep(slow);
 
@@ -297,6 +303,7 @@  int main(int argc, char **argv)
         { "port", 'p', 0, G_OPTION_ARG_INT, &port, "Server port (default 5000)", "PORT" },
         { "wait", 'w', 0, G_OPTION_ARG_NONE, &wait, "Wait for client", NULL },
         { "slow", 's', 0, G_OPTION_ARG_INT, &slow, "Slow down replay. Delays USEC microseconds before each command", "USEC" },
+        { "count", 0, 0, G_OPTION_ARG_NONE, &do_count, "count the number of commands", NULL },
         { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file, "replay file", "FILE" },
         { NULL }
     };
@@ -402,6 +409,9 @@  int main(int argc, char **argv)
     loop = g_main_loop_new(basic_event_loop_get_context(), FALSE);
     g_main_loop_run(loop);
 
+    if (do_count)
+        g_print("Counted %d commands\n", ncommands);
+
     end_replay();
     g_async_queue_unref(aqueue);
 

Comments

> 
> ---
>  server/tests/replay.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/server/tests/replay.c b/server/tests/replay.c
> index f3b670f..83411d3 100644
> --- a/server/tests/replay.c
> +++ b/server/tests/replay.c
> @@ -47,6 +47,8 @@ static QXLWorker *qxl_worker = NULL;
>  static gboolean started = FALSE;
>  static QXLInstance display_sin = { 0, };
>  static gint slow = 0;
> +static gboolean do_count = 0;

I would use FALSE here.

> +static guint ncommands = 0;
>  static pid_t client_pid;
>  static GMainLoop *loop = NULL;
>  static GAsyncQueue *aqueue = NULL;
> @@ -117,6 +119,10 @@ static gboolean fill_queue_idle(gpointer user_data)
>              goto end;
>          }
>  
> +        if (do_count) {
> +            ncommands++;
> +        }
> +

why not just ++ncommands ?

>          if (slow)
>              g_usleep(slow);
>  
> @@ -297,6 +303,7 @@ int main(int argc, char **argv)
>          { "port", 'p', 0, G_OPTION_ARG_INT, &port, "Server port (default
>          5000)", "PORT" },
>          { "wait", 'w', 0, G_OPTION_ARG_NONE, &wait, "Wait for client", NULL
>          },
>          { "slow", 's', 0, G_OPTION_ARG_INT, &slow, "Slow down replay. Delays
>          USEC microseconds before each command", "USEC" },
> +        { "count", 0, 0, G_OPTION_ARG_NONE, &do_count, "count the number of
> commands", NULL },

the help could be "Print number of commands executed" but it's just a preference.
All other option helps start with a capital letter.

>          { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file,
>          "replay file", "FILE" },
>          { NULL }
>      };
> @@ -402,6 +409,9 @@ int main(int argc, char **argv)
>      loop = g_main_loop_new(basic_event_loop_get_context(), FALSE);
>      g_main_loop_run(loop);
>  
> +    if (do_count)
> +        g_print("Counted %d commands\n", ncommands);
> +
>      end_replay();
>      g_async_queue_unref(aqueue);
>  
> --
> 2.5.0
> 

Frediano