instrument.h 3.2 KB

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