From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv0L2-00087g-PE for qemu-devel@nongnu.org; Wed, 20 May 2015 05:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yv0Kz-00041x-If for qemu-devel@nongnu.org; Wed, 20 May 2015 05:30:56 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:40855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv0Kz-0003uK-0g for qemu-devel@nongnu.org; Wed, 20 May 2015 05:30:53 -0400 Message-ID: <555C53D8.707@huawei.com> Date: Wed, 20 May 2015 17:28:56 +0800 From: Gonglei MIME-Version: 1.0 References: <33183CC9F5247A488A2544077AF1902086E86BFF@SZXEMA503-MBS.china.huawei.com> <20150520090043.GD23989@redhat.com> In-Reply-To: <20150520090043.GD23989@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: "Herongguang (Stephen)" , "qemu-devel@nongnu.org" , "Huangpeng (Peter)" On 2015/5/20 17:00, Daniel P. Berrange wrote: > On Wed, May 20, 2015 at 06:29:55AM +0000, Gonglei (Arei) wrote: >> Hi, >> >> At present, Qemu use g_time_val_to_iso8601() to get the UTC added to error_report() >> (commit 5e2ac5191), TBH this way is very simply, we just need invoke standard glib functions to >> complete the job. >> >> But in the cloud computing and data center scenarios, there are many >> Other open source components, such as kernel, libvirt, openstack which are all using local time >> to record the message logs, only Qemu is using the UTC time. When we want to find a error >> message of Qemu, we should convert the UTC time to local time manually, and unfortunately >> different countries have different local time, what a trouble thing the converting is. >> >> So, my question is: Can we convert the UTC time to local time in Qemu? >> >> Any thoughts? Thanks. > > Actually, libvirt uses UTC for logging almost exclusively for quite a > while, because AFAIK, there is no async signal safe way to convert to > localtime in POSIX / glibc > Thanks for correcting me :) Regards, -Gonglei > commit 3ec128989606278635a7c5dfbeee959692d12e15 > Author: Daniel P. Berrange > Date: Tue Nov 29 12:11:01 2011 +0000 > > Add internal APIs for dealing with time > > The logging APIs need to be able to generate formatted timestamps > using only async signal safe functions. This rules out using > gmtime/localtime/malloc/gettimeday(!) and much more. > > Introduce a new internal API which is async signal safe. > > virTimeMillisNowRaw replacement for gettimeofday. Uses clock_gettime > where available, otherwise falls back to the unsafe > gettimeofday > > virTimeFieldsNowRaw replacements for gmtime(), convert a timestamp > virTimeFieldsThenRaw into a broken out set of fields. No localtime() > replacement is provided, because converting to > local time is not practical with only async signal > safe APIs. > > virTimeStringNowRaw replacements for strftime() which print a timestamp > virTimeStringThenRaw into a string, using a pre-determined format, with > a fixed size buffer (VIR_TIME_STRING_BUFLEN) > > For each of these there is also a version without the Raw postfix > which raises a full libvirt error. These versions are not async > signal safe > > Regards, > Daniel >