All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
@ 2015-05-20  6:29 Gonglei (Arei)
  2015-05-20  9:00 ` Daniel P. Berrange
  2015-05-20 14:43 ` Eric Blake
  0 siblings, 2 replies; 6+ messages in thread
From: Gonglei (Arei) @ 2015-05-20  6:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Huangpeng (Peter), Herongguang (Stephen)

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.


Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
  2015-05-20  6:29 [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu Gonglei (Arei)
@ 2015-05-20  9:00 ` Daniel P. Berrange
  2015-05-20  9:28   ` Gonglei
  2015-05-20 14:43 ` Eric Blake
  1 sibling, 1 reply; 6+ messages in thread
From: Daniel P. Berrange @ 2015-05-20  9:00 UTC (permalink / raw)
  To: Gonglei (Arei); +Cc: Herongguang (Stephen), qemu-devel, Huangpeng (Peter)

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

commit 3ec128989606278635a7c5dfbeee959692d12e15
Author: Daniel P. Berrange <berrange@redhat.com>
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
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
  2015-05-20  9:00 ` Daniel P. Berrange
@ 2015-05-20  9:28   ` Gonglei
  0 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2015-05-20  9:28 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: Herongguang (Stephen), qemu-devel, 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 <berrange@redhat.com>
> 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
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
  2015-05-20  6:29 [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu Gonglei (Arei)
  2015-05-20  9:00 ` Daniel P. Berrange
@ 2015-05-20 14:43 ` Eric Blake
  2015-05-21  2:10   ` Gonglei
  2015-05-21  3:04   ` Eric Blake
  1 sibling, 2 replies; 6+ messages in thread
From: Eric Blake @ 2015-05-20 14:43 UTC (permalink / raw)
  To: Gonglei (Arei), qemu-devel; +Cc: Huangpeng (Peter), Herongguang (Stephen)

[-- Attachment #1: Type: text/plain, Size: 1571 bytes --]

On 05/20/2015 12:29 AM, 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. 

local time is ambiguous (daylight savings, and even consider what
happens when you physically relocate your machine to a different time
zone).  UTC is better.

> 
> 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? 

Actually, libvirt uses UTC on purpose, not only because it is
unambiguous, but because it prints timestamps even in situations where
it must be async-signal safe, and there is no async-signal-safe way to
determine the offset required to convert UTC to local time.

> 
> Any thoughts? Thanks.

I'd rather stick with UTC in logs (but perhaps make it more obvious that
the timestamp is UTC by actually sticking that string as part of the
timestamp - libvirt is not currently doing that).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
  2015-05-20 14:43 ` Eric Blake
@ 2015-05-21  2:10   ` Gonglei
  2015-05-21  3:04   ` Eric Blake
  1 sibling, 0 replies; 6+ messages in thread
From: Gonglei @ 2015-05-21  2:10 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: Huangpeng (Peter), Herongguang (Stephen)

On 2015/5/20 22:43, Eric Blake wrote:
> On 05/20/2015 12:29 AM, 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. 
> 
> local time is ambiguous (daylight savings, and even consider what
> happens when you physically relocate your machine to a different time
> zone).  UTC is better.
> 
Actually this is a scenario that happen unlikely. :(
>>
>> 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? 
> 
> Actually, libvirt uses UTC on purpose, not only because it is
> unambiguous, but because it prints timestamps even in situations where
> it must be async-signal safe, and there is no async-signal-safe way to
> determine the offset required to convert UTC to local time.
> 
Yes, I got it.
>>
>> Any thoughts? Thanks.
> 
> I'd rather stick with UTC in logs (but perhaps make it more obvious that
> the timestamp is UTC by actually sticking that string as part of the
> timestamp - libvirt is not currently doing that).
> 
OK, I agree, will post a patch to Qemu maillist.

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu
  2015-05-20 14:43 ` Eric Blake
  2015-05-21  2:10   ` Gonglei
@ 2015-05-21  3:04   ` Eric Blake
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Blake @ 2015-05-21  3:04 UTC (permalink / raw)
  To: Gonglei (Arei), qemu-devel; +Cc: Huangpeng (Peter), Herongguang (Stephen)

[-- Attachment #1: Type: text/plain, Size: 809 bytes --]

On 05/20/2015 08:43 AM, Eric Blake wrote:

> 
> I'd rather stick with UTC in logs (but perhaps make it more obvious that
> the timestamp is UTC by actually sticking that string as part of the
> timestamp - libvirt is not currently doing that).

Actually, here's a libvirt log timestamp:
2015-05-17 02:29:06.931+0000: shutting down

which includes the timezone offset (so while it doesn't state "UTC", it
DOES state an unambiguous timezone, which happens to be UTC).

Compare that to a qemu timestamp:
   (qemu) 2015-05-21T02:07:43.695065Z qemu-system-x86_64: test....

which is ALSO unambiguous (the trailing "Z" _is_ the UTC timezone).
https://en.wikipedia.org/wiki/ISO_8601#UTC

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-21  3:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20  6:29 [Qemu-devel] [RFC] Can we convert UTC time to local time in Qemu Gonglei (Arei)
2015-05-20  9:00 ` Daniel P. Berrange
2015-05-20  9:28   ` Gonglei
2015-05-20 14:43 ` Eric Blake
2015-05-21  2:10   ` Gonglei
2015-05-21  3:04   ` Eric Blake

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.