Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d0c3b3

Browse files
committed
pgbench: allow per-script statistics
Provide per-script statistical info (count of transactions executedunder that script, average latency for the whole script) after amulti-script run, adding an intermediate level of detail to existingglobal stats and per-command stats.Author: Fabien CoelhoReviewer: Michaël Paquier, Álvaro Herrera
1 parent64f5edc commit1d0c3b3

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,9 @@ number of transactions actually processed: 10000/10000
11381138
tps = 618.764555 (including connections establishing)
11391139
tps = 622.977698 (excluding connections establishing)
11401140
SQL script 1: <builtin: TPC-B (sort of)>
1141+
- 10000 transactions (100.0% of total, tps = 618.764555)
1142+
- latency average = 15.844 ms
1143+
- latency stddev = 2.715 ms
11411144
- statement latencies in milliseconds:
11421145
0.004386 \set nbranches 1 * :scale
11431146
0.001343 \set ntellers 10 * :scale

‎src/bin/pgbench/pgbench.c

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ booluse_log;/* log transaction latencies to a file */
164164
booluse_quiet;/* quiet logging onto stderr */
165165
intagg_interval;/* log aggregates instead of individual
166166
* transactions */
167+
boolper_script_stats= false;/* whether to collect stats per script */
167168
intprogress=0;/* thread progress report every this seconds */
168169
boolprogress_timestamp= false;/* progress report with Unix time */
169170
intnclients=1;/* number of clients */
@@ -206,8 +207,8 @@ typedef struct SimpleStats
206207
}SimpleStats;
207208

208209
/*
209-
* Data structure to hold various statistics: per-threadstats are maintained
210-
* and merged together.
210+
* Data structure to hold various statistics: per-threadand per-script stats
211+
*are maintainedand merged together.
211212
*/
212213
typedefstructStatsData
213214
{
@@ -299,6 +300,7 @@ static struct
299300
{
300301
constchar*name;
301302
Command**commands;
303+
StatsDatastats;
302304
}sql_script[MAX_SCRIPTS];/* SQL script files */
303305
staticintnum_scripts;/* number of scripts in sql_script[] */
304306
staticintnum_commands=0;/* total number of Command structs */
@@ -1358,7 +1360,8 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
13581360
/* transaction finished: calculate latency and log the transaction */
13591361
if (commands[st->state+1]==NULL)
13601362
{
1361-
if (progress||throttle_delay||latency_limit||logfile)
1363+
if (progress||throttle_delay||latency_limit||
1364+
per_script_stats||logfile)
13621365
processXactStats(thread,st,&now, false,logfile,agg);
13631366
else
13641367
thread->stats.cnt++;
@@ -1451,7 +1454,7 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
14511454
}
14521455

14531456
/* 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)
14551458
{
14561459
INSTR_TIME_SET_CURRENT(st->txn_begin);
14571460

@@ -1904,6 +1907,10 @@ processXactStats(TState *thread, CState *st, instr_time *now,
19041907

19051908
if (use_log)
19061909
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);
19071914
}
19081915

19091916

@@ -2693,6 +2700,7 @@ addScript(const char *name, Command **commands)
26932700

26942701
sql_script[num_scripts].name=name;
26952702
sql_script[num_scripts].commands=commands;
2703+
initStats(&sql_script[num_scripts].stats,0.0);
26962704
num_scripts++;
26972705
}
26982706

@@ -2776,22 +2784,43 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
27762784
printf("tps = %f (including connections establishing)\n",tps_include);
27772785
printf("tps = %f (excluding connections establishing)\n",tps_exclude);
27782786

2779-
/* Report per-commandlatencies */
2780-
if (is_latencies)
2787+
/* Report per-commandstatistics */
2788+
if (per_script_stats)
27812789
{
27822790
inti;
27832791

27842792
for (i=0;i<num_scripts;i++)
27852793
{
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);
27872808

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");
27902815

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+
}
27952824
}
27962825
}
27972826
}
@@ -2977,6 +3006,7 @@ main(int argc, char **argv)
29773006
break;
29783007
case'r':
29793008
benchmarking_option_set= true;
3009+
per_script_stats= true;
29803010
is_latencies= true;
29813011
break;
29823012
case's':
@@ -3200,6 +3230,10 @@ main(int argc, char **argv)
32003230
internal_script_used= true;
32013231
}
32023232

3233+
/* show per script stats if several scripts are used */
3234+
if (num_scripts>1)
3235+
per_script_stats= true;
3236+
32033237
/*
32043238
* Don't need more threads than there are clients. (This is not merely an
32053239
* optimization; throttle_delay is calculated incorrectly below if some

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp