@@ -164,6 +164,7 @@ bool use_log; /* log transaction latencies to a file */
164
164
bool use_quiet ; /* quiet logging onto stderr */
165
165
int agg_interval ; /* log aggregates instead of individual
166
166
* transactions */
167
+ bool per_script_stats = false; /* whether to collect stats per script */
167
168
int progress = 0 ; /* thread progress report every this seconds */
168
169
bool progress_timestamp = false; /* progress report with Unix time */
169
170
int nclients = 1 ; /* number of clients */
@@ -206,8 +207,8 @@ typedef struct SimpleStats
206
207
} SimpleStats ;
207
208
208
209
/*
209
- * Data structure to hold various statistics: per-thread stats are maintained
210
- * and merged together.
210
+ * Data structure to hold various statistics: per-thread and per-script stats
211
+ * are maintained and merged together.
211
212
*/
212
213
typedef struct StatsData
213
214
{
@@ -299,6 +300,7 @@ static struct
299
300
{
300
301
const char * name ;
301
302
Command * * commands ;
303
+ StatsData stats ;
302
304
} sql_script [MAX_SCRIPTS ]; /* SQL script files */
303
305
static int num_scripts ; /* number of scripts in sql_script[] */
304
306
static int num_commands = 0 ; /* total number of Command structs */
@@ -1358,7 +1360,8 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
1358
1360
/* transaction finished: calculate latency and log the transaction */
1359
1361
if (commands [st -> state + 1 ] == NULL )
1360
1362
{
1361
- if (progress || throttle_delay || latency_limit || logfile )
1363
+ if (progress || throttle_delay || latency_limit ||
1364
+ per_script_stats || logfile )
1362
1365
processXactStats (thread , st , & now , false, logfile , agg );
1363
1366
else
1364
1367
thread -> stats .cnt ++ ;
@@ -1451,7 +1454,7 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
1451
1454
}
1452
1455
1453
1456
/* Record transaction start time under logging, progress or throttling */
1454
- if ((logfile || progress || throttle_delay || latency_limit ) && st -> state == 0 )
1457
+ if ((logfile || progress || throttle_delay || latency_limit || per_script_stats ) && st -> state == 0 )
1455
1458
{
1456
1459
INSTR_TIME_SET_CURRENT (st -> txn_begin );
1457
1460
@@ -1904,6 +1907,10 @@ processXactStats(TState *thread, CState *st, instr_time *now,
1904
1907
1905
1908
if (use_log )
1906
1909
doLog (thread , st , logfile , now , agg , skipped , latency , lag );
1910
+
1911
+ /* XXX could use a mutex here, but we choose not to */
1912
+ if (per_script_stats )
1913
+ accumStats (& sql_script [st -> use_file ].stats , skipped , latency , lag );
1907
1914
}
1908
1915
1909
1916
@@ -2693,6 +2700,7 @@ addScript(const char *name, Command **commands)
2693
2700
2694
2701
sql_script [num_scripts ].name = name ;
2695
2702
sql_script [num_scripts ].commands = commands ;
2703
+ initStats (& sql_script [num_scripts ].stats , 0.0 );
2696
2704
num_scripts ++ ;
2697
2705
}
2698
2706
@@ -2776,22 +2784,43 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
2776
2784
printf ("tps = %f (including connections establishing)\n" , tps_include );
2777
2785
printf ("tps = %f (excluding connections establishing)\n" , tps_exclude );
2778
2786
2779
- /* Report per-command latencies */
2780
- if (is_latencies )
2787
+ /* Report per-command statistics */
2788
+ if (per_script_stats )
2781
2789
{
2782
2790
int i ;
2783
2791
2784
2792
for (i = 0 ; i < num_scripts ; i ++ )
2785
2793
{
2786
- Command * * commands ;
2794
+ printf ("SQL script %d: %s\n"
2795
+ " - " INT64_FORMAT " transactions (%.1f%% of total, tps = %f)\n" ,
2796
+ i + 1 , sql_script [i ].name ,
2797
+ sql_script [i ].stats .cnt ,
2798
+ 100.0 * sql_script [i ].stats .cnt / total -> cnt ,
2799
+ sql_script [i ].stats .cnt / time_include );
2800
+
2801
+ if (latency_limit )
2802
+ printf (" - number of transactions skipped: " INT64_FORMAT " (%.3f%%)\n" ,
2803
+ sql_script [i ].stats .skipped ,
2804
+ 100.0 * sql_script [i ].stats .skipped /
2805
+ (sql_script [i ].stats .skipped + sql_script [i ].stats .cnt ));
2806
+
2807
+ printSimpleStats (" - latency" , & sql_script [i ].stats .latency );
2787
2808
2788
- printf ("SQL script %d: %s\n" , i + 1 , sql_script [i ].name );
2789
- printf (" - statement latencies in milliseconds:\n" );
2809
+ /* Report per-command latencies */
2810
+ if (is_latencies )
2811
+ {
2812
+ Command * * commands ;
2813
+
2814
+ printf (" - statement latencies in milliseconds:\n" );
2790
2815
2791
- for (commands = sql_script [i ].commands ; * commands != NULL ; commands ++ )
2792
- printf (" %11.3f %s\n" ,
2793
- 1000.0 * (* commands )-> stats .sum / (* commands )-> stats .count ,
2794
- (* commands )-> line );
2816
+ for (commands = sql_script [i ].commands ;
2817
+ * commands != NULL ;
2818
+ commands ++ )
2819
+ printf (" %11.3f %s\n" ,
2820
+ 1000.0 * (* commands )-> stats .sum /
2821
+ (* commands )-> stats .count ,
2822
+ (* commands )-> line );
2823
+ }
2795
2824
}
2796
2825
}
2797
2826
}
@@ -2977,6 +3006,7 @@ main(int argc, char **argv)
2977
3006
break ;
2978
3007
case 'r' :
2979
3008
benchmarking_option_set = true;
3009
+ per_script_stats = true;
2980
3010
is_latencies = true;
2981
3011
break ;
2982
3012
case 's' :
@@ -3200,6 +3230,10 @@ main(int argc, char **argv)
3200
3230
internal_script_used = true;
3201
3231
}
3202
3232
3233
+ /* show per script stats if several scripts are used */
3234
+ if (num_scripts > 1 )
3235
+ per_script_stats = true;
3236
+
3203
3237
/*
3204
3238
* Don't need more threads than there are clients. (This is not merely an
3205
3239
* optimization; throttle_delay is calculated incorrectly below if some
0 commit comments