Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 41124a9

Browse files
committed
pgbench: Allow the transaction log file prefix to be changed.
Masahiko Sawada, reviewed by Fabien Coelho and Beena Emerson, with some a bit of wordsmithing and cosmetic adjustment by me.
1 parent 3887ba6 commit 41124a9

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

doc/src/sgml/ref/pgbench.sgml

+19-7
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,16 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
614614
</listitem>
615615
</varlistentry>
616616

617+
<varlistentry>
618+
<term><option>--log-prefix=<replaceable>prefix</></option></term>
619+
<listitem>
620+
<para>
621+
Set the filename prefix for the transaction log file created by
622+
<option>--log</>. The default is <replaceable>pgbench_log</>.
623+
</para>
624+
</listitem>
625+
</varlistentry>
626+
617627
</variablelist>
618628
</para>
619629

@@ -1121,15 +1131,17 @@ END;
11211131
With the <option>-l</> option but without the <option>--aggregate-interval</option>,
11221132
<application>pgbench</> writes the time taken by each transaction
11231133
to a log file. The log file will be named
1124-
<filename>pgbench_log.<replaceable>nnn</></filename>, where
1125-
<replaceable>nnn</> is the PID of the <application>pgbench</application> process.
1126-
If the <option>-j</> option is 2 or higher, creating multiple worker
1127-
threads, each will have its own log file. The first worker will use the
1128-
same name for its log file as in the standard single worker case.
1134+
<filename><replaceable>prefix</>.<replaceable>nnn</></filename>,
1135+
where <replaceable>prefix</> defaults to <literal>pgbench_log</>, and
1136+
<replaceable>nnn</> is the PID of the
1137+
<application>pgbench</application> process. If the <option>-j</> option is 2 or higher,
1138+
creating multiple worker threads, each will have its own log file. The first worker will
1139+
use the same name for its log file as in the standard single worker case.
11291140
The additional log files for the other workers will be named
1130-
<filename>pgbench_log.<replaceable>nnn</>.<replaceable>mmm</></filename>,
1141+
<filename><replaceable>pgbench_log</>.<replaceable>nnn</>.<replaceable>mmm</></filename>,
11311142
where <replaceable>mmm</> is a sequential number for each worker starting
1132-
with 1.
1143+
with 1. The prefix can be changed by using the <option>--log-prefix</>
1144+
option.
11331145
</para>
11341146

11351147
<para>

src/bin/pgbench/pgbench.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ char *pghost = "";
180180
char *pgport = "";
181181
char *login = NULL;
182182
char *dbName;
183+
char *logfile_prefix = NULL;
183184
const char *progname;
184185

185186
#define WSEP '@' /* weight separator */
@@ -511,6 +512,8 @@ usage(void)
511512
" --aggregate-interval=NUM aggregate data over NUM seconds\n"
512513
" --progress-timestamp use Unix epoch timestamps for progress\n"
513514
" --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
515+
" --log-prefix=PREFIX prefix for transaction time log file\n"
516+
" (default: \"pgbench_log\")\n"
514517
"\nCommon options:\n"
515518
" -d, --debug print debugging output\n"
516519
" -h, --host=HOSTNAME database server host or socket directory\n"
@@ -3643,6 +3646,7 @@ main(int argc, char **argv)
36433646
{"sampling-rate", required_argument, NULL, 4},
36443647
{"aggregate-interval", required_argument, NULL, 5},
36453648
{"progress-timestamp", no_argument, NULL, 6},
3649+
{"log-prefix", required_argument, NULL, 7},
36463650
{NULL, 0, NULL, 0}
36473651
};
36483652

@@ -3990,6 +3994,10 @@ main(int argc, char **argv)
39903994
progress_timestamp = true;
39913995
benchmarking_option_set = true;
39923996
break;
3997+
case 7:
3998+
benchmarking_option_set = true;
3999+
logfile_prefix = pg_strdup(optarg);
4000+
break;
39934001
default:
39944002
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
39954003
exit(1);
@@ -4087,6 +4095,12 @@ main(int argc, char **argv)
40874095
exit(1);
40884096
}
40894097

4098+
if (!use_log && logfile_prefix)
4099+
{
4100+
fprintf(stderr, "log file prefix (--log-prefix) is allowed only when logging transactions (-l)\n");
4101+
exit(1);
4102+
}
4103+
40904104
if (duration > 0 && agg_interval > duration)
40914105
{
40924106
fprintf(stderr, "number of seconds for aggregation (%d) must not be higher than test duration (%d)\n", agg_interval, duration);
@@ -4388,11 +4402,13 @@ threadRun(void *arg)
43884402
if (use_log)
43894403
{
43904404
char logpath[64];
4405+
char *prefix = logfile_prefix ? logfile_prefix : "pgbench_log";
43914406

43924407
if (thread->tid == 0)
4393-
snprintf(logpath, sizeof(logpath), "pgbench_log.%d", main_pid);
4408+
snprintf(logpath, sizeof(logpath), "%s.%d", prefix, main_pid);
43944409
else
4395-
snprintf(logpath, sizeof(logpath), "pgbench_log.%d.%d", main_pid, thread->tid);
4410+
snprintf(logpath, sizeof(logpath), "%s.%d.%d", prefix, main_pid, thread->tid);
4411+
43964412
thread->logfile = fopen(logpath, "w");
43974413

43984414
if (thread->logfile == NULL)

0 commit comments

Comments
 (0)