2001-09-18 03:59:07 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* instrument.c
|
2001-10-25 07:50:21 +02:00
|
|
|
* functions for instrumentation of plan execution
|
2001-09-18 03:59:07 +02:00
|
|
|
*
|
|
|
|
*
|
2008-01-01 20:46:01 +01:00
|
|
|
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
2001-09-18 03:59:07 +02:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2008-05-14 21:10:29 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/executor/instrument.c,v 1.21 2008/05/14 19:10:29 tgl Exp $
|
2001-09-18 03:59:07 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2006-05-30 21:24:25 +02:00
|
|
|
#include <unistd.h>
|
2001-09-18 03:59:07 +02:00
|
|
|
|
|
|
|
#include "executor/instrument.h"
|
|
|
|
|
2006-05-30 16:01:58 +02:00
|
|
|
|
2005-03-25 22:58:00 +01:00
|
|
|
/* Allocate new instrumentation structure(s) */
|
2001-09-18 03:59:07 +02:00
|
|
|
Instrumentation *
|
2005-03-25 22:58:00 +01:00
|
|
|
InstrAlloc(int n)
|
2001-09-18 03:59:07 +02:00
|
|
|
{
|
2006-06-09 21:30:56 +02:00
|
|
|
Instrumentation *instr = palloc0(n * sizeof(Instrumentation));
|
2006-05-30 21:24:25 +02:00
|
|
|
|
|
|
|
/* we don't need to do any initialization except zero 'em */
|
|
|
|
|
2001-09-18 03:59:07 +02:00
|
|
|
return instr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Entry to a plan node */
|
|
|
|
void
|
|
|
|
InstrStartNode(Instrumentation *instr)
|
|
|
|
{
|
2005-04-16 22:07:35 +02:00
|
|
|
if (INSTR_TIME_IS_ZERO(instr->starttime))
|
2006-06-09 21:30:56 +02:00
|
|
|
INSTR_TIME_SET_CURRENT(instr->starttime);
|
2005-04-16 22:07:35 +02:00
|
|
|
else
|
|
|
|
elog(DEBUG2, "InstrStartNode called twice in a row");
|
2001-09-18 03:59:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit from a plan node */
|
|
|
|
void
|
2006-05-30 16:01:58 +02:00
|
|
|
InstrStopNode(Instrumentation *instr, double nTuples)
|
2001-09-18 03:59:07 +02:00
|
|
|
{
|
2006-06-09 21:30:56 +02:00
|
|
|
instr_time endtime;
|
|
|
|
|
|
|
|
/* count the returned tuples */
|
2006-05-30 16:01:58 +02:00
|
|
|
instr->tuplecount += nTuples;
|
2001-09-18 03:59:07 +02:00
|
|
|
|
2006-06-09 21:30:56 +02:00
|
|
|
if (INSTR_TIME_IS_ZERO(instr->starttime))
|
2001-09-18 03:59:07 +02:00
|
|
|
{
|
2006-06-09 21:30:56 +02:00
|
|
|
elog(DEBUG2, "InstrStopNode called without start");
|
|
|
|
return;
|
|
|
|
}
|
2006-06-07 20:49:03 +02:00
|
|
|
|
2006-06-09 21:30:56 +02:00
|
|
|
INSTR_TIME_SET_CURRENT(endtime);
|
2008-05-14 21:10:29 +02:00
|
|
|
INSTR_TIME_ACCUM_DIFF(instr->counter, endtime, instr->starttime);
|
2001-09-18 03:59:07 +02:00
|
|
|
|
2006-06-09 21:30:56 +02:00
|
|
|
INSTR_TIME_SET_ZERO(instr->starttime);
|
2001-09-18 03:59:07 +02:00
|
|
|
|
|
|
|
/* Is this the first tuple of this cycle? */
|
|
|
|
if (!instr->running)
|
|
|
|
{
|
|
|
|
instr->running = true;
|
2005-03-20 23:27:52 +01:00
|
|
|
instr->firsttuple = INSTR_TIME_GET_DOUBLE(instr->counter);
|
2001-09-18 03:59:07 +02:00
|
|
|
}
|
2005-04-16 22:07:35 +02:00
|
|
|
}
|
2001-09-18 03:59:07 +02:00
|
|
|
|
|
|
|
/* Finish a run cycle for a plan node */
|
2001-10-25 07:50:21 +02:00
|
|
|
void
|
2001-09-18 03:59:07 +02:00
|
|
|
InstrEndLoop(Instrumentation *instr)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
double totaltime;
|
2001-09-18 03:59:07 +02:00
|
|
|
|
|
|
|
/* Skip if nothing has happened, or already shut down */
|
|
|
|
if (!instr->running)
|
|
|
|
return;
|
|
|
|
|
2005-04-16 22:07:35 +02:00
|
|
|
if (!INSTR_TIME_IS_ZERO(instr->starttime))
|
|
|
|
elog(DEBUG2, "InstrEndLoop called on running node");
|
|
|
|
|
2006-06-09 21:30:56 +02:00
|
|
|
/* Accumulate per-cycle statistics into totals */
|
2005-03-20 23:27:52 +01:00
|
|
|
totaltime = INSTR_TIME_GET_DOUBLE(instr->counter);
|
2001-09-18 03:59:07 +02:00
|
|
|
|
2006-05-30 21:24:25 +02:00
|
|
|
instr->startup += instr->firsttuple;
|
|
|
|
instr->total += totaltime;
|
2001-09-18 03:59:07 +02:00
|
|
|
instr->ntuples += instr->tuplecount;
|
|
|
|
instr->nloops += 1;
|
|
|
|
|
|
|
|
/* Reset for next cycle (if any) */
|
|
|
|
instr->running = false;
|
2005-03-20 23:27:52 +01:00
|
|
|
INSTR_TIME_SET_ZERO(instr->starttime);
|
|
|
|
INSTR_TIME_SET_ZERO(instr->counter);
|
2001-09-18 03:59:07 +02:00
|
|
|
instr->firsttuple = 0;
|
|
|
|
instr->tuplecount = 0;
|
|
|
|
}
|