From patchwork Wed Jun 26 22:20:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seiji Aguchi X-Patchwork-Id: 254886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E463E2C007C for ; Thu, 27 Jun 2013 08:21:51 +1000 (EST) Received: from localhost ([::1]:56574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ury62-0003E3-01 for incoming@patchwork.ozlabs.org; Wed, 26 Jun 2013 18:21:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ury5X-00036x-OY for qemu-devel@nongnu.org; Wed, 26 Jun 2013 18:21:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ury5U-0004UV-Eq for qemu-devel@nongnu.org; Wed, 26 Jun 2013 18:21:19 -0400 Received: from usindpps06.hds.com ([207.126.252.19]:33467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ury5U-0004RJ-7O for qemu-devel@nongnu.org; Wed, 26 Jun 2013 18:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hds.com; h=message-id : date : from : mime-version : to : cc : subject : content-type : content-transfer-encoding; s=mail1; bh=CLq0Dw7L+qYmNi4znFj2oxr9RBet5ippiHriQAu6sQo=; b=AfHygjkb1XojwDy6qCRKD8zJFnKVMUcOR1N6ja8vTVjLF/r38J/+HJiyoB5U4f1pG+AA qlps3h+K97sBH+uAYzxeIwDGqvP2LOEVPx7Nnb6CpzbLGNWMANciFMfQS21NjfNE/BHD LxQ/Y1FY0yjeaePoZ6s1dxhP6E5JvA/l2jChq5CHUKtKIGV3/N0oNNGdYLMeUMwdUSNm A2EJAaZOdDDNgfEx7648UTXuvnSV1s0fb9f5tU7UgWPvuuaHC7ZVfQBspVKX1iWJfQ0h 4Ik4Fyldi9RvF7NRwKUdblybrIPV5DeeQI4WrvUOxnOr7kbLE2gKmx0CLn62xTlEHRiz 8Q== Received: from usindmail01.hds.com (usindmail03 [207.126.252.22]) by usindpps06.hds.com (8.14.5/8.14.5) with ESMTP id r5QMKvXw008262; Wed, 26 Jun 2013 15:20:57 -0700 Received: from [10.74.80.29] (usindnetf5d-vlan47float.corp.hds.com [10.74.73.11]) by usindmail01.hds.com (8.14.1/8.14.1) with ESMTP id r5QMKtRr011869; Wed, 26 Jun 2013 18:20:55 -0400 (EDT) Message-ID: <51CB6946.90903@hds.com> Date: Wed, 26 Jun 2013 18:20:54 -0400 From: Seiji Aguchi User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 mx ip4:207.126.244.0/26 ip4:207.126.252.0/25 include:mktomail.com include:cloud.hds.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8794, 1.0.431, 0.0.0000 definitions=2013-06-26_08:2013-06-26, 2013-06-26, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=outbound_policy score=0 kscore.is_bulkscore=3.34177130412172e-14 kscore.compositescore=0 circleOfTrustscore=0 compositescore=0.172425699998943 urlsuspect_oldscore=0.997706193548354 suspectscore=21 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=393 rbsscore=0.172425699998943 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1305240000 definitions=main-1306260189 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 207.126.252.19 Cc: kwolf@redhat.com, aliguori@us.ibm.com, tomoki.sekiyama@hds.com, mst@redhat.com, stefanha@gmail.com, mtosatti@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, dle-develop@lists.sourceforge.net, av1474@comtv.ru, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v3] Add timestamp to error message X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org [Issue] When we offer a customer support service and a problem happens in a customer's system, we try to understand the problem by comparing what the customer reports with message logs of the customer's system. In this case, we often need to know when the problem happens. But, currently, there is no timestamp in qemu's error messages. Therefore, we may not be able to understand the problem based on error messages. [Solution] Add a timestamp to qemu's error message logged by error_report() with g_time_val_to_iso8601(). [TODO] Add timestamp to monitor_printf() and fprintf(). Signed-off-by: Seiji Aguchi --- Changelog v2 -> v3 - Use g_time_val_to_iso8601() to get timestamp instead of copying libvirt's time-handling functions. According to discussion below, qemu doesn't need to take care if timestamp functions are async-signal safe or not. http://marc.info/?l=qemu-devel&m=136741841921265&w=2 Also, In the review of v2 patch, strftime() are recommended to format string. But it is not a suitable function to handle msec. Then, simply call g_time_val_to_iso8601(). - Intoroduce a common time-handling function to util/qemu-time.c. (Suggested by Daniel P. Berrange) v1 -> v2 - add an option, -msg timestamp={on|off}, to enable output message with timestamp --- include/qemu/time.h | 11 +++++++++++ qemu-options.hx | 12 ++++++++++++ util/Makefile.objs | 1 + util/qemu-error.c | 8 ++++++++ util/qemu-time.c | 24 ++++++++++++++++++++++++ vl.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 include/qemu/time.h create mode 100644 util/qemu-time.c diff --git a/include/qemu/time.h b/include/qemu/time.h new file mode 100644 index 0000000..f70739b --- /dev/null +++ b/include/qemu/time.h @@ -0,0 +1,11 @@ +#ifndef TIME_H +#define TIME_H + +#include "qemu-common.h" + +/* "1970-01-01T00:00:00.999999Z" + '\0' */ +#define TIMESTAMP_LEN 28 +extern void qemu_get_timestamp_str(char (*timestr)[]); +extern bool enable_timestamp_msg; + +#endif /* !TIME_H */ diff --git a/qemu-options.hx b/qemu-options.hx index ca6fdf6..7890921 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3102,3 +3102,15 @@ HXCOMM This is the last statement. Insert new options before this line! STEXI @end table ETEXI + +DEF("msg", HAS_ARG, QEMU_OPTION_msg, + "-msg [timestamp=on|off]\n" + " output message with timestamp (default: off)\n", + QEMU_ARCH_ALL) +STEXI +@item -msg timestamp=on|off +@findex - msg +Output message with timestamp. +Adding timestamp to messages with @option{timestamp=on} +(disabled by default). +ETEXI diff --git a/util/Makefile.objs b/util/Makefile.objs index dc72ab0..063db56 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -11,3 +11,4 @@ util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o util-obj-y += hexdump.o util-obj-y += crc32c.o +util-obj-y += qemu-time.o diff --git a/util/qemu-error.c b/util/qemu-error.c index 08a36f4..33fa9d3 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -12,6 +12,7 @@ #include #include "monitor/monitor.h" +#include "qemu/time.h" /* * Print to current monitor if we have one, else to stderr. @@ -196,6 +197,7 @@ void error_print_loc(void) } } +bool enable_timestamp_msg; /* * Print an error message to current monitor if we have one, else to stderr. * Format arguments like sprintf(). The result should not contain @@ -206,6 +208,12 @@ void error_print_loc(void) void error_report(const char *fmt, ...) { va_list ap; + char timestr[TIMESTAMP_LEN]; + + if (enable_timestamp_msg) { + qemu_get_timestamp_str(×tr); + error_printf("%s ", timestr); + } error_print_loc(); va_start(ap, fmt); diff --git a/util/qemu-time.c b/util/qemu-time.c new file mode 100644 index 0000000..37f7b9e --- /dev/null +++ b/util/qemu-time.c @@ -0,0 +1,24 @@ +/* + * Time handling + * + * Copyright (C) 2013 Hitachi Data Systems Corp. + * + * Authors: + * Seiji Aguchi + * + * 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/time.h" + +void qemu_get_timestamp_str(char (*timestr)[]) +{ + GTimeVal tv; + gchar *tmp_str = NULL; + + g_get_current_time(&tv); + tmp_str = g_time_val_to_iso8601(&tv); + g_strlcpy((gchar *)*timestr, tmp_str, TIMESTAMP_LEN); + g_free(tmp_str); + return; +} diff --git a/vl.c b/vl.c index 0a8f056..aee7350 100644 --- a/vl.c +++ b/vl.c @@ -171,6 +171,8 @@ int main(int argc, char **argv) #include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" +#include "qemu/time.h" + //#define DEBUG_NET //#define DEBUG_SLIRP @@ -516,6 +518,18 @@ static QemuOptsList qemu_realtime_opts = { }, }; +static QemuOptsList qemu_msg_opts = { + .name = "msg", + .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), + .desc = { + { + .name = "timestamp", + .type = QEMU_OPT_BOOL, + }, + { /* end of list */ } + }, +}; + const char *qemu_get_vm_name(void) { return qemu_name; @@ -1459,6 +1473,12 @@ static void configure_realtime(QemuOpts *opts) } } + +static void configure_msg(QemuOpts *opts) +{ + enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true); +} + /***********************************************************/ /* USB devices */ @@ -2901,6 +2921,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_object_opts); qemu_add_opts(&qemu_tpmdev_opts); qemu_add_opts(&qemu_realtime_opts); + qemu_add_opts(&qemu_msg_opts); runstate_init(); @@ -3808,6 +3829,13 @@ int main(int argc, char **argv, char **envp) } configure_realtime(opts); break; + case QEMU_OPTION_msg: + opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0); + if (!opts) { + exit(1); + } + configure_msg(opts); + break; default: os_parse_cmd_args(popt->index, optarg); }