From: Markus Armbruster <armbru@redhat.com>
To: Pavel Butsykin <pbutsykin@odin.com>
Cc: "Denis V. Lunev" <den@openvz.org>,
Pavel Butsykin <pbutsykin@virtuozzo.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [PATCH 2/3] log: report hmp/qmp command and qmp event
Date: Fri, 16 Oct 2015 14:35:11 +0200 [thread overview]
Message-ID: <87io67dm9s.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <5620C8BD.9020106@odin.com> (Pavel Butsykin's message of "Fri, 16 Oct 2015 12:51:57 +0300")
Pavel Butsykin <pbutsykin@odin.com> writes:
> On 16.10.2015 10:34, Markus Armbruster wrote:
>> "Denis V. Lunev" <den@openvz.org> writes:
>>
>>> From: Pavel Butsykin <pbutsykin@virtuozzo.com>
>>>
>>> This log would be very welcome for long-term diagnostics of the system
>>> in the production. This log is at least necessary to understand what
>>> has been happened on the system and to identify issues at higher-level
>>> subsystems (libvirt, etc).
>>>
>>> Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>> CC: Markus Armbruster <armbru@redhat.com>
>>> CC: Luiz Capitulino <lcapitulino@redhat.com>
>>> CC: Eric Blake <eblake@redhat.com>
>>> CC: Peter Maydell <peter.maydell@linaro.org>
>>> ---
>>> include/qemu/log.h | 1 +
>>> monitor.c | 18 ++++++++++++++++++
>>> qemu-log.c | 1 +
>>> 3 files changed, 20 insertions(+)
>>>
>>> diff --git a/include/qemu/log.h b/include/qemu/log.h
>>> index 57b8c96..ba86606 100644
>>> --- a/include/qemu/log.h
>>> +++ b/include/qemu/log.h
>>> @@ -41,6 +41,7 @@ static inline bool qemu_log_enabled(void)
>>> #define LOG_UNIMP (1 << 10)
>>> #define LOG_GUEST_ERROR (1 << 11)
>>> #define CPU_LOG_MMU (1 << 12)
>>> +#define LOG_CMD (1 << 13)
>>>
>>> /* Returns true if a bit is set in the current loglevel mask
>>> */
>>> diff --git a/monitor.c b/monitor.c
>>> index 4f1ba2f..71810bb 100644
>>> --- a/monitor.c
>>> +++ b/monitor.c
>>> @@ -434,6 +434,12 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data,
>>> }
>>>
>>> monitor_json_emitter(mon, QOBJECT(qmp));
>>> + if (qemu_loglevel_mask(LOG_CMD)) {
>>> + QString *output_json = qobject_to_json_pretty(QOBJECT(qmp));
>>> + qemu_log("qmp response:\n%s\n", output_json->string);
>>> + QDECREF(output_json);
>>> + }
>>> +
>>
>> Uh, _pretty makes this multiple lines. Is this appropriate for the log
>> file? Finding log message boundaries goes from regular to
>> context-free...
>>
> I think so much more convenient to read the log, for example:
> qmp requested:
> {
> "execute": "query-block"
> }
> qmp responsed:
> {
> "return": [
> {
> "io-status": "ok",
> "device": "drive-virtio-disk0",
> "locked": false,
> "removable": false,
> "inserted": {
> "iops_rd": 0,
> "detect_zeroes": "off",
> "image": {
> "snapshots": [
> {
> "vm-clock-nsec": 235120743,
> "name": "snap4",
> "date-sec": 1444402741,
> "date-nsec": 246561000,
> "vm-clock-sec": 42,
> "id": "2",
> "vm-state-size": 247252333
> },
> ...
>
> if we just use qobject_to_json(), it will be a long string, which may
> be difficult to understand.
Log files should be utterly trivial to parse. That means a rigid
format.
The traditional format is one line per entry, prefixed with a timestamp.
Extracting JSON from such lines and feeding it to a pretty-printer is
bothersome, but it's at least feasible.
Reliably finding log message boundaries in a log file without rules on
message format generally isn't.
I'm not sure how the log.h interface is currently used. Are there any
rules, or is it a "barf whatever text you like to the log file" thing?
If there are rules, we should stick to them.
If there are none, I'd seriously consider giving up on this log file and
create a new one that's actually parseable.
See also "What's the intended use of log.h logging?"
>> Nitpick: we generally spell it QMP.
>>
> Ok.
>
>>> QDECREF(qmp);
>>> }
>>>
>>> @@ -474,6 +480,11 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *data, Error **errp)
>>> evstate->last,
>>> now);
>>>
>>> + if (qemu_loglevel_mask(LOG_CMD)) {
>>> + QString *output_json = qobject_to_json_pretty(QOBJECT(data));
>>> + qemu_log("qmp event:\n%s\n", output_json->string);
>>> + QDECREF(output_json);
>>> + }
>>
>> This does *not* log QMP events (the ones put on the wire), it logs
>> *QAPI* events, which may or may not put on the wire due to rate
>> limiting.
>>
>> Are you sure we don't want to rate-limit log messages?
>>
>> If you really want to log QAPI events rather than QMP events, you get to
>> explain why in the commit message, and you get to document the
>> difference between the log and the actual wire.
>>
>> But I suspect you merely put this in the wrong place :)
>>
>>> /* Rate limit of 0 indicates no throttling */
>>> qemu_mutex_lock(&monitor_lock);
>>> if (!evstate->rate) {
>>
>> Not logged: the QMP greeting. If you want to log QMP, log all of QMP.
>>
>> You can either put the logging of the transmit direction in
>> monitor_json_emitter(), or you put it in each of its callers.
>>
> I agree, just missed this point. In this case, we are interested in
> logging QAPI and QMP events. For QAPI events point logging can be put
> in monitor_qapi_event_emit(), it should solve the problem with
> rate-limit. For QMP(and monitor_json_emitter) more suitable put it in
> each of its callers, because it is not known what is this call(it the
> request, response or event).
>
>>> @@ -2848,6 +2859,8 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
>>> QDict *qdict;
>>> const mon_cmd_t *cmd;
>>>
>>> + qemu_log_mask(LOG_CMD, "hmp request:\n%s\n", cmdline);
>>> +
>>> cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table);
>>> if (!cmd) {
>>> return;
>>> @@ -3823,6 +3836,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
>>> goto err_out;
>>> }
>>>
>>> + if (qemu_loglevel_mask(LOG_CMD)) {
>>> + QString *output_json = output_json = qobject_to_json_pretty(obj);
>>> + qemu_log("qmp request:\n%s\n", output_json->string);
>>> + QDECREF(output_json);
>>> + }
>>> input = qmp_check_input_obj(obj, &local_err);
>>> if (!input) {
>>> qobject_decref(obj);
>>
>> Nitpick: QMP calls this a command, not a request.
>>
> It is understood that the request came to execute the command.
It's just terminology, but I like *consistent* terminology.
docs/qmp-spec.txt calls it a command, not a request.
>>> diff --git a/qemu-log.c b/qemu-log.c
>>> index e6d2b3f..ba7b34c 100644
>>> --- a/qemu-log.c
>>> +++ b/qemu-log.c
>>> @@ -98,6 +98,7 @@ const QEMULogItem qemu_log_items[] = {
>>> { LOG_GUEST_ERROR, "guest_errors",
>>> "log when the guest OS does something invalid (eg accessing a\n"
>>> "non-existent register)" },
>>> + { LOG_CMD, "cmd", "log the hmp/qmp commands execution" },
>>> { 0, NULL, NULL },
>>> };
>>
>> I can't quite see the use case for logging HMP, but since you wrote it,
>> I assume you got one.
>>
>> Regardless, separate flags and patches for QMP and HMP, please.
>>
> Ok.
next prev parent reply other threads:[~2015-10-16 12:35 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 7:30 [Qemu-devel] [PATCH 0/3] QEMU logging improvements Denis V. Lunev
2015-10-15 7:30 ` [Qemu-devel] [PATCH 1/3] log: improve performance of qemu_log and qemu_log_mask if disabled Denis V. Lunev
2015-10-15 17:23 ` Alex Bennée
2015-10-15 17:40 ` Denis V. Lunev
2015-10-15 18:36 ` Alex Bennée
2015-10-16 7:17 ` Markus Armbruster
2015-10-16 7:45 ` Denis V. Lunev
2015-10-16 11:02 ` Markus Armbruster
2015-10-16 11:08 ` Denis V. Lunev
2015-10-15 7:30 ` [Qemu-devel] [PATCH 2/3] log: report hmp/qmp command and qmp event Denis V. Lunev
2015-10-16 7:34 ` Markus Armbruster
2015-10-16 9:51 ` Pavel Butsykin
2015-10-16 12:35 ` Markus Armbruster [this message]
2015-10-16 12:33 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Markus Armbruster
2015-10-16 12:48 ` [Qemu-devel] What's the intended use of log.h logging? Paolo Bonzini
2015-10-16 12:54 ` Peter Maydell
2015-10-16 13:00 ` Paolo Bonzini
2015-10-16 13:38 ` Denis V. Lunev
2015-10-16 13:26 ` Daniel P. Berrange
2015-10-16 13:29 ` Peter Maydell
2015-10-16 13:30 ` Paolo Bonzini
2015-10-16 13:36 ` Peter Maydell
2015-10-16 14:17 ` Paolo Bonzini
2015-10-16 14:31 ` Peter Maydell
2015-10-16 15:27 ` Paolo Bonzini
2015-10-19 13:17 ` Markus Armbruster
2015-10-19 13:19 ` Paolo Bonzini
2015-10-19 13:54 ` Peter Maydell
2015-10-16 12:51 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Peter Maydell
2015-10-19 14:29 ` [Qemu-devel] What's the intended use of log.h logging? Markus Armbruster
2015-10-19 14:41 ` Peter Maydell
2015-10-19 16:57 ` Dr. David Alan Gilbert
2015-10-19 17:02 ` Dr. David Alan Gilbert
2015-10-20 13:11 ` Kevin Wolf
2015-10-16 14:36 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Alex Bennée
2015-10-19 14:52 ` [Qemu-devel] What's the intended use of log.h logging? Markus Armbruster
2015-10-19 14:57 ` Peter Maydell
2015-10-21 10:41 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Stefan Hajnoczi
2015-10-21 11:10 ` [Qemu-devel] What's the intended use of log.h logging? Denis V. Lunev
2015-10-21 12:22 ` [Qemu-devel] What's the intended use of log.h logging? (was: [PATCH 2/3] log: report hmp/qmp command and qmp event) Peter Maydell
2015-10-22 12:26 ` Stefan Hajnoczi
2015-10-22 13:05 ` [Qemu-devel] What's the intended use of log.h logging? Paolo Bonzini
2015-10-15 7:30 ` [Qemu-devel] [PATCH 3/3] log: adds a timestamp to each log entry Denis V. Lunev
2015-10-16 7:49 ` Markus Armbruster
2015-10-16 9:55 ` Pavel Butsykin
2015-10-16 11:33 ` Markus Armbruster
2015-10-15 14:49 ` [Qemu-devel] [PATCH 0/3] QEMU logging improvements Kashyap Chamarthy
2015-10-15 15:18 ` Pavel Butsykin
2015-10-15 16:02 ` Kashyap Chamarthy
2015-10-26 9:16 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87io67dm9s.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=den@openvz.org \
--cc=lcapitulino@redhat.com \
--cc=pbutsykin@odin.com \
--cc=pbutsykin@virtuozzo.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.