[LTP] [PATCH] fs/fsx-linux/fsx-linux.c: Add measurement of execution time

Cyril Hrubis chrubis@suse.cz
Thu Aug 10 10:04:40 CEST 2023


Hi!
> Signed-off-by: Xin.Wang@windriver.com
> ---
>  testcases/kernel/fs/fsx-linux/fsx-linux.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/fs/fsx-linux/fsx-linux.c b/testcases/kernel/fs/fsx-linux/fsx-linux.c
> index 64c27a0f5..71b719782 100644
> --- a/testcases/kernel/fs/fsx-linux/fsx-linux.c
> +++ b/testcases/kernel/fs/fsx-linux/fsx-linux.c
> @@ -1115,7 +1115,8 @@ int main(int argc, char **argv)
>  	int i, style, ch;
>  	char *endp;
>  	int dirpath = 0;
> -
> +	struct timeval time_start, time_end, time_diff;
> +	
>  	goodfile[0] = 0;
>  	logfile[0] = 0;
>  
> @@ -1336,12 +1337,24 @@ int main(int argc, char **argv)
>  	} else
>  		check_trunc_hack();
>  
> +	gettimeofday(&time_start, NULL);

gettimeofday() is not a good way how to measure elapsed time, it may
jump up and down as it's adjusted by ntp-daemon.

If you want to measure time between two events you should use
clock_gettime() with CLOCK_MONOTONIC_RAW instead.

>  	while (numops == -1 || numops--)
>  		test();
>  
>  	close_test_files();
> +	gettimeofday(&time_end, NULL);
> +
>  	prt("All operations completed A-OK!\n");
>  
> +	time_diff.tv_sec = time_end.tv_sec - time_start.tv_sec;
> +	time_diff.tv_usec = time_end.tv_usec - time_start.tv_usec;
> +	if (time_diff.tv_usec < 0) {
> +		time_diff.tv_usec += 1000000;
> +		time_diff.tv_sec -= 1; 
> +	}
> +	prt("Elapsed Test Time %lu.%06lu\n",
> +        (unsigned long)time_diff.tv_sec, time_diff.tv_usec);
> +	
>  	if (tf_buf)
>  		free(tf_buf);
>  
> -- 
> 2.34.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list