1 /*-------------------------------------------------------------------------
4 * functions for instrumentation of plan execution
7 * Copyright (c) 2001-2008, PostgreSQL Global Development Group
12 *-------------------------------------------------------------------------
18 #include "executor/instrument.h"
21 /* Allocate new instrumentation structure(s) */
25 Instrumentation
*instr
= palloc0(n
* sizeof(Instrumentation
));
27 /* we don't need to do any initialization except zero 'em */
32 /* Entry to a plan node */
34 InstrStartNode(Instrumentation
*instr
)
36 if (INSTR_TIME_IS_ZERO(instr
->starttime
))
37 INSTR_TIME_SET_CURRENT(instr
->starttime
);
39 elog(DEBUG2
, "InstrStartNode called twice in a row");
42 /* Exit from a plan node */
44 InstrStopNode(Instrumentation
*instr
, double nTuples
)
48 /* count the returned tuples */
49 instr
->tuplecount
+= nTuples
;
51 if (INSTR_TIME_IS_ZERO(instr
->starttime
))
53 elog(DEBUG2
, "InstrStopNode called without start");
57 INSTR_TIME_SET_CURRENT(endtime
);
58 INSTR_TIME_ACCUM_DIFF(instr
->counter
, endtime
, instr
->starttime
);
60 INSTR_TIME_SET_ZERO(instr
->starttime
);
62 /* Is this the first tuple of this cycle? */
65 instr
->running
= true;
66 instr
->firsttuple
= INSTR_TIME_GET_DOUBLE(instr
->counter
);
70 /* Finish a run cycle for a plan node */
72 InstrEndLoop(Instrumentation
*instr
)
76 /* Skip if nothing has happened, or already shut down */
80 if (!INSTR_TIME_IS_ZERO(instr
->starttime
))
81 elog(DEBUG2
, "InstrEndLoop called on running node");
83 /* Accumulate per-cycle statistics into totals */
84 totaltime
= INSTR_TIME_GET_DOUBLE(instr
->counter
);
86 instr
->startup
+= instr
->firsttuple
;
87 instr
->total
+= totaltime
;
88 instr
->ntuples
+= instr
->tuplecount
;
91 /* Reset for next cycle (if any) */
92 instr
->running
= false;
93 INSTR_TIME_SET_ZERO(instr
->starttime
);
94 INSTR_TIME_SET_ZERO(instr
->counter
);
95 instr
->firsttuple
= 0;
96 instr
->tuplecount
= 0;