static void setBoolValue(PgBenchValue *pv, bool bval);
static void setIntValue(PgBenchValue *pv, int64 ival);
static void setDoubleValue(PgBenchValue *pv, double dval);
-static bool evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr,
+static bool evaluateExpr(CState *st, PgBenchExpr *expr,
PgBenchValue *retval);
-static ConnectionStateEnum executeMetaCommand(TState *thread, CState *st,
- instr_time *now);
+static ConnectionStateEnum executeMetaCommand(CState *st, instr_time *now);
static void doLog(TState *thread, CState *st,
StatsData *agg, bool skipped, double latency, double lag);
static void processXactStats(TState *thread, CState *st, instr_time *now,
/* lazy evaluation of some functions */
static bool
-evalLazyFunc(TState *thread, CState *st,
+evalLazyFunc(CState *st,
PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval)
{
PgBenchValue a1,
Assert(isLazyFunc(func) && args != NULL && args->next != NULL);
/* args points to first condition */
- if (!evaluateExpr(thread, st, args->expr, &a1))
+ if (!evaluateExpr(st, args->expr, &a1))
return false;
/* second condition for AND/OR and corresponding branch for CASE */
return true;
}
- if (!evaluateExpr(thread, st, args->expr, &a2))
+ if (!evaluateExpr(st, args->expr, &a2))
return false;
if (a2.type == PGBT_NULL)
return true;
}
- if (!evaluateExpr(thread, st, args->expr, &a2))
+ if (!evaluateExpr(st, args->expr, &a2))
return false;
if (a2.type == PGBT_NULL)
case PGBENCH_CASE:
/* when true, execute branch */
if (valueTruth(&a1))
- return evaluateExpr(thread, st, args->expr, retval);
+ return evaluateExpr(st, args->expr, retval);
/* now args contains next condition or final else expression */
args = args->next;
/* final else case? */
if (args->next == NULL)
- return evaluateExpr(thread, st, args->expr, retval);
+ return evaluateExpr(st, args->expr, retval);
/* no, another when, proceed */
- return evalLazyFunc(thread, st, PGBENCH_CASE, args, retval);
+ return evalLazyFunc(st, PGBENCH_CASE, args, retval);
default:
/* internal error, cannot get here */
* which do not require lazy evaluation.
*/
static bool
-evalStandardFunc(TState *thread, CState *st,
+evalStandardFunc(CState *st,
PgBenchFunction func, PgBenchExprLink *args,
PgBenchValue *retval)
{
for (nargs = 0; nargs < MAX_FARGS && l != NULL; nargs++, l = l->next)
{
- if (!evaluateExpr(thread, st, l->expr, &vargs[nargs]))
+ if (!evaluateExpr(st, l->expr, &vargs[nargs]))
return false;
has_null |= vargs[nargs].type == PGBT_NULL;
}
/* evaluate some function */
static bool
-evalFunc(TState *thread, CState *st,
+evalFunc(CState *st,
PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval)
{
if (isLazyFunc(func))
- return evalLazyFunc(thread, st, func, args, retval);
+ return evalLazyFunc(st, func, args, retval);
else
- return evalStandardFunc(thread, st, func, args, retval);
+ return evalStandardFunc(st, func, args, retval);
}
/*
* the value itself is returned through the retval pointer.
*/
static bool
-evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, PgBenchValue *retval)
+evaluateExpr(CState *st, PgBenchExpr *expr, PgBenchValue *retval)
{
switch (expr->etype)
{
}
case ENODE_FUNCTION:
- return evalFunc(thread, st,
+ return evalFunc(st,
expr->u.function.function,
expr->u.function.args,
retval);
* - on sleep CSTATE_SLEEP
* - else CSTATE_END_COMMAND
*/
- st->state = executeMetaCommand(thread, st, &now);
+ st->state = executeMetaCommand(st, &now);
}
/*
* take no time to execute.
*/
static ConnectionStateEnum
-executeMetaCommand(TState *thread, CState *st, instr_time *now)
+executeMetaCommand(CState *st, instr_time *now)
{
Command *command = sql_script[st->use_file].commands[st->command];
int argc;
PgBenchExpr *expr = command->expr;
PgBenchValue result;
- if (!evaluateExpr(thread, st, expr, &result))
+ if (!evaluateExpr(st, expr, &result))
{
commandFailed(st, argv[0], "evaluation of meta-command failed");
return CSTATE_ABORTED;
PgBenchValue result;
bool cond;
- if (!evaluateExpr(thread, st, expr, &result))
+ if (!evaluateExpr(st, expr, &result))
{
commandFailed(st, argv[0], "evaluation of meta-command failed");
return CSTATE_ABORTED;
return CSTATE_END_COMMAND;
}
- if (!evaluateExpr(thread, st, expr, &result))
+ if (!evaluateExpr(st, expr, &result))
{
commandFailed(st, argv[0], "evaluation of meta-command failed");
return CSTATE_ABORTED;
* progress report. On exit, they are updated with the new stats.
*/
static void
-printProgressReport(TState *thread, int64 test_start, int64 now,
+printProgressReport(TState *threads, int64 test_start, int64 now,
StatsData *last, int64 *last_report)
{
/* generate and show report */
initStats(&cur, 0);
for (int i = 0; i < nthreads; i++)
{
- mergeSimpleStats(&cur.latency, &thread[i].stats.latency);
- mergeSimpleStats(&cur.lag, &thread[i].stats.lag);
- cur.cnt += thread[i].stats.cnt;
- cur.skipped += thread[i].stats.skipped;
+ mergeSimpleStats(&cur.latency, &threads[i].stats.latency);
+ mergeSimpleStats(&cur.lag, &threads[i].stats.lag);
+ cur.cnt += threads[i].stats.cnt;
+ cur.skipped += threads[i].stats.skipped;
}
/* we count only actually executed transactions */
/* print out results */
static void
-printResults(TState *threads, StatsData *total, instr_time total_time,
+printResults(StatsData *total, instr_time total_time,
instr_time conn_total_time, int64 latency_late)
{
double time_include,
*/
INSTR_TIME_SET_CURRENT(total_time);
INSTR_TIME_SUBTRACT(total_time, start_time);
- printResults(threads, &stats, total_time, conn_total_time, latency_late);
+ printResults(&stats, total_time, conn_total_time, latency_late);
if (exit_code != 0)
fprintf(stderr, "Run was aborted; the above results are incomplete.\n");
now = INSTR_TIME_GET_MICROSEC(now_time);
if (now >= next_report)
{
- printProgressReport(thread, thread_start, now, &last, &last_report);
+ /*
+ * Horrible hack: this relies on the thread pointer we are
+ * passed to be equivalent to threads[0], that is the first
+ * entry of the threads array. That is why this MUST be done
+ * by thread 0 and not any other.
+ */
+ printProgressReport(thread, thread_start, now,
+ &last, &last_report);
/*
* Ensure that the next report is in the future, in case