1/*-------------------------------------------------------------------------
2 *
3 * instrument.h
4 * definitions for run-time statistics collection
5 *
6 *
7 * Copyright (c) 2001-2019, PostgreSQL Global Development Group
8 *
9 * src/include/executor/instrument.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef INSTRUMENT_H
14#define INSTRUMENT_H
15
16#include "portability/instr_time.h"
17
18
19typedef struct BufferUsage
20{
21 long shared_blks_hit; /* # of shared buffer hits */
22 long shared_blks_read; /* # of shared disk blocks read */
23 long shared_blks_dirtied; /* # of shared blocks dirtied */
24 long shared_blks_written; /* # of shared disk blocks written */
25 long local_blks_hit; /* # of local buffer hits */
26 long local_blks_read; /* # of local disk blocks read */
27 long local_blks_dirtied; /* # of shared blocks dirtied */
28 long local_blks_written; /* # of local disk blocks written */
29 long temp_blks_read; /* # of temp blocks read */
30 long temp_blks_written; /* # of temp blocks written */
31 instr_time blk_read_time; /* time spent reading */
32 instr_time blk_write_time; /* time spent writing */
33} BufferUsage;
34
35/* Flag bits included in InstrAlloc's instrument_options bitmask */
36typedef enum InstrumentOption
37{
38 INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */
39 INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */
40 INSTRUMENT_ROWS = 1 << 2, /* needs row count */
41 INSTRUMENT_ALL = PG_INT32_MAX
42} InstrumentOption;
43
44typedef struct Instrumentation
45{
46 /* Parameters set at node creation: */
47 bool need_timer; /* true if we need timer data */
48 bool need_bufusage; /* true if we need buffer usage data */
49 /* Info about current plan cycle: */
50 bool running; /* true if we've completed first tuple */
51 instr_time starttime; /* Start time of current iteration of node */
52 instr_time counter; /* Accumulated runtime for this node */
53 double firsttuple; /* Time for first tuple of this cycle */
54 double tuplecount; /* Tuples emitted so far this cycle */
55 BufferUsage bufusage_start; /* Buffer usage at start */
56 /* Accumulated statistics across all completed cycles: */
57 double startup; /* Total startup time (in seconds) */
58 double total; /* Total total time (in seconds) */
59 double ntuples; /* Total tuples produced */
60 double ntuples2; /* Secondary node-specific tuple counter */
61 double nloops; /* # of run cycles for this node */
62 double nfiltered1; /* # tuples removed by scanqual or joinqual */
63 double nfiltered2; /* # tuples removed by "other" quals */
64 BufferUsage bufusage; /* Total buffer usage */
65} Instrumentation;
66
67typedef struct WorkerInstrumentation
68{
69 int num_workers; /* # of structures that follow */
70 Instrumentation instrument[FLEXIBLE_ARRAY_MEMBER];
71} WorkerInstrumentation;
72
73extern PGDLLIMPORT BufferUsage pgBufferUsage;
74
75extern Instrumentation *InstrAlloc(int n, int instrument_options);
76extern void InstrInit(Instrumentation *instr, int instrument_options);
77extern void InstrStartNode(Instrumentation *instr);
78extern void InstrStopNode(Instrumentation *instr, double nTuples);
79extern void InstrEndLoop(Instrumentation *instr);
80extern void InstrAggNode(Instrumentation *dst, Instrumentation *add);
81extern void InstrStartParallelQuery(void);
82extern void InstrEndParallelQuery(BufferUsage *result);
83extern void InstrAccumParallelQuery(BufferUsage *result);
84
85#endif /* INSTRUMENT_H */
86