summaryrefslogtreecommitdiff
path: root/src/backend/utils/activity/pgstat_checkpointer.c
diff options
context:
space:
mode:
authorAndres Freund2022-03-21 19:02:25 +0000
committerAndres Freund2022-03-21 19:02:25 +0000
commit13619598f1080d7923454634a2570ca1bc0f2fec (patch)
treedc04d18eb8055eafc481f29b71095a756c20341d /src/backend/utils/activity/pgstat_checkpointer.c
parentcb02fcb4c95bae08adaca1202c2081cfc81a28b5 (diff)
pgstat: split different types of stats into separate files.
pgstat.c is very long, and it's hard to find an order that makes sense and is likely to be maintained over time. Splitting the different pieces into separate files makes that a lot easier. With a few exceptions, this commit just moves code around. Those exceptions are: - adding file headers for new files - removing 'static' from functions - adapting pgstat_assert_is_up() to work across TUs - minor comment adjustments git diff --color-moved=dimmed-zebra is very helpful separating code movement from code changes. The next commit in this series will reorder pgstat.[ch] contents to be a bit more coherent. Earlier revisions of this patch had "global" statistics (archiver, bgwriter, checkpointer, replication slots, SLRU, WAL) in one file, because each seemed small enough. However later commits will increase their size and their aggregate size is not insubstantial. It also just seems easier to split each type of statistic into its own file. Author: Andres Freund <[email protected]> Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/utils/activity/pgstat_checkpointer.c')
-rw-r--r--src/backend/utils/activity/pgstat_checkpointer.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/backend/utils/activity/pgstat_checkpointer.c b/src/backend/utils/activity/pgstat_checkpointer.c
new file mode 100644
index 00000000000..2ce3fba76c7
--- /dev/null
+++ b/src/backend/utils/activity/pgstat_checkpointer.c
@@ -0,0 +1,61 @@
+/* -------------------------------------------------------------------------
+ *
+ * pgstat_checkpointer.c
+ * Implementation of checkpoint statistics.
+ *
+ * This file contains the implementation of checkpoint statistics. It is kept
+ * separate from pgstat.c to enforce the line between the statistics access /
+ * storage implementation and the details about individual types of
+ * statistics.
+ *
+ * Copyright (c) 2001-2022, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * src/backend/utils/activity/pgstat_checkpointer.c
+ * -------------------------------------------------------------------------
+ */
+
+#include "postgres.h"
+
+#include "utils/pgstat_internal.h"
+
+
+/*
+ * Checkpointer global statistics counters. Stored directly in a stats
+ * message structure so they can be sent without needing to copy things
+ * around. We assume this init to zeroes.
+ */
+PgStat_MsgCheckpointer PendingCheckpointerStats;
+
+
+/* ----------
+ * pgstat_send_checkpointer() -
+ *
+ * Send checkpointer statistics to the collector
+ * ----------
+ */
+void
+pgstat_send_checkpointer(void)
+{
+ /* We assume this initializes to zeroes */
+ static const PgStat_MsgCheckpointer all_zeroes;
+
+ /*
+ * This function can be called even if nothing at all has happened. In
+ * this case, avoid sending a completely empty message to the stats
+ * collector.
+ */
+ if (memcmp(&PendingCheckpointerStats, &all_zeroes, sizeof(PgStat_MsgCheckpointer)) == 0)
+ return;
+
+ /*
+ * Prepare and send the message
+ */
+ pgstat_setheader(&PendingCheckpointerStats.m_hdr, PGSTAT_MTYPE_CHECKPOINTER);
+ pgstat_send(&PendingCheckpointerStats, sizeof(PendingCheckpointerStats));
+
+ /*
+ * Clear out the statistics buffer, so it can be re-used.
+ */
+ MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats));
+}