@@ -3664,27 +3664,32 @@ addScript(ParsedScript script)
3664
3664
static void
3665
3665
printSimpleStats (const char * prefix , SimpleStats * ss )
3666
3666
{
3667
- /* print NaN if no transactions where executed */
3668
- double latency = ss -> sum / ss -> count ;
3669
- double stddev = sqrt (ss -> sum2 / ss -> count - latency * latency );
3667
+ if (ss -> count > 0 )
3668
+ {
3669
+ double latency = ss -> sum / ss -> count ;
3670
+ double stddev = sqrt (ss -> sum2 / ss -> count - latency * latency );
3670
3671
3671
- printf ("%s average = %.3f ms\n" , prefix , 0.001 * latency );
3672
- printf ("%s stddev = %.3f ms\n" , prefix , 0.001 * stddev );
3672
+ printf ("%s average = %.3f ms\n" , prefix , 0.001 * latency );
3673
+ printf ("%s stddev = %.3f ms\n" , prefix , 0.001 * stddev );
3674
+ }
3673
3675
}
3674
3676
3675
3677
/* print out results */
3676
3678
static void
3677
3679
printResults (TState * threads , StatsData * total , instr_time total_time ,
3678
- instr_time conn_total_time , int latency_late )
3680
+ instr_time conn_total_time , int64 latency_late )
3679
3681
{
3680
3682
double time_include ,
3681
3683
tps_include ,
3682
3684
tps_exclude ;
3685
+ int64 ntx = total -> cnt - total -> skipped ;
3683
3686
3684
3687
time_include = INSTR_TIME_GET_DOUBLE (total_time );
3685
- tps_include = total -> cnt / time_include ;
3686
- tps_exclude = total -> cnt / (time_include -
3687
- (INSTR_TIME_GET_DOUBLE (conn_total_time ) / nclients ));
3688
+
3689
+ /* tps is about actually executed transactions */
3690
+ tps_include = ntx / time_include ;
3691
+ tps_exclude = ntx /
3692
+ (time_include - (INSTR_TIME_GET_DOUBLE (conn_total_time ) / nclients ));
3688
3693
3689
3694
/* Report test parameters. */
3690
3695
printf ("transaction type: %s\n" ,
@@ -3697,13 +3702,13 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
3697
3702
{
3698
3703
printf ("number of transactions per client: %d\n" , nxacts );
3699
3704
printf ("number of transactions actually processed: " INT64_FORMAT "/%d\n" ,
3700
- total -> cnt - total -> skipped , nxacts * nclients );
3705
+ ntx , nxacts * nclients );
3701
3706
}
3702
3707
else
3703
3708
{
3704
3709
printf ("duration: %d s\n" , duration );
3705
3710
printf ("number of transactions actually processed: " INT64_FORMAT "\n" ,
3706
- total -> cnt );
3711
+ ntx );
3707
3712
}
3708
3713
3709
3714
/* Remaining stats are nonsensical if we failed to execute any xacts */
@@ -3716,9 +3721,9 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
3716
3721
100.0 * total -> skipped / total -> cnt );
3717
3722
3718
3723
if (latency_limit )
3719
- printf ("number of transactions above the %.1f ms latency limit: %d (%.3f %%)\n" ,
3720
- latency_limit / 1000.0 , latency_late ,
3721
- 100.0 * latency_late / total -> cnt );
3724
+ printf ("number of transactions above the %.1f ms latency limit: " INT64_FORMAT "/" INT64_FORMAT " (%.3f %%)\n" ,
3725
+ latency_limit / 1000.0 , latency_late , ntx ,
3726
+ ( ntx > 0 ) ? 100.0 * latency_late / ntx : 0.0 );
3722
3727
3723
3728
if (throttle_delay || progress || latency_limit )
3724
3729
printSimpleStats ("latency" , & total -> latency );
@@ -3745,47 +3750,55 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
3745
3750
printf ("tps = %f (excluding connections establishing)\n" , tps_exclude );
3746
3751
3747
3752
/* Report per-script/command statistics */
3748
- if (per_script_stats || latency_limit || is_latencies )
3753
+ if (per_script_stats || is_latencies )
3749
3754
{
3750
3755
int i ;
3751
3756
3752
3757
for (i = 0 ; i < num_scripts ; i ++ )
3753
3758
{
3754
- if (num_scripts > 1 )
3759
+ if (per_script_stats )
3760
+ {
3761
+ StatsData * sstats = & sql_script [i ].stats ;
3762
+
3755
3763
printf ("SQL script %d: %s\n"
3756
3764
" - weight: %d (targets %.1f%% of total)\n"
3757
3765
" - " INT64_FORMAT " transactions (%.1f%% of total, tps = %f)\n" ,
3758
3766
i + 1 , sql_script [i ].desc ,
3759
3767
sql_script [i ].weight ,
3760
3768
100.0 * sql_script [i ].weight / total_weight ,
3761
- sql_script [i ].stats .cnt ,
3762
- 100.0 * sql_script [i ].stats .cnt / total -> cnt ,
3763
- sql_script [i ].stats .cnt / time_include );
3764
- else
3765
- printf ("script statistics:\n" );
3769
+ sstats -> cnt ,
3770
+ 100.0 * sstats -> cnt / total -> cnt ,
3771
+ (sstats -> cnt - sstats -> skipped ) / time_include );
3766
3772
3767
- if (latency_limit )
3768
- printf (" - number of transactions skipped: " INT64_FORMAT " (%.3f%%)\n" ,
3769
- sql_script [ i ]. stats . skipped ,
3770
- 100.0 * sql_script [ i ]. stats . skipped / sql_script [ i ]. stats . cnt );
3773
+ if (throttle_delay && latency_limit && sstats -> cnt > 0 )
3774
+ printf (" - number of transactions skipped: " INT64_FORMAT " (%.3f%%)\n" ,
3775
+ sstats -> skipped ,
3776
+ 100.0 * sstats -> skipped / sstats -> cnt );
3771
3777
3772
- if ( num_scripts > 1 )
3773
- printSimpleStats ( " - latency" , & sql_script [ i ]. stats . latency );
3778
+ printSimpleStats ( " - latency" , & sstats -> latency );
3779
+ }
3774
3780
3775
3781
/* Report per-command latencies */
3776
3782
if (is_latencies )
3777
3783
{
3778
3784
Command * * commands ;
3779
3785
3780
- printf (" - statement latencies in milliseconds:\n" );
3786
+ if (per_script_stats )
3787
+ printf (" - statement latencies in milliseconds:\n" );
3788
+ else
3789
+ printf ("statement latencies in milliseconds:\n" );
3781
3790
3782
3791
for (commands = sql_script [i ].commands ;
3783
3792
* commands != NULL ;
3784
3793
commands ++ )
3794
+ {
3795
+ SimpleStats * cstats = & (* commands )-> stats ;
3796
+
3785
3797
printf (" %11.3f %s\n" ,
3786
- 1000.0 * ( * commands ) -> stats . sum /
3787
- ( * commands ) -> stats . count ,
3798
+ ( cstats -> count > 0 ) ?
3799
+ 1000.0 * cstats -> sum / cstats -> count : 0.0 ,
3788
3800
(* commands )-> line );
3801
+ }
3789
3802
}
3790
3803
}
3791
3804
}
@@ -3984,7 +3997,6 @@ main(int argc, char **argv)
3984
3997
break ;
3985
3998
case 'r' :
3986
3999
benchmarking_option_set = true;
3987
- per_script_stats = true;
3988
4000
is_latencies = true;
3989
4001
break ;
3990
4002
case 's' :
@@ -4861,7 +4873,8 @@ threadRun(void *arg)
4861
4873
{
4862
4874
/* generate and show report */
4863
4875
StatsData cur ;
4864
- int64 run = now - last_report ;
4876
+ int64 run = now - last_report ,
4877
+ ntx ;
4865
4878
double tps ,
4866
4879
total_run ,
4867
4880
latency ,
@@ -4876,7 +4889,7 @@ threadRun(void *arg)
4876
4889
* XXX: No locking. There is no guarantee that we get an
4877
4890
* atomic snapshot of the transaction count and latencies, so
4878
4891
* these figures can well be off by a small amount. The
4879
- * progress is report's purpose is to give a quick overview of
4892
+ * progress report's purpose is to give a quick overview of
4880
4893
* how the test is going, so that shouldn't matter too much.
4881
4894
* (If a read from a 64-bit integer is not atomic, you might
4882
4895
* get a "torn" read and completely bogus latencies though!)
@@ -4890,15 +4903,21 @@ threadRun(void *arg)
4890
4903
cur .skipped += thread [i ].stats .skipped ;
4891
4904
}
4892
4905
4906
+ /* we count only actually executed transactions */
4907
+ ntx = (cur .cnt - cur .skipped ) - (last .cnt - last .skipped );
4893
4908
total_run = (now - thread_start ) / 1000000.0 ;
4894
- tps = 1000000.0 * (cur .cnt - last .cnt ) / run ;
4895
- latency = 0.001 * (cur .latency .sum - last .latency .sum ) /
4896
- (cur .cnt - last .cnt );
4897
- sqlat = 1.0 * (cur .latency .sum2 - last .latency .sum2 )
4898
- / (cur .cnt - last .cnt );
4899
- stdev = 0.001 * sqrt (sqlat - 1000000.0 * latency * latency );
4900
- lag = 0.001 * (cur .lag .sum - last .lag .sum ) /
4901
- (cur .cnt - last .cnt );
4909
+ tps = 1000000.0 * ntx / run ;
4910
+ if (ntx > 0 )
4911
+ {
4912
+ latency = 0.001 * (cur .latency .sum - last .latency .sum ) / ntx ;
4913
+ sqlat = 1.0 * (cur .latency .sum2 - last .latency .sum2 ) / ntx ;
4914
+ stdev = 0.001 * sqrt (sqlat - 1000000.0 * latency * latency );
4915
+ lag = 0.001 * (cur .lag .sum - last .lag .sum ) / ntx ;
4916
+ }
4917
+ else
4918
+ {
4919
+ latency = sqlat = stdev = lag = 0 ;
4920
+ }
4902
4921
4903
4922
if (progress_timestamp )
4904
4923
{
@@ -4915,7 +4934,10 @@ threadRun(void *arg)
4915
4934
(long ) tv .tv_sec , (long ) (tv .tv_usec / 1000 ));
4916
4935
}
4917
4936
else
4937
+ {
4938
+ /* round seconds are expected, but the thread may be late */
4918
4939
snprintf (tbuf , sizeof (tbuf ), "%.1f s" , total_run );
4940
+ }
4919
4941
4920
4942
fprintf (stderr ,
4921
4943
"progress: %s, %.1f tps, lat %.3f ms stddev %.3f" ,
0 commit comments