From c8a2beac1c278cfc0daafffc7f678697970ecd18 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 23 May 2022 07:28:13 +0200 Subject: [PATCH v2] Convert macros to static inline functions (pgstat.h) Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com --- src/include/pgstat.h | 227 ++++++++++++++++++++++++------------------- 1 file changed, 125 insertions(+), 102 deletions(-) diff --git a/src/include/pgstat.h b/src/include/pgstat.h index ac28f813b4..e7a122dcdb 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -16,6 +16,7 @@ #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */ #include "utils/backend_progress.h" /* for backward compatibility */ #include "utils/backend_status.h" /* for backward compatibility */ +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/wait_event.h" /* for backward compatibility */ @@ -396,6 +397,62 @@ typedef struct PgStat_WalStats } PgStat_WalStats; +/* + * Variables in pgstat.c + */ + +/* GUC parameters */ +extern PGDLLIMPORT bool pgstat_track_counts; +extern PGDLLIMPORT int pgstat_track_functions; +extern PGDLLIMPORT int pgstat_fetch_consistency; + + +/* + * Variables in pgstat_bgwriter.c + */ + +/* updated directly by bgwriter and bufmgr */ +extern PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats; + + +/* + * Variables in pgstat_checkpointer.c + */ + +/* + * Checkpointer statistics counters are updated directly by checkpointer and + * bufmgr. + */ +extern PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats; + + +/* + * Variables in pgstat_database.c + */ + +/* Updated by pgstat_count_buffer_*_time macros */ +extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime; +extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime; + +/* + * Updated by pgstat_count_conn_*_time macros, called by + * pgstat_report_activity(). + */ +extern PGDLLIMPORT PgStat_Counter pgStatActiveTime; +extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime; + +/* updated by the traffic cop and in errfinish() */ +extern PGDLLIMPORT SessionEndType pgStatSessionEndCause; + + +/* + * Variables in pgstat_wal.c + */ + +/* updated directly by backends and background processes */ +extern PGDLLIMPORT PgStat_WalStats PendingWalStats; + + /* * Functions in pgstat.c */ @@ -465,14 +522,26 @@ extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount); extern void pgstat_report_checksum_failure(void); extern void pgstat_report_connect(Oid dboid); -#define pgstat_count_buffer_read_time(n) \ - (pgStatBlockReadTime += (n)) -#define pgstat_count_buffer_write_time(n) \ - (pgStatBlockWriteTime += (n)) -#define pgstat_count_conn_active_time(n) \ - (pgStatActiveTime += (n)) -#define pgstat_count_conn_txn_idle_time(n) \ - (pgStatTransactionIdleTime += (n)) +static inline void +pgstat_count_buffer_read_time(PgStat_Counter n) +{ + pgStatBlockReadTime += n; +} +static inline void +pgstat_count_buffer_write_time(PgStat_Counter n) +{ + pgStatBlockWriteTime += n; +} +static inline void +pgstat_count_conn_active_time(PgStat_Counter n) +{ + pgStatActiveTime += n; +} +static inline void +pgstat_count_conn_txn_idle_time(PgStat_Counter n) +{ + pgStatTransactionIdleTime += n; +} extern PgStat_StatDBEntry *pgstat_fetch_stat_dbentry(Oid dbid); @@ -516,47 +585,57 @@ extern void pgstat_report_analyze(Relation rel, * pgstat_assoc_relation() to do so. See its comment for why this is done * separately from pgstat_init_relation(). */ -#define pgstat_should_count_relation(rel) \ - (likely((rel)->pgstat_info != NULL) ? true : \ - ((rel)->pgstat_enabled ? pgstat_assoc_relation(rel), true : false)) +static inline bool +pgstat_should_count_relation(Relation rel) +{ + return (likely(rel->pgstat_info != NULL) ? true : + (rel->pgstat_enabled ? pgstat_assoc_relation(rel), true : false)); +} /* nontransactional event counts are simple enough to inline */ -#define pgstat_count_heap_scan(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_numscans++; \ - } while (0) -#define pgstat_count_heap_getnext(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_tuples_returned++; \ - } while (0) -#define pgstat_count_heap_fetch(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_tuples_fetched++; \ - } while (0) -#define pgstat_count_index_scan(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_numscans++; \ - } while (0) -#define pgstat_count_index_tuples(rel, n) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \ - } while (0) -#define pgstat_count_buffer_read(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_blocks_fetched++; \ - } while (0) -#define pgstat_count_buffer_hit(rel) \ - do { \ - if (pgstat_should_count_relation(rel)) \ - (rel)->pgstat_info->t_counts.t_blocks_hit++; \ - } while (0) +static inline void +pgstat_count_heap_scan(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_numscans++; +} +static inline void +pgstat_count_heap_getnext(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_tuples_returned++; +} +static inline void +pgstat_count_heap_fetch(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_tuples_fetched++; +} +static inline void +pgstat_count_index_scan(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_numscans++; +} +static inline void +pgstat_count_index_tuples(Relation rel, PgStat_Counter n) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_tuples_returned += n; +} +static inline void +pgstat_count_buffer_read(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_blocks_fetched++; +} +static inline void +pgstat_count_buffer_hit(Relation rel) +{ + if (pgstat_should_count_relation(rel)) + rel->pgstat_info->t_counts.t_blocks_hit++; +} extern void pgstat_count_heap_insert(Relation rel, PgStat_Counter n); extern void pgstat_count_heap_update(Relation rel, bool hot); @@ -636,60 +715,4 @@ extern void pgstat_report_wal(bool force); extern PgStat_WalStats *pgstat_fetch_stat_wal(void); -/* - * Variables in pgstat.c - */ - -/* GUC parameters */ -extern PGDLLIMPORT bool pgstat_track_counts; -extern PGDLLIMPORT int pgstat_track_functions; -extern PGDLLIMPORT int pgstat_fetch_consistency; - - -/* - * Variables in pgstat_bgwriter.c - */ - -/* updated directly by bgwriter and bufmgr */ -extern PGDLLIMPORT PgStat_BgWriterStats PendingBgWriterStats; - - -/* - * Variables in pgstat_checkpointer.c - */ - -/* - * Checkpointer statistics counters are updated directly by checkpointer and - * bufmgr. - */ -extern PGDLLIMPORT PgStat_CheckpointerStats PendingCheckpointerStats; - - -/* - * Variables in pgstat_database.c - */ - -/* Updated by pgstat_count_buffer_*_time macros */ -extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime; -extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime; - -/* - * Updated by pgstat_count_conn_*_time macros, called by - * pgstat_report_activity(). - */ -extern PGDLLIMPORT PgStat_Counter pgStatActiveTime; -extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime; - -/* updated by the traffic cop and in errfinish() */ -extern PGDLLIMPORT SessionEndType pgStatSessionEndCause; - - -/* - * Variables in pgstat_wal.c - */ - -/* updated directly by backends and background processes */ -extern PGDLLIMPORT PgStat_WalStats PendingWalStats; - - #endif /* PGSTAT_H */ -- 2.36.1