diff mbox

[RFC,v2,46/49] replay: replay_info command

Message ID 20140717110616.8352.95699.stgit@PASHA-ISP
State New
Headers show

Commit Message

Pavel Dovgalyuk July 17, 2014, 11:06 a.m. UTC
This patch adds support for replay_info monitor command. This command
returns the information about replay execution (replay mode and current step).

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
 hmp-commands.hx      |   13 +++++++++++++
 monitor.c            |   17 +++++++++++++++++
 qapi-schema.json     |   27 +++++++++++++++++++++++++++
 qmp-commands.hx      |   14 ++++++++++++++
 replay/Makefile.objs |    1 +
 replay/replay-qmp.c  |   29 +++++++++++++++++++++++++++++
 replay/replay.c      |   25 +++++++++++++++++++++++++
 replay/replay.h      |    4 ++++
 8 files changed, 130 insertions(+), 0 deletions(-)
 create mode 100755 replay/replay-qmp.c

Comments

Eric Blake July 18, 2014, 3:55 p.m. UTC | #1
On 07/17/2014 05:06 AM, Pavel Dovgalyuk wrote:
> This patch adds support for replay_info monitor command. This command
> returns the information about replay execution (replay mode and current step).
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> ---

> +++ b/qapi-schema.json
> @@ -3491,3 +3491,30 @@
>  # Since: 2.1
>  ##
>  { 'command': 'rtc-reset-reinjection' }
> +
> +##
> +# @ReplayInfo:
> +#
> +# Information about replay process
> +#
> +# @mode: replay mode (none, play, record)
> +#
> +# @submode: play submode

What are the valid submodes?  Does the set of submodes differ according
to the main mode?  If so, is it better to use a flat union, where the
subtype is strongly typed to the correct limited possibilities according
to the mode?

> +#
> +# @step: current step of record or play
> +#
> +# Since:  2.2
> +##
> +{ 'type': 'ReplayInfo',
> +  'data': {'mode': 'str', 'submode': 'str', 'step': 'uint64'} }

Using 'str' to open-code a finite set of strings is not nice.  Please add:
 { 'enum': 'ReplayMode', 'data': [ 'none', 'play', 'record' ] }
then use 'mode': 'ReplayMode'.


> +++ b/qmp-commands.hx
> @@ -3755,3 +3755,17 @@ Example:
>  <- { "return": {} }
>  
>  EQMP
> +
> +    {
> +        .name       = "replay_info",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_replay_info,
> +    },
> +
> +SQMP
> +replay_info
> +-----------
> +
> +Shows information about replay process.
> +

No example?


> +
> +const char *replay_get_mode_name(void)
> +{
> +    switch (replay_mode) {
> +    case REPLAY_NONE:
> +        return "none";
> +    case REPLAY_PLAY:
> +        return "replay";
> +    case REPLAY_SAVE:
> +        return "record";
> +    default:
> +        return "unknown";
> +    }
> +}
> +

No need to open-code this.  If you properly set up an enum type in the
.json file, then you get the conversions between enum values and strings
for free from the generated QAPI framework.
Eric Blake July 18, 2014, 3:56 p.m. UTC | #2
On 07/17/2014 05:06 AM, Pavel Dovgalyuk wrote:
> This patch adds support for replay_info monitor command. This command
> returns the information about replay execution (replay mode and current step).
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> ---

Oh, missed one.


> +++ b/qapi-schema.json

> +##
> +# @replay_info

Please name this replay-info. HMP still uses '_', but QMP should prefer '-'.
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index d0943b1..19174f1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1788,6 +1788,19 @@  STEXI
 show available trace events and their state
 ETEXI
 
+    {
+        .name       = "replay_info",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show replay info",
+        .mhandler.cmd = do_replay_info,
+    },
+
+STEXI
+@item replay_info
+Shows information about replay process.
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/monitor.c b/monitor.c
index 5bc70a6..f336b91 100644
--- a/monitor.c
+++ b/monitor.c
@@ -73,6 +73,7 @@ 
 #include "block/qapi.h"
 #include "qapi/qmp-event.h"
 #include "qapi-event.h"
+#include "replay/replay.h"
 
 /* for pic/irq_info */
 #if defined(TARGET_SPARC)
@@ -1173,6 +1174,22 @@  static void do_watchdog_action(Monitor *mon, const QDict *qdict)
     }
 }
 
