Commit 41124a91 authored by Robert Haas's avatar Robert Haas

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.
parent 3887ba6d
...@@ -614,6 +614,16 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</> ...@@ -614,6 +614,16 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--log-prefix=<replaceable>prefix</></option></term>
<listitem>
<para>
Set the filename prefix for the transaction log file created by
<option>--log</>. The default is <replaceable>pgbench_log</>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
...@@ -1121,15 +1131,17 @@ END; ...@@ -1121,15 +1131,17 @@ END;
With the <option>-l</> option but without the <option>--aggregate-interval</option>, With the <option>-l</> option but without the <option>--aggregate-interval</option>,
<application>pgbench</> writes the time taken by each transaction <application>pgbench</> writes the time taken by each transaction
to a log file. The log file will be named to a log file. The log file will be named
<filename>pgbench_log.<replaceable>nnn</></filename>, where <filename><replaceable>prefix</>.<replaceable>nnn</></filename>,
<replaceable>nnn</> is the PID of the <application>pgbench</application> process. where <replaceable>prefix</> defaults to <literal>pgbench_log</>, and
If the <option>-j</> option is 2 or higher, creating multiple worker <replaceable>nnn</> is the PID of the
threads, each will have its own log file. The first worker will use the <application>pgbench</application> process. If the <option>-j</> option is 2 or higher,
same name for its log file as in the standard single worker case. creating multiple worker threads, each will have its own log file. The first worker will
use the same name for its log file as in the standard single worker case.
The additional log files for the other workers will be named The additional log files for the other workers will be named
<filename>pgbench_log.<replaceable>nnn</>.<replaceable>mmm</></filename>, <filename><replaceable>pgbench_log</>.<replaceable>nnn</>.<replaceable>mmm</></filename>,
where <replaceable>mmm</> is a sequential number for each worker starting where <replaceable>mmm</> is a sequential number for each worker starting
with 1. with 1. The prefix can be changed by using the <option>--log-prefix</>
option.
</para> </para>
<para> <para>
......
...@@ -180,6 +180,7 @@ char *pghost = ""; ...@@ -180,6 +180,7 @@ char *pghost = "";
char *pgport = ""; char *pgport = "";
char *login = NULL; char *login = NULL;
char *dbName; char *dbName;
char *logfile_prefix = NULL;
const char *progname; const char *progname;
#define WSEP '@' /* weight separator */ #define WSEP '@' /* weight separator */
...@@ -511,6 +512,8 @@ usage(void) ...@@ -511,6 +512,8 @@ usage(void)
" --aggregate-interval=NUM aggregate data over NUM seconds\n" " --aggregate-interval=NUM aggregate data over NUM seconds\n"
" --progress-timestamp use Unix epoch timestamps for progress\n" " --progress-timestamp use Unix epoch timestamps for progress\n"
" --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n" " --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
" --log-prefix=PREFIX prefix for transaction time log file\n"
" (default: \"pgbench_log\")\n"
"\nCommon options:\n" "\nCommon options:\n"
" -d, --debug print debugging output\n" " -d, --debug print debugging output\n"
" -h, --host=HOSTNAME database server host or socket directory\n" " -h, --host=HOSTNAME database server host or socket directory\n"
...@@ -3643,6 +3646,7 @@ main(int argc, char **argv) ...@@ -3643,6 +3646,7 @@ main(int argc, char **argv)
{"sampling-rate", required_argument, NULL, 4}, {"sampling-rate", required_argument, NULL, 4},
{"aggregate-interval", required_argument, NULL, 5}, {"aggregate-interval", required_argument, NULL, 5},
{"progress-timestamp", no_argument, NULL, 6}, {"progress-timestamp", no_argument, NULL, 6},
{"log-prefix", required_argument, NULL, 7},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -3990,6 +3994,10 @@ main(int argc, char **argv) ...@@ -3990,6 +3994,10 @@ main(int argc, char **argv)
progress_timestamp = true; progress_timestamp = true;
benchmarking_option_set = true; benchmarking_option_set = true;
break; break;
case 7:
benchmarking_option_set = true;
logfile_prefix = pg_strdup(optarg);
break;
default: default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1); exit(1);
...@@ -4087,6 +4095,12 @@ main(int argc, char **argv) ...@@ -4087,6 +4095,12 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
if (!use_log && logfile_prefix)
{
fprintf(stderr, "log file prefix (--log-prefix) is allowed only when logging transactions (-l)\n");
exit(1);
}
if (duration > 0 && agg_interval > duration) if (duration > 0 && agg_interval > duration)
{ {
fprintf(stderr, "number of seconds for aggregation (%d) must not be higher than test duration (%d)\n", agg_interval, duration); 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) ...@@ -4388,11 +4402,13 @@ threadRun(void *arg)
if (use_log) if (use_log)
{ {
char logpath[64]; char logpath[64];
char *prefix = logfile_prefix ? logfile_prefix : "pgbench_log";
if (thread->tid == 0) if (thread->tid == 0)
snprintf(logpath, sizeof(logpath), "pgbench_log.%d", main_pid); snprintf(logpath, sizeof(logpath), "%s.%d", prefix, main_pid);
else else
snprintf(logpath, sizeof(logpath), "pgbench_log.%d.%d", main_pid, thread->tid); snprintf(logpath, sizeof(logpath), "%s.%d.%d", prefix, main_pid, thread->tid);
thread->logfile = fopen(logpath, "w"); thread->logfile = fopen(logpath, "w");
if (thread->logfile == NULL) if (thread->logfile == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment