diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-03-15 15:51:46 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-03-16 00:10:06 +0100 |
commit | 8002d8a662d4db7cc8c833ac960179e05f1280ed (patch) | |
tree | 8501690a65b5953bb2f08aa69ad4bc4a41e4137e | |
parent | 5a0107638d07e287001d69a786591162dc62e5e2 (diff) | |
download | qemu-8002d8a662d4db7cc8c833ac960179e05f1280ed.tar.gz |
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.
-rw-r--r-- | net/dump.c | 8 |
1 files 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; } |