monitor: improve tracing in handle_qmp_command
PATCH v2 1/1 monitor: improve tracing in handle_qmp_command
Calculate req_json only if trace_handle_qmp_command enabled.
---
Changes from v1:
- written in the explicit for, as discussed in the mailing list
monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
monitor.c +5 -4
@@ -3822,7 +3822,6 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QDict *qdict =NULL ;Monitor *mon = cur_mon;Error *err =NULL ; -QString *req_json; req =json_parser_parse_err (tokens,NULL , &err);if (!req && !err) {
@@ -3840,9 +3839,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)qdict_del (qdict,"id" ); }/* else will fail qmp_dispatch() */ - req_json =qobject_to_json (req); -trace_handle_qmp_command (mon,qstring_get_str (req_json)); -qobject_decref (QOBJECT (req_json)); +if (trace_event_get_state (TRACE_HANDLE_QMP_COMMAND )) { +QString *req_json =qobject_to_json (req); +trace_handle_qmp_command (mon,qstring_get_str (req_json)); +qobject_decref (QOBJECT (req_json)); + } rsp =qmp_dispatch (cur_mon->qmp.commands, req);
Signature · 1 line
2.11.0
Quoted 10 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>---
Changes from v1:
- written in the explicit for, as discussed in the mailing list
I could live with this being considered a bug-fix for 2.10, as we regressed in speed/memory usage during normal untraced QMP commands.
Quoted 32 lines
monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)monitor.c +5
-4@@ -3822,7 +3822,6 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QDict *qdict =NULL ;Monitor *mon = cur_mon;Error *err =NULL ; -QString *req_json; req =json_parser_parse_err (tokens,NULL , &err);if (!req && !err) {@@ -3840,9 +3839,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)qdict_del (qdict,"id" ); }/* else will fail qmp_dispatch() */ - req_json =qobject_to_json (req); -trace_handle_qmp_command (mon,qstring_get_str (req_json)); -qobject_decref (QOBJECT (req_json)); +if (trace_event_get_state (TRACE_HANDLE_QMP_COMMAND )) { +QString *req_json =qobject_to_json (req); +trace_handle_qmp_command (mon,qstring_get_str (req_json)); +qobject_decref (QOBJECT (req_json)); + } rsp =qmp_dispatch (cur_mon->qmp.commands, req);
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 30 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>---
Changes from v1:
- written in the explicit for, as discussed in the mailing listmonitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)monitor.c +0
-1@@ -3822,7 +3822,6 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QDict *qdict =NULL ;Monitor *mon = cur_mon;Error *err =NULL ; -QString *req_json; req =json_parser_parse_err (tokens,NULL , &err);if (!req && !err) {@@ -3840,9 +3839,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)qdict_del (qdict,"id" ); }/* else will fail qmp_dispatch() */
monitor.c static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) · line 3848
Quoted 10 lines
monitor.c +5
-3- req_json =qobject_to_json (req); -trace_handle_qmp_command (mon,qstring_get_str (req_json)); -qobject_decref (QOBJECT (req_json)); +if (trace_event_get_state (TRACE_HANDLE_QMP_COMMAND )) { +QString *req_json =qobject_to_json (req); +trace_handle_qmp_command (mon,qstring_get_str (req_json)); +qobject_decref (QOBJECT (req_json)); + } rsp =qmp_dispatch (cur_mon->qmp.commands, req);
Thanks for the patch. Another fix is needed first so that SystemTap and LTTng UST users can use this trace event. Currently trace_event_get_state(TRACE_HANDLE_QMP_COMMAND) will return false because SystemTap and LTTng UST maintain their own state. I have CCed you on the fix.
Stefan
Quoted 30 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>---
Changes from v1:
- written in the explicit for, as discussed in the mailing listmonitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)monitor.c +0
-1@@ -3822,7 +3822,6 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QDict *qdict =NULL ;Monitor *mon = cur_mon;Error *err =NULL ; -QString *req_json; req =json_parser_parse_err (tokens,NULL , &err);if (!req && !err) {@@ -3840,9 +3839,11 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)qdict_del (qdict,"id" ); }/* else will fail qmp_dispatch() */
monitor.c static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) · line 3848
Quoted 10 lines
monitor.c +5
-3- req_json =qobject_to_json (req); -trace_handle_qmp_command (mon,qstring_get_str (req_json)); -qobject_decref (QOBJECT (req_json)); +if (trace_event_get_state (TRACE_HANDLE_QMP_COMMAND )) { +QString *req_json =qobject_to_json (req); +trace_handle_qmp_command (mon,qstring_get_str (req_json)); +qobject_decref (QOBJECT (req_json)); + } rsp =qmp_dispatch (cur_mon->qmp.commands, req);
Conflicts with Eric's commit 8a4613a, but I can resolve that in my tree.
The commit message is too terse. "Improve tracing" makes me think of more informative traces, but that's not the case. What exactly is improved here?
Quoted 11 lines · Markus Armbruster
Quoted 8 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>---
Quoted 5 lines
Conflicts with Eric's commit 8a4613a, but I can resolve that in my tree.
The commit message is too terse. "Improve tracing" makes me think of more informative traces, but that's not the case. What exactly is improved here?
Reduce overhead when not tracing. Without the patch, we are malloc'ing a QString and spending CPU cycles on converting a QObject to string, just for the sake of sticking the string in the trace message - if we aren't tracing, it's wasted effort.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 14 lines · Eric Blake
Quoted 13 lines · Markus Armbruster
Quoted 8 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>---
Conflicts with Eric's commit 8a4613a, but I can resolve that in my tree.
Quoted 8 lines
Quoted 3 lines
The commit message is too terse. "Improve tracing" makes me think of more informative traces, but that's not the case. What exactly is improved here?
Reduce overhead when not tracing. Without the patch, we are malloc'ing a QString and spending CPU cycles on converting a QObject to string, just for the sake of sticking the string in the trace message - if we aren't tracing, it's wasted effort.
What about:
monitor: Reduce handle_qmp_command() tracing overhead
We are malloc'ing a QString and spending CPU cycles on converting a QObject to string, just for the sake of sticking the string in the trace message. Wasted when we aren't tracing. Avoid that.
Denis?
Stefan Hajnoczi
AppliedQuoted 7 lines · Denis V. Lunev
Calculate
req_jsononly iftrace_handle_qmp_commandenabled.Signed-off-by Denis V. Lunev <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Lluís Vilanova <[email protected]>CC Dr. David Alan Gilbert <[email protected]>CC Markus Armbruster <[email protected]>
Quoted 6 lines
---
Changes from v1:
- written in the explicit for, as discussed in the mailing listmonitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Replaced commit message & description with the one Markus suggested to include more details on why this patch is necessary.
Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing
Stefan