Skip to content

Commit 74baa1e

Browse files
committed
Avoid assuming that instr_time == struct timeval in pgbench logging.
This code was presuming undue familiarity with the contents of the instr_time struct. That was already broken on Windows, and it's about to get broken on most other platforms as well. The simplest solution that preserves the current output definition is to just do our own gettimeofday() call here. Realistically, the extra cost is probably negligible in comparison to everything else that's going on in a pgbench transaction, so it's not worth sweating over. On Windows, the precision delivered by gettimeofday() is lower than one could wish, but this is still a big improvement over printing zeroes, as the code did before. Discussion: https://postgr.es/m/8837.1483216839@sss.pgh.pa.us
1 parent 257d815 commit 74baa1e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/bin/pgbench/pgbench.c

+11-15
Original file line numberDiff line numberDiff line change
@@ -2483,27 +2483,23 @@ doLog(TState *thread, CState *st, instr_time *now,
24832483
else
24842484
{
24852485
/* no, print raw transactions */
2486-
#ifndef WIN32
2486+
struct timeval tv;
24872487

2488-
/* This is more than we really ought to know about instr_time */
2488+
/*
2489+
* We print the current system timestamp in the log, so that entries
2490+
* can be correlated against other logs. On some platforms this is
2491+
* available in *now, but rather than get entangled with that, we just
2492+
* eat the cost of an extra syscall in all cases.
2493+
*/
2494+
gettimeofday(&tv, NULL);
24892495
if (skipped)
24902496
fprintf(logfile, "%d " INT64_FORMAT " skipped %d %ld %ld",
24912497
st->id, st->cnt, st->use_file,
2492-
(long) now->tv_sec, (long) now->tv_usec);
2498+
(long) tv.tv_sec, (long) tv.tv_usec);
24932499
else
24942500
fprintf(logfile, "%d " INT64_FORMAT " %.0f %d %ld %ld",
24952501
st->id, st->cnt, latency, st->use_file,
2496-
(long) now->tv_sec, (long) now->tv_usec);
2497-
#else
2498-
2499-
/* On Windows, instr_time doesn't provide a timestamp anyway */
2500-
if (skipped)
2501-
fprintf(logfile, "%d " INT64_FORMAT " skipped %d 0 0",
2502-
st->id, st->cnt, st->use_file);
2503-
else
2504-
fprintf(logfile, "%d " INT64_FORMAT " %.0f %d 0 0",
2505-
st->id, st->cnt, latency, st->use_file);
2506-
#endif
2502+
(long) tv.tv_sec, (long) tv.tv_usec);
25072503
if (throttle_delay)
25082504
fprintf(logfile, " %.0f", lag);
25092505
fputc('\n', logfile);
@@ -4402,7 +4398,7 @@ threadRun(void *arg)
44024398
if (use_log)
44034399
{
44044400
char logpath[MAXPGPATH];
4405-
char *prefix = logfile_prefix ? logfile_prefix : "pgbench_log";
4401+
char *prefix = logfile_prefix ? logfile_prefix : "pgbench_log";
44064402

44074403
if (thread->tid == 0)
44084404
snprintf(logpath, sizeof(logpath), "%s.%d", prefix, main_pid);

0 commit comments

Comments
 (0)