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

Commit 5b3cc1a

Browse files
committed
Mostly mechanical cleanup of pgbench
pgindent for recent commits; also change some variables from int to boolean, which is how they are really used. Mostly submitted by Fabien Coelho; this is in preparation to commit further patches to the file.
1 parent b8682a7 commit 5b3cc1a

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/bin/pgbench/pgbench.c

+33-32
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int pthread_join(pthread_t th, void **thread_return);
9090
#define LOG_STEP_SECONDS 5 /* seconds between log messages */
9191
#define DEFAULT_NXACTS 10 /* default nxacts */
9292

93-
#define MIN_GAUSSIAN_PARAM 2.0 /* minimum parameter for gauss */
93+
#define MIN_GAUSSIAN_PARAM 2.0 /* minimum parameter for gauss */
9494

9595
int nxacts = 0; /* number of transactions per client */
9696
int duration = 0; /* duration in seconds */
@@ -201,16 +201,15 @@ typedef struct
201201
PGconn *con; /* connection handle to DB */
202202
int id; /* client No. */
203203
int state; /* state No. */
204-
int listen; /* 0 indicates that an async query has been
205-
* sent */
206-
int sleeping; /* 1 indicates that the client is napping */
204+
bool listen; /* whether an async query has been sent */
205+
bool is_throttled; /* whether transaction throttling is done */
206+
bool sleeping; /* whether the client is napping */
207207
bool throttling; /* whether nap is for throttling */
208208
Variable *variables; /* array of variable definitions */
209209
int nvariables;
210210
int64 txn_scheduled; /* scheduled start time of transaction (usec) */
211211
instr_time txn_begin; /* used for measuring schedule lag times */
212212
instr_time stmt_begin; /* used for measuring statement latencies */
213-
bool is_throttled; /* whether transaction throttling is done */
214213
int use_file; /* index in sql_files for this client */
215214
bool prepared[MAX_FILES];
216215

@@ -374,7 +373,7 @@ usage(void)
374373
" -f, --file=FILENAME read transaction script from FILENAME\n"
375374
" -j, --jobs=NUM number of threads (default: 1)\n"
376375
" -l, --log write transaction times to log file\n"
377-
" -L, --latency-limit=NUM count transactions lasting more than NUM ms as late\n"
376+
" -L, --latency-limit=NUM count transactions lasting more than NUM ms as late\n"
378377
" -M, --protocol=simple|extended|prepared\n"
379378
" protocol for submitting queries (default: simple)\n"
380379
" -n, --no-vacuum do not run VACUUM before tests\n"
@@ -389,7 +388,7 @@ usage(void)
389388
" -v, --vacuum-all vacuum all four standard tables before tests\n"
390389
" --aggregate-interval=NUM aggregate data over NUM seconds\n"
391390
" --sampling-rate=NUM fraction of transactions to log (e.g. 0.01 for 1%%)\n"
392-
" --progress-timestamp use Unix epoch timestamps for progress\n"
391+
" --progress-timestamp use Unix epoch timestamps for progress\n"
393392
"\nCommon options:\n"
394393
" -d, --debug print debugging output\n"
395394
" -h, --host=HOSTNAME database server host or socket directory\n"
@@ -520,16 +519,16 @@ getGaussianRand(TState *thread, int64 min, int64 max, double parameter)
520519
double rand;
521520

522521
/*
523-
* Get user specified random number from this loop,
524-
* with -parameter < stdev <= parameter
522+
* Get user specified random number from this loop, with -parameter <
523+
* stdev <= parameter
525524
*
526525
* This loop is executed until the number is in the expected range.
527526
*
528527
* As the minimum parameter is 2.0, the probability of looping is low:
529528
* sqrt(-2 ln(r)) <= 2 => r >= e^{-2} ~ 0.135, then when taking the
530529
* average sinus multiplier as 2/pi, we have a 8.6% looping probability in
531-
* the worst case. For a parameter value of 5.0, the looping probability is
532-
* about e^{-5} * 2 / pi ~ 0.43%.
530+
* the worst case. For a parameter value of 5.0, the looping probability
531+
* is about e^{-5} * 2 / pi ~ 0.43%.
533532
*/
534533
do
535534
{
@@ -1191,7 +1190,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
11911190
}
11921191
}
11931192

1194-
st->sleeping = 1;
1193+
st->sleeping = true;
11951194
st->throttling = true;
11961195
st->is_throttled = true;
11971196
if (debug)
@@ -1208,7 +1207,8 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
12081207
now_us = INSTR_TIME_GET_MICROSEC(now);
12091208
if (st->txn_scheduled <= now_us)
12101209
{
1211-
st->sleeping = 0; /* Done sleeping, go ahead with next command */
1210+
/* Done sleeping, go ahead with next command */
1211+
st->sleeping = false;
12121212
if (st->throttling)
12131213
{
12141214
/* Measure lag of throttled transaction relative to target */
@@ -1337,9 +1337,9 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
13371337
* nothing to listen to right now. When throttling rate limits
13381338
* are active, a sleep will happen next, as the next transaction
13391339
* starts. And then in any case the next SQL command will set
1340-
* listen back to 1.
1340+
* listen back to true.
13411341
*/
1342-
st->listen = 0;
1342+
st->listen = false;
13431343
trans_needs_throttle = (throttle_delay > 0);
13441344
}
13451345
}
@@ -1462,7 +1462,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
14621462
st->ecnt++;
14631463
}
14641464
else
1465-
st->listen = 1; /* flags that should be listened */
1465+
st->listen = true; /* flags that should be listened */
14661466
}
14671467
else if (commands[st->state]->type == META_COMMAND)
14681468
{
@@ -1585,8 +1585,8 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
15851585
if (parameter <= 0.0)
15861586
{
15871587
fprintf(stderr,
1588-
"exponential parameter must be greater than zero (not \"%s\")\n",
1589-
argv[5]);
1588+
"exponential parameter must be greater than zero (not \"%s\")\n",
1589+
argv[5]);
15901590
st->ecnt++;
15911591
return true;
15921592
}
@@ -1613,7 +1613,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
16131613
return true;
16141614
}
16151615

