Re: [PATCH v4 06/21] test-date: add a subcommand to measure times in shell scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Johannes Schindelin via GitGitGadget" <gitgitgadget@xxxxxxxxx>
writes:

> From: Johannes Schindelin <johannes.schindelin@xxxxxx>
>
> In the next commit, we want to teach Git's test suite to optionally
> output test results in JUnit-style .xml files. These files contain
> information about the time spent. So we need a way to measure time.
>
> While we could use `date +%s` for that, this will give us only seconds,
> i.e. very coarse-grained timings.
>
> GNU `date` supports `date +%s.%N` (i.e. nanosecond-precision output),
> but there is no equivalent in BSD `date` (read: on macOS, we would not
> be able to obtain precise timings).
>
> So let's introduce `test-tool date getnanos`, with an optional start
> time, that outputs preciser values.

I think the goal to have our own stopwatch so that we do not have to
worry about differences among system-provided ones makes sense.

The only thing that may become an issue is how widely available
getnanotime() is.  As "test-date" itself is built on any platform an
end-user/developer runs our tests, which is wider set of platforms
than what we run Travis and other CIs on, unconditionally relying on
its availability might pose an issue.  I dunno.

> diff --git a/t/helper/test-date.c b/t/helper/test-date.c
> index a0837371ab..792a805374 100644
> --- a/t/helper/test-date.c
> +++ b/t/helper/test-date.c
> @@ -7,6 +7,7 @@ static const char *usage_msg = "\n"
>  "  test-tool date parse [date]...\n"
>  "  test-tool date approxidate [date]...\n"
>  "  test-tool date timestamp [date]...\n"
> +"  test-tool date getnanos [start-nanos]\n"
>  "  test-tool date is64bit\n"
>  "  test-tool date time_t-is64bit\n";
>  
> @@ -82,6 +83,15 @@ static void parse_approx_timestamp(const char **argv, struct timeval *now)
>  	}
>  }
>  
> +static void getnanos(const char **argv, struct timeval *now)
> +{
> +	double seconds = getnanotime() / 1.0e9;
> +
> +	if (*argv)
> +		seconds -= strtod(*argv, NULL);
> +	printf("%lf\n", seconds);
> +}
> +
>  int cmd__date(int argc, const char **argv)
>  {
>  	struct timeval now;
> @@ -108,6 +118,8 @@ int cmd__date(int argc, const char **argv)
>  		parse_approxidate(argv+1, &now);
>  	else if (!strcmp(*argv, "timestamp"))
>  		parse_approx_timestamp(argv+1, &now);
> +	else if (!strcmp(*argv, "getnanos"))
> +		getnanos(argv+1, &now);
>  	else if (!strcmp(*argv, "is64bit"))
>  		return sizeof(timestamp_t) == 8 ? 0 : 1;
>  	else if (!strcmp(*argv, "time_t-is64bit"))



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux