From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgp-0001vB-VW for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIHgg-000664-0P for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:07 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:42481 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgf-000653-N3 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:36:57 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Fri, 15 Aug 2014 15:35:42 +0200 Message-Id: <1408109759-1100-11-git-send-email-benoit.canet@nodalink.com> In-Reply-To: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> References: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to monitor-system.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com The extracted function are help_cmd, do_help_cmd, do_trace_event_set_stat= e, and do_trace_file. Signed-off-by: Beno=C3=AEt Canet --- monitor-system.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ monitor.c | 121 -------------------------------------------------= ------ 2 files changed, 121 insertions(+), 121 deletions(-) diff --git a/monitor-system.c b/monitor-system.c index 90758db..e725a42 100644 --- a/monitor-system.c +++ b/monitor-system.c @@ -110,3 +110,124 @@ out: monitor_data_destroy(&hmp); return output; } + +static void help_cmd_dump_one(Monitor *mon, + const MonitorCommand *cmd, + char **prefix_args, + int prefix_args_nb) +{ + int i; + + for (i =3D 0; i < prefix_args_nb; i++) { + monitor_printf(mon, "%s ", prefix_args[i]); + } + monitor_printf(mon, "%s %s -- %s\n", cmd->name, cmd->params, cmd->he= lp); +} + +/* @args[@arg_index] is the valid command need to find in @cmds */ +static void help_cmd_dump(Monitor *mon, const MonitorCommand *cmds, + char **args, int nb_args, int arg_index) +{ + const MonitorCommand *cmd; + + /* No valid arg need to compare with, dump all in *cmds */ + if (arg_index >=3D nb_args) { + for (cmd =3D cmds; cmd->name !=3D NULL; cmd++) { + help_cmd_dump_one(mon, cmd, args, arg_index); + } + return; + } + + /* Find one entry to dump */ + for (cmd =3D cmds; cmd->name !=3D NULL; cmd++) { + if (compare_cmd(args[arg_index], cmd->name)) { + if (cmd->sub_table) { + /* continue with next arg */ + help_cmd_dump(mon, cmd->sub_table, + args, nb_args, arg_index + 1); + } else { + help_cmd_dump_one(mon, cmd, args, arg_index); + } + break; + } + } +} + +void help_cmd(Monitor *mon, const char *name) +{ + char *args[MAX_ARGS]; + int nb_args =3D 0; + + /* 1. parse user input */ + if (name) { + /* special case for log, directly dump and return */ + if (!strcmp(name, "log")) { + const QEMULogItem *item; + monitor_printf(mon, "Log items (comma separated):\n"); + monitor_printf(mon, "%-10s %s\n", "none", "remove all logs")= ; + for (item =3D qemu_log_items; item->mask !=3D 0; item++) { + monitor_printf(mon, "%-10s %s\n", item->name, item->help= ); + } + return; + } + + if (parse_cmdline(name, &nb_args, args) < 0) { + return; + } + } + + /* 2. dump the contents according to parsed args */ + help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0); + + free_cmdline_args(args, nb_args); +} + +void do_help_cmd(Monitor *mon, const QDict *qdict) +{ + help_cmd(mon, qdict_get_try_str(qdict, "name")); +} + +void do_trace_event_set_state(Monitor *mon, const QDict *qdict) +{ + const char *tp_name =3D qdict_get_str(qdict, "name"); + bool new_state =3D qdict_get_bool(qdict, "option"); + + bool found =3D false; + TraceEvent *ev =3D NULL; + while ((ev =3D trace_event_pattern(tp_name, ev)) !=3D NULL) { + found =3D true; + if (!trace_event_get_state_static(ev)) { + monitor_printf(mon, "event \"%s\" is not traceable\n", tp_na= me); + } else { + trace_event_set_state_dynamic(ev, new_state); + } + } + if (!trace_event_is_pattern(tp_name) && !found) { + monitor_printf(mon, "unknown event name \"%s\"\n", tp_name); + } +} + +#ifdef CONFIG_TRACE_SIMPLE +void do_trace_file(Monitor *mon, const QDict *qdict) +{ + const char *op =3D qdict_get_try_str(qdict, "op"); + const char *arg =3D qdict_get_try_str(qdict, "arg"); + + if (!op) { + st_print_trace_file_status((FILE *)mon, &monitor_fprintf); + } else if (!strcmp(op, "on")) { + st_set_trace_file_enabled(true); + } else if (!strcmp(op, "off")) { + st_set_trace_file_enabled(false); + } else if (!strcmp(op, "flush")) { + st_flush_trace_buffer(); + } else if (!strcmp(op, "set")) { + if (arg) { + st_set_trace_file(arg); + } + } else { + monitor_printf(mon, "unexpected argument \"%s\"\n", op); + help_cmd(mon, "trace-file"); + } +} +#endif diff --git a/monitor.c b/monitor.c index 12ec622..a807ff9 100644 --- a/monitor.c +++ b/monitor.c @@ -698,127 +698,6 @@ int parse_cmdline(const char *cmdline, int *pnb_arg= s, char **args) return -1; } =20 -static void help_cmd_dump_one(Monitor *mon, - const MonitorCommand *cmd, - char **prefix_args, - int prefix_args_nb) -{ - int i; - - for (i =3D 0; i < prefix_args_nb; i++) { - monitor_printf(mon, "%s ", prefix_args[i]); - } - monitor_printf(mon, "%s %s -- %s\n", cmd->name, cmd->params, cmd->he= lp); -} - -/* @args[@arg_index] is the valid command need to find in @cmds */ -static void help_cmd_dump(Monitor *mon, const MonitorCommand *cmds, - char **args, int nb_args, int arg_index) -{ - const MonitorCommand *cmd; - - /* No valid arg need to compare with, dump all in *cmds */ - if (arg_index >=3D nb_args) { - for (cmd =3D cmds; cmd->name !=3D NULL; cmd++) { - help_cmd_dump_one(mon, cmd, args, arg_index); - } - return; - } - - /* Find one entry to dump */ - for (cmd =3D cmds; cmd->name !=3D NULL; cmd++) { - if (compare_cmd(args[arg_index], cmd->name)) { - if (cmd->sub_table) { - /* continue with next arg */ - help_cmd_dump(mon, cmd->sub_table, - args, nb_args, arg_index + 1); - } else { - help_cmd_dump_one(mon, cmd, args, arg_index); - } - break; - } - } -} - -void help_cmd(Monitor *mon, const char *name) -{ - char *args[MAX_ARGS]; - int nb_args =3D 0; - - /* 1. parse user input */ - if (name) { - /* special case for log, directly dump and return */ - if (!strcmp(name, "log")) { - const QEMULogItem *item; - monitor_printf(mon, "Log items (comma separated):\n"); - monitor_printf(mon, "%-10s %s\n", "none", "remove all logs")= ; - for (item =3D qemu_log_items; item->mask !=3D 0; item++) { - monitor_printf(mon, "%-10s %s\n", item->name, item->help= ); - } - return; - } - - if (parse_cmdline(name, &nb_args, args) < 0) { - return; - } - } - - /* 2. dump the contents according to parsed args */ - help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0); - - free_cmdline_args(args, nb_args); -} - -void do_help_cmd(Monitor *mon, const QDict *qdict) -{ - help_cmd(mon, qdict_get_try_str(qdict, "name")); -} - -void do_trace_event_set_state(Monitor *mon, const QDict *qdict) -{ - const char *tp_name =3D qdict_get_str(qdict, "name"); - bool new_state =3D qdict_get_bool(qdict, "option"); - - bool found =3D false; - TraceEvent *ev =3D NULL; - while ((ev =3D trace_event_pattern(tp_name, ev)) !=3D NULL) { - found =3D true; - if (!trace_event_get_state_static(ev)) { - monitor_printf(mon, "event \"%s\" is not traceable\n", tp_na= me); - } else { - trace_event_set_state_dynamic(ev, new_state); - } - } - if (!trace_event_is_pattern(tp_name) && !found) { - monitor_printf(mon, "unknown event name \"%s\"\n", tp_name); - } -} - -#ifdef CONFIG_TRACE_SIMPLE -void do_trace_file(Monitor *mon, const QDict *qdict) -{ - const char *op =3D qdict_get_try_str(qdict, "op"); - const char *arg =3D qdict_get_try_str(qdict, "arg"); - - if (!op) { - st_print_trace_file_status((FILE *)mon, &monitor_fprintf); - } else if (!strcmp(op, "on")) { - st_set_trace_file_enabled(true); - } else if (!strcmp(op, "off")) { - st_set_trace_file_enabled(false); - } else if (!strcmp(op, "flush")) { - st_flush_trace_buffer(); - } else if (!strcmp(op, "set")) { - if (arg) { - st_set_trace_file(arg); - } - } else { - monitor_printf(mon, "unexpected argument \"%s\"\n", op); - help_cmd(mon, "trace-file"); - } -} -#endif - static void user_monitor_complete(void *opaque, QObject *ret_data) { MonitorCompletionData *data =3D (MonitorCompletionData *)opaque;=20 --=20 2.1.0.rc1