Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

instrument.c File Reference

#include "postgres.h"
#include <unistd.h>
#include "executor/instrument.h"
Include dependency graph for instrument.c:

Go to the source code of this file.

Functions

static void BufferUsageAccumDiff (BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
InstrumentationInstrAlloc (int n, int instrument_options)
void InstrStartNode (Instrumentation *instr)
void InstrStopNode (Instrumentation *instr, double nTuples)
void InstrEndLoop (Instrumentation *instr)

Variables

BufferUsage pgBufferUsage

Function Documentation

static void BufferUsageAccumDiff ( BufferUsage dst,
const BufferUsage add,
const BufferUsage sub 
) [static]
Instrumentation* InstrAlloc ( int  n,
int  instrument_options 
)

Definition at line 28 of file instrument.c.

References i, INSTRUMENT_BUFFERS, INSTRUMENT_TIMER, Instrumentation::need_bufusage, Instrumentation::need_timer, and palloc0().

Referenced by ExecInitNode(), explain_ExecutorStart(), InitResultRelInfo(), and pgss_ExecutorStart().

{
    Instrumentation *instr;

    /* initialize all fields to zeroes, then modify as needed */
    instr = palloc0(n * sizeof(Instrumentation));
    if (instrument_options & (INSTRUMENT_BUFFERS | INSTRUMENT_TIMER))
    {
        bool        need_buffers = (instrument_options & INSTRUMENT_BUFFERS) != 0;
        bool        need_timer = (instrument_options & INSTRUMENT_TIMER) != 0;
        int         i;

        for (i = 0; i < n; i++)
        {
            instr[i].need_bufusage = need_buffers;
            instr[i].need_timer = need_timer;
        }
    }

    return instr;
}

void InstrEndLoop ( Instrumentation instr  ) 

Definition at line 103 of file instrument.c.

References Instrumentation::counter, elog, ERROR, Instrumentation::firsttuple, INSTR_TIME_GET_DOUBLE, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_ZERO, Instrumentation::nloops, Instrumentation::ntuples, Instrumentation::running, Instrumentation::starttime, Instrumentation::startup, Instrumentation::total, and Instrumentation::tuplecount.

Referenced by ExecReScan(), explain_ExecutorEnd(), ExplainNode(), pgss_ExecutorEnd(), and report_triggers().

{
    double      totaltime;

    /* Skip if nothing has happened, or already shut down */
    if (!instr->running)
        return;

    if (!INSTR_TIME_IS_ZERO(instr->starttime))
        elog(ERROR, "InstrEndLoop called on running node");

    /* Accumulate per-cycle statistics into totals */
    totaltime = INSTR_TIME_GET_DOUBLE(instr->counter);

    instr->startup += instr->firsttuple;
    instr->total += totaltime;
    instr->ntuples += instr->tuplecount;
    instr->nloops += 1;

    /* Reset for next cycle (if any) */
    instr->running = false;
    INSTR_TIME_SET_ZERO(instr->starttime);
    INSTR_TIME_SET_ZERO(instr->counter);
    instr->firsttuple = 0;
    instr->tuplecount = 0;
}

void InstrStartNode ( Instrumentation instr  ) 
void InstrStopNode ( Instrumentation instr,
double  nTuples 
)

Definition at line 69 of file instrument.c.

References BufferUsageAccumDiff(), Instrumentation::bufusage, Instrumentation::bufusage_start, Instrumentation::counter, elog, ERROR, Instrumentation::firsttuple, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_GET_DOUBLE, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, Instrumentation::need_bufusage, Instrumentation::need_timer, Instrumentation::running, Instrumentation::starttime, and Instrumentation::tuplecount.

Referenced by AfterTriggerExecute(), ExecCallTriggerFunc(), ExecProcNode(), MultiExecBitmapAnd(), MultiExecBitmapIndexScan(), MultiExecBitmapOr(), MultiExecHash(), standard_ExecutorFinish(), and standard_ExecutorRun().

{
    instr_time  endtime;

    /* count the returned tuples */
    instr->tuplecount += nTuples;

    /* let's update the time only if the timer was requested */
    if (instr->need_timer)
    {
        if (INSTR_TIME_IS_ZERO(instr->starttime))
            elog(ERROR, "InstrStopNode called without start");

        INSTR_TIME_SET_CURRENT(endtime);
        INSTR_TIME_ACCUM_DIFF(instr->counter, endtime, instr->starttime);

        INSTR_TIME_SET_ZERO(instr->starttime);
    }

    /* Add delta of buffer usage since entry to node's totals */
    if (instr->need_bufusage)
        BufferUsageAccumDiff(&instr->bufusage,
                             &pgBufferUsage, &instr->bufusage_start);

    /* Is this the first tuple of this cycle? */
    if (!instr->running)
    {
        instr->running = true;
        instr->firsttuple = INSTR_TIME_GET_DOUBLE(instr->counter);
    }
}


Variable Documentation