1616-
st->listen = 1;
1616+
st->listen = true;
16171617
}
16181618
else if (pg_strcasecmp(argv[0], "set") == 0)
16191619
{
@@ -1634,7 +1634,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
16341634
return true;
16351635
}
16361636

1637-
st->listen = 1;
1637+
st->listen = true;
16381638
}
16391639
else if (pg_strcasecmp(argv[0], "sleep") == 0)
16401640
{
@@ -1668,9 +1668,9 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
16681668

16691669
INSTR_TIME_SET_CURRENT(now);
16701670
st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec;
1671-
st->sleeping = 1;
1671+
st->sleeping = true;
16721672

1673-
st->listen = 1;
1673+
st->listen = true;
16741674
}
16751675
else if (pg_strcasecmp(argv[0], "setshell") == 0)
16761676
{
@@ -1684,7 +1684,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
16841684
return true;
16851685
}
16861686
else /* succeeded */
1687-
st->listen = 1;
1687+
st->listen = true;
16881688
}
16891689
else if (pg_strcasecmp(argv[0], "shell") == 0)
16901690
{
@@ -1698,7 +1698,7 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
16981698
return true;
16991699
}
17001700
else /* succeeded */
1701-
st->listen = 1;
1701+
st->listen = true;
17021702
}
17031703
goto top;
17041704
}
@@ -2207,7 +2207,8 @@ parseQuery(Command *cmd, const char *raw_sql)
22072207
return true;
22082208
}
22092209

2210-
void pg_attribute_noreturn()
2210+
void
2211+
pg_attribute_noreturn()
22112212
syntax_error(const char *source, const int lineno,
22122213
const char *line, const char *command,
22132214
const char *msg, const char *more, const int column)
@@ -2289,10 +2290,10 @@ process_commands(char *buf, const char *source, const int lineno)
22892290

22902291
if (pg_strcasecmp(my_commands->argv[0], "setrandom") == 0)
22912292
{
2292-
/*
2293+
/*--------
22932294
* parsing:
2294-
* \setrandom variable min max [uniform]
2295-
* \setrandom variable min max (gaussian|exponential) parameter
2295+
* \setrandom variable min max [uniform]
2296+
* \setrandom variable min max (gaussian|exponential) parameter
22962297
*/
22972298

22982299
if (my_commands->argc < 4)
@@ -2317,7 +2318,7 @@ process_commands(char *buf, const char *source, const int lineno)
23172318
if (my_commands->argc < 6)
23182319
{
23192320
syntax_error(source, lineno, my_commands->line, my_commands->argv[0],
2320-
"missing parameter", my_commands->argv[4], -1);
2321+
"missing parameter", my_commands->argv[4], -1);
23212322
}
23222323
else if (my_commands->argc > 6)
23232324
{
@@ -2762,12 +2763,14 @@ main(int argc, char **argv)
27622763
{"initialize", no_argument, NULL, 'i'},
27632764
{"jobs", required_argument, NULL, 'j'},
27642765
{"log", no_argument, NULL, 'l'},
2766+
{"latency-limit", required_argument, NULL, 'L'},
27652767
{"no-vacuum", no_argument, NULL, 'n'},
27662768
{"port", required_argument, NULL, 'p'},
27672769
{"progress", required_argument, NULL, 'P'},
27682770
{"protocol", required_argument, NULL, 'M'},
27692771
{"quiet", no_argument, NULL, 'q'},
27702772
{"report-latencies", no_argument, NULL, 'r'},
2773+
{"rate", required_argument, NULL, 'R'},
27712774
{"scale", required_argument, NULL, 's'},
27722775
{"select-only", no_argument, NULL, 'S'},
27732776
{"skip-some-updates", no_argument, NULL, 'N'},
@@ -2782,8 +2785,6 @@ main(int argc, char **argv)
27822785
{"unlogged-tables", no_argument, &unlogged_tables, 1},
27832786
{"sampling-rate", required_argument, NULL, 4},
27842787
{"aggregate-interval", required_argument, NULL, 5},
2785-
{"rate", required_argument, NULL, 'R'},
2786-
{"latency-limit", required_argument, NULL, 'L'},
27872788
{"progress-timestamp", no_argument, NULL, 6},
27882789
{NULL, 0, NULL, 0}
27892790
};
@@ -3627,7 +3628,7 @@ threadRun(void *arg)
36273628
{
36283629
/* interrupt client which has not started a transaction */
36293630
remains--;
3630-
st->sleeping = 0;
3631+
st->sleeping = false;
36313632
st->throttling = false;
36323633
PQfinish(st->con);
36333634
st->con = NULL;

0 commit comments

Comments
 (0)