+static void do_replay_info(Monitor *mon, const QDict *qdict)
+{
+    switch (replay_mode) {
+    case REPLAY_NONE:
+        monitor_printf(mon, "Replay is not enabled\n");
+        break;
+    default:
+        monitor_printf(mon, "Replay mode: %s ", replay_get_mode_name());
+        if (replay_mode == REPLAY_PLAY) {
+            monitor_printf(mon, "(%s)", replay_get_play_submode_name());
+        }
+        monitor_printf(mon, "\n\tcurrent step: %" PRId64 "\n", replay_get_current_step());
+        break;
+    }
+}
+
 static void monitor_printc(Monitor *mon, int c)
 {
     monitor_printf(mon, "'");
diff --git a/qapi-schema.json b/qapi-schema.json
index fee541a..c45f795 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3491,3 +3491,30 @@ 
 # Since: 2.1
 ##
 { 'command': 'rtc-reset-reinjection' }
+
+##
+# @ReplayInfo:
+#
+# Information about replay process
+#
+# @mode: replay mode (none, play, record)
+#
+# @submode: play submode
+#
+# @step: current step of record or play
+#
+# Since:  2.2
+##
+{ 'type': 'ReplayInfo',
+  'data': {'mode': 'str', 'submode': 'str', 'step': 'uint64'} }
+
+##
+# @replay_info
+#
+# Query the status of replay engine
+#
+# Returns: @ReplayInfo reflecting the status
+#
+# Since:  2.2
+##
+{ 'command': 'replay_info', 'returns': 'ReplayInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 4be4765..d475633 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3755,3 +3755,17 @@  Example:
 <- { "return": {} }
 
 EQMP
+
+    {
+        .name       = "replay_info",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_replay_info,
+    },
+
+SQMP
+replay_info
+-----------
+
+Shows information about replay process.
+
+EQMP
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index f2e3bdc..1bc9621 100755
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -7,3 +7,4 @@  obj-y += replay-net.o
 obj-y += replay-audio.o
 obj-y += replay-char.o
 obj-y += replay-usb.o
+obj-y += replay-qmp.o
diff --git a/replay/replay-qmp.c b/replay/replay-qmp.c
new file mode 100755
index 0000000..966bd4d
--- /dev/null
+++ b/replay/replay-qmp.c
@@ -0,0 +1,29 @@ 
+/*
+ * replay-qmp.c
+ *
+ * Copyright (c) 2010-2014 Institute for System Programming
+ *                         of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "sysemu/sysemu.h"
+#include "qmp-commands.h"
+#include "qapi/qmp/qobject.h"
+#include "qapi/qmp-input-visitor.h"
+#include "replay/replay.h"
+#include "replay/replay-internal.h"
+
+ReplayInfo *qmp_replay_info(Error **errp)
+{
+    ReplayInfo *info = g_malloc0(sizeof(*info));
+
+    info->mode = g_strdup(replay_get_mode_name());
+    info->submode = g_strdup(replay_get_play_submode_name());
+    info->step = replay_get_current_step();
+
+    return info;
+}
diff --git a/replay/replay.c b/replay/replay.c
index a89ba91..f711c26 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -638,3 +638,28 @@  void replay_data_buffer(unsigned char *data, size_t size)
         replay_put_array(data, size);
     }
 }
+
+const char *replay_get_mode_name(void)
+{
+    switch (replay_mode) {
+    case REPLAY_NONE:
+        return "none";
+    case REPLAY_PLAY:
+        return "replay";
+    case REPLAY_SAVE:
+        return "record";
+    default:
+        return "unknown";
+    }
+}
+
+const char *replay_get_play_submode_name(void)
+{
+    switch (play_submode) {
+    case REPLAY_PLAY_NORMAL:
+        return "normal";
+    case REPLAY_PLAY_UNKNOWN:
+    default:
+        return "unknown";
+    }
+}
diff --git a/replay/replay.h b/replay/replay.h
index aa15803..ee0460f 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -52,6 +52,10 @@  extern int replay_icount;
 
 /*! Returns replay play submode */
 int replay_get_play_submode(void);
+/*! Returns current mode name */
+const char *replay_get_mode_name(void);
+/*! Returns replay-play submode name */
+const char *replay_get_play_submode_name(void);
 
 /* Replay process control functions */