From 8002d8a662d4db7cc8c833ac960179e05f1280ed Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 15 Mar 2014 15:51:46 +0100 Subject: net/dump: simplify timestamp calculation The timestamp calculation in dump_receive is very unobvious now and looks completely arbitrary. qemu_clock_get_us already returns micro- seconds, so use that instead of manual calculating with nanoseconds. While at it, express the private start_ts field in microseconds too instead of seconds. This is supposed to yield a more accurate initial timestamp (based on host clock). NOTE: this patch ignores the RTC of the guest! Perhaps this part should be reverted. --- net/dump.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/dump.c b/net/dump.c index 9d3a09e334..d956dc1c19 100644 --- a/net/dump.c +++ b/net/dump.c @@ -69,10 +69,10 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) return size; } - ts = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 1000000, get_ticks_per_sec()); + ts = s->start_ts + qemu_clock_get_us(QEMU_CLOCK_VIRTUAL); caplen = size > s->pcap_caplen ? s->pcap_caplen : size; - hdr.ts.tv_sec = ts / 1000000 + s->start_ts; + hdr.ts.tv_sec = ts / 1000000; hdr.ts.tv_usec = ts % 1000000; hdr.caplen = caplen; hdr.len = size; @@ -106,7 +106,6 @@ static int net_dump_init(NetClientState *peer, const char *device, struct pcap_file_hdr hdr; NetClientState *nc; DumpState *s; - struct tm tm; int fd; fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644); @@ -139,8 +138,7 @@ static int net_dump_init(NetClientState *peer, const char *device, s->fd = fd; s->pcap_caplen = len; - qemu_get_timedate(&tm, 0); - s->start_ts = mktime(&tm); + s->start_ts = qemu_clock_get_us(QEMU_CLOCK_HOST); return 0; } -- cgit v1.2.1