#ifndef INSTRUMENT_H
#define INSTRUMENT_H
#include "portability/instr_time.h"
typedef struct BufferUsage
{
int64 shared_blks_hit;
int64 shared_blks_read;
int64 shared_blks_dirtied;
int64 shared_blks_written;
int64 local_blks_hit;
int64 local_blks_read;
int64 local_blks_dirtied;
int64 local_blks_written;
int64 temp_blks_read;
int64 temp_blks_written;
instr_time shared_blk_read_time;
instr_time shared_blk_write_time;
instr_time local_blk_read_time;
instr_time local_blk_write_time;
instr_time temp_blk_read_time;
instr_time temp_blk_write_time;
} BufferUsage;
typedef struct WalUsage
{
int64 wal_records;
int64 wal_fpi;
uint64 wal_bytes;
} WalUsage;
typedef enum InstrumentOption
{
INSTRUMENT_TIMER = 1 << 0,
INSTRUMENT_BUFFERS = 1 << 1,
INSTRUMENT_ROWS = 1 << 2,
INSTRUMENT_WAL = 1 << 3,
INSTRUMENT_ALL = PG_INT32_MAX
} InstrumentOption;
typedef struct Instrumentation
{
bool need_timer;
bool need_bufusage;
bool need_walusage;
bool async_mode;
bool running;
instr_time starttime;
instr_time counter;
double firsttuple;
double tuplecount;
BufferUsage bufusage_start;
WalUsage walusage_start;
double startup;
double total;
double ntuples;
double ntuples2;
double nloops;
double nfiltered1;
double nfiltered2;
BufferUsage bufusage;
WalUsage walusage;
} Instrumentation;
typedef struct WorkerInstrumentation
{
int num_workers;
Instrumentation instrument[FLEXIBLE_ARRAY_MEMBER];
} WorkerInstrumentation;
extern PGDLLIMPORT BufferUsage pgBufferUsage;
extern PGDLLIMPORT WalUsage pgWalUsage;
extern Instrumentation *InstrAlloc(int n, int instrument_options,
bool async_mode);
extern void InstrInit(Instrumentation *instr, int instrument_options);
extern void InstrStartNode(Instrumentation *instr);
extern void InstrStopNode(Instrumentation *instr, double nTuples);
extern void InstrUpdateTupleCount(Instrumentation *instr, double nTuples);
extern void InstrEndLoop(Instrumentation *instr);
extern void InstrAggNode(Instrumentation *dst, Instrumentation *add);
extern void InstrStartParallelQuery(void);
extern void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage);
extern void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage);
extern void BufferUsageAccumDiff(BufferUsage *dst,
const BufferUsage *add, const BufferUsage *sub);
extern void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add,
const WalUsage *sub);
#endif