Skip to content

Commit 132d41e

Browse files
kbleesgitster
authored andcommitted
wt-status: simplify performance measurement by using getnanotime()
Calculating duration from a single uint64_t is simpler than from a struct timeval. Change performance measurement for 'advice.statusuoption' from gettimeofday() to getnanotime(). Also initialize t_begin to prevent uninitialized variable warning. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 578da03 commit 132d41e

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

wt-status.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,11 @@ static void wt_status_collect_untracked(struct wt_status *s)
574574
{
575575
int i;
576576
struct dir_struct dir;
577-
struct timeval t_begin;
577+
uint64_t t_begin = getnanotime();
578578

579579
if (!s->show_untracked_files)
580580
return;
581581

582-
if (advice_status_u_option)
583-
gettimeofday(&t_begin, NULL);
584-
585582
memset(&dir, 0, sizeof(dir));
586583
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
587584
dir.flags |=
@@ -612,13 +609,8 @@ static void wt_status_collect_untracked(struct wt_status *s)
612609
free(dir.ignored);
613610
clear_directory(&dir);
614611

615-
if (advice_status_u_option) {
616-
struct timeval t_end;
617-
gettimeofday(&t_end, NULL);
618-
s->untracked_in_ms =
619-
(uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 -
620-
((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000);
621-
}
612+
if (advice_status_u_option)
613+
s->untracked_in_ms = (getnanotime() - t_begin) / 1000000;
622614
}
623615

624616
void wt_status_collect(struct wt_status *s)

0 commit comments

Comments
 (0)