20 static void output(uint64 loop_count);
26 main(
int argc,
char *argv[])
45 static struct option long_options[] = {
57 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
62 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
64 puts(
"pg_test_timing (PostgreSQL) " PG_VERSION);
70 long_options, &optindex)) != -1)
76 optval = strtoul(
optarg, &endptr, 10);
78 if (endptr ==
optarg || *endptr !=
'\0' ||
79 errno != 0 || optval != (
unsigned int) optval)
81 fprintf(stderr,
_(
"%s: invalid argument for option %s\n"),
90 fprintf(stderr,
_(
"%s: %s must be in range %u..%u\n"),
91 progname,
"--duration", 1, UINT_MAX);
97 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
107 _(
"%s: too many command-line arguments (first is \"%s\")\n"),
109 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
116 "Testing timing overhead for %u seconds.\n",
125 int64 time_elapsed = 0;
126 uint64 loop_count = 0;
138 while (time_elapsed < total_time)
151 fprintf(stderr,
_(
"Detected clock going backwards in time.\n"));
152 fprintf(stderr,
_(
"Time warp: %d ms\n"), diff);
175 printf(
_(
"Per loop time including overhead: %0.2f ns\n"),
186 char *header1 =
_(
"< us");
187 char *header2 =
_(
"% of total");
188 char *header3 =
_(
"count");
189 int len1 = strlen(header1);
190 int len2 = strlen(header2);
191 int len3 = strlen(header3);
194 while (max_bit > 0 &&
histogram[max_bit] == 0)
197 printf(
_(
"Histogram of timing durations:\n"));
199 Max(6, len1), header1,
200 Max(10, len2), header2,
201 Max(10, len3), header3);
203 for (
i = 0;
i <= max_bit;
i++)
204 printf(
"%*ld %*.5f %*lld\n",
205 Max(6, len1), 1l <<
i,
#define ngettext(s, p, n)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_GET_DOUBLE(t)
#define INSTR_TIME_SUBTRACT(x, y)
#define INSTR_TIME_GET_MICROSEC(t)
PGDLLIMPORT char * optarg
int main(int argc, char *argv[])
static void output(uint64 loop_count)
static long long int histogram[32]
static void handle_args(int argc, char *argv[])
static uint64 test_timing(unsigned int duration)
static const char * progname
static unsigned int test_duration
const char * get_progname(const char *argv0)