mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-29 09:59:08 -04:00
dig: Use high resolution clocks when microsecond accuracy is requested
The TIME_NOW macro calls isc_time_now which uses CLOCK_REALTIME_COARSE
for getting the current time. This is perfectly fine for millisecond,
however when the user request microsecond resolutiuon, they are going
to get very inaccurate results. This is especially true on a server
class machine where the clock ticks may be set to 100HZ.
This changes dig to use the new TIME_NOW_HIRES macro that uses the
CLOCK_MONOTONIC_RAW that is more expensive, but gets the *actual*
current time rather than the at the last kernel time tick.
(cherry picked from commit 56cef1495f)
This commit is contained in:
parent
c5c9c9b83f
commit
702edde73a
2 changed files with 20 additions and 4 deletions
|
|
@ -2935,7 +2935,11 @@ send_udp(dig_query_t *query) {
|
|||
}
|
||||
isc_buffer_usedregion(&query->sendbuf, &r);
|
||||
debug("sending a request");
|
||||
TIME_NOW(&query->time_sent);
|
||||
if (query->lookup->use_usec) {
|
||||
TIME_NOW_HIRES(&query->time_sent);
|
||||
} else {
|
||||
TIME_NOW(&query->time_sent);
|
||||
}
|
||||
INSIST(query->sock != NULL);
|
||||
query->waiting_senddone = true;
|
||||
sevent = isc_socket_socketevent(
|
||||
|
|
@ -3217,7 +3221,11 @@ launch_next_query(dig_query_t *query, bool include_question) {
|
|||
debug("recvcount=%d", recvcount);
|
||||
if (!query->first_soa_rcvd) {
|
||||
debug("sending a request in launch_next_query");
|
||||
TIME_NOW(&query->time_sent);
|
||||
if (query->lookup->use_usec) {
|
||||
TIME_NOW_HIRES(&query->time_sent);
|
||||
} else {
|
||||
TIME_NOW(&query->time_sent);
|
||||
}
|
||||
query->waiting_senddone = true;
|
||||
isc_buffer_clear(&query->tmpsendbuf);
|
||||
isc_buffer_putuint16(&query->tmpsendbuf,
|
||||
|
|
@ -3623,7 +3631,11 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
|||
INSIST(recvcount >= 0);
|
||||
|
||||
query = event->ev_arg;
|
||||
TIME_NOW(&query->time_recv);
|
||||
if (query->lookup->use_usec) {
|
||||
TIME_NOW_HIRES(&query->time_recv);
|
||||
} else {
|
||||
TIME_NOW(&query->time_recv);
|
||||
}
|
||||
|
||||
l = query->lookup;
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,11 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
|||
if (!short_form) {
|
||||
char fromtext[ISC_SOCKADDR_FORMATSIZE];
|
||||
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
|
||||
TIME_NOW(&now);
|
||||
if (query->lookup->use_usec) {
|
||||
TIME_NOW_HIRES(&now);
|
||||
} else {
|
||||
TIME_NOW(&now);
|
||||
}
|
||||
diff = (int)isc_time_microdiff(&now, &query->time_sent);
|
||||
printf("Received %u bytes from %s in %d ms\n", bytes, fromtext,
|
||||
diff / 1000);
|
||||
|
|
|
|||
Loading…
Reference in a new issue