@@ -343,6 +343,12 @@ typedef struct StatsData
343
343
SimpleStats lag ;
344
344
} StatsData ;
345
345
346
+ /*
347
+ * For displaying Unix epoch timestamps, as some time functions may have
348
+ * another reference.
349
+ */
350
+ pg_time_usec_t epoch_shift ;
351
+
346
352
/*
347
353
* Struct to keep random state.
348
354
*/
@@ -3772,16 +3778,17 @@ executeMetaCommand(CState *st, pg_time_usec_t *now)
3772
3778
* Print log entry after completing one transaction.
3773
3779
*
3774
3780
* We print Unix-epoch timestamps in the log, so that entries can be
3775
- * correlated against other logs. On some platforms this could be obtained
3776
- * from the caller, but rather than get entangled with that, we just eat
3777
- * the cost of an extra syscall in all cases.
3781
+ * correlated against other logs.
3782
+ *
3783
+ * XXX We could obtain the time from the caller and just shift it here, to
3784
+ * avoid the cost of an extra call to pg_time_now().
3778
3785
*/
3779
3786
static void
3780
3787
doLog (TState * thread , CState * st ,
3781
3788
StatsData * agg , bool skipped , double latency , double lag )
3782
3789
{
3783
3790
FILE * logfile = thread -> logfile ;
3784
- pg_time_usec_t now = pg_time_now ();
3791
+ pg_time_usec_t now = pg_time_now () + epoch_shift ;
3785
3792
3786
3793
Assert (use_log );
3787
3794
@@ -3796,17 +3803,19 @@ doLog(TState *thread, CState *st,
3796
3803
/* should we aggregate the results or not? */
3797
3804
if (agg_interval > 0 )
3798
3805
{
3806
+ pg_time_usec_t next ;
3807
+
3799
3808
/*
3800
3809
* Loop until we reach the interval of the current moment, and print
3801
3810
* any empty intervals in between (this may happen with very low tps,
3802
3811
* e.g. --rate=0.1).
3803
3812
*/
3804
3813
3805
- while (agg -> start_time + agg_interval <= now )
3814
+ while (( next = agg -> start_time + agg_interval * INT64CONST ( 1000000 )) <= now )
3806
3815
{
3807
3816
/* print aggregated report to logfile */
3808
3817
fprintf (logfile , INT64_FORMAT " " INT64_FORMAT " %.0f %.0f %.0f %.0f" ,
3809
- agg -> start_time ,
3818
+ agg -> start_time / 1000000 , /* seconds since Unix epoch */
3810
3819
agg -> cnt ,
3811
3820
agg -> latency .sum ,
3812
3821
agg -> latency .sum2 ,
@@ -3825,7 +3834,7 @@ doLog(TState *thread, CState *st,
3825
3834
fputc ('\n' , logfile );
3826
3835
3827
3836
/* reset data and move to next interval */
3828
- initStats (agg , agg -> start_time + agg_interval );
3837
+ initStats (agg , next );
3829
3838
}
3830
3839
3831
3840
/* accumulate the current transaction */
@@ -5458,7 +5467,8 @@ printProgressReport(TState *threads, int64 test_start, pg_time_usec_t now,
5458
5467
5459
5468
if (progress_timestamp )
5460
5469
{
5461
- snprintf (tbuf , sizeof (tbuf ), "%.3f s" , PG_TIME_GET_DOUBLE (now ));
5470
+ snprintf (tbuf , sizeof (tbuf ), "%.3f s" ,
5471
+ PG_TIME_GET_DOUBLE (now + epoch_shift ));
5462
5472
}
5463
5473
else
5464
5474
{
@@ -5808,6 +5818,14 @@ main(int argc, char **argv)
5808
5818
char * env ;
5809
5819
5810
5820
int exit_code = 0 ;
5821
+ struct timeval tv ;
5822
+
5823
+ /*
5824
+ * Record difference between Unix time and instr_time time. We'll use
5825
+ * this for logging and aggregation.
5826
+ */
5827
+ gettimeofday (& tv , NULL );
5828
+ epoch_shift = tv .tv_sec * INT64CONST (1000000 ) + tv .tv_usec - pg_time_now ();
5811
5829
5812
5830
pg_logging_init (argv [0 ]);
5813
5831
progname = get_progname (argv [0 ]);
@@ -6637,7 +6655,14 @@ threadRun(void *arg)
6637
6655
thread -> bench_start = start ;
6638
6656
thread -> throttle_trigger = start ;
6639
6657
6640
- initStats (& aggs , start );
6658
+ /*
6659
+ * The log format currently has Unix epoch timestamps with whole numbers
6660
+ * of seconds. Round the first aggregate's start time down to the nearest
6661
+ * Unix epoch second (the very first aggregate might really have started a
6662
+ * fraction of a second later, but later aggregates are measured from the
6663
+ * whole number time that is actually logged).
6664
+ */
6665
+ initStats (& aggs , (start + epoch_shift ) / 1000000 * 1000000 );
6641
6666
last = aggs ;
6642
6667
6643
6668
/* loop till all clients have terminated */
0 commit comments