@@ -39,23 +39,21 @@ pgstat_fetch_stat_backend(ProcNumber procNumber)
3939}
4040
4141/*
42- * Flush out locally pending backend statistics
43- *
44- * If no stats have been recorded, this function returns false.
42+ * Flush out locally pending backend IO statistics. Locking is managed
43+ * by the caller.
4544 */
46- bool
47- pgstat_backend_flush_cb (PgStat_EntryRef * entry_ref , bool nowait )
45+ static void
46+ pgstat_flush_backend_entry_io (PgStat_EntryRef * entry_ref )
4847{
49- PgStatShared_Backend * shbackendioent ;
50- PgStat_BackendPendingIO * pendingent ;
48+ PgStatShared_Backend * shbackendent ;
49+ PgStat_BackendPending * pendingent ;
5150 PgStat_BktypeIO * bktype_shstats ;
51+ PgStat_PendingIO * pending_io ;
5252
53- if (!pgstat_lock_entry (entry_ref , nowait ))
54- return false;
55-
56- shbackendioent = (PgStatShared_Backend * ) entry_ref -> shared_stats ;
57- bktype_shstats = & shbackendioent -> stats .stats ;
58- pendingent = (PgStat_BackendPendingIO * ) entry_ref -> pending ;
53+ shbackendent = (PgStatShared_Backend * ) entry_ref -> shared_stats ;
54+ pendingent = (PgStat_BackendPending * ) entry_ref -> pending ;
55+ bktype_shstats = & shbackendent -> stats .io_stats ;
56+ pending_io = & pendingent -> pending_io ;
5957
6058 for (int io_object = 0 ; io_object < IOOBJECT_NUM_TYPES ; io_object ++ )
6159 {
@@ -66,26 +64,57 @@ pgstat_backend_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
6664 instr_time time ;
6765
6866 bktype_shstats -> counts [io_object ][io_context ][io_op ] +=
69- pendingent -> counts [io_object ][io_context ][io_op ];
67+ pending_io -> counts [io_object ][io_context ][io_op ];
7068
71- time = pendingent -> pending_times [io_object ][io_context ][io_op ];
69+ time = pending_io -> pending_times [io_object ][io_context ][io_op ];
7270
7371 bktype_shstats -> times [io_object ][io_context ][io_op ] +=
7472 INSTR_TIME_GET_MICROSEC (time );
7573 }
7674 }
7775 }
76+ }
77+
78+ /*
79+ * Wrapper routine to flush backend statistics.
80+ */
81+ static bool
82+ pgstat_flush_backend_entry (PgStat_EntryRef * entry_ref , bool nowait ,
83+ bits32 flags )
84+ {
85+ if (!pgstat_tracks_backend_bktype (<
67E6
span class=pl-s1>MyBackendType))
86+ return false;
87+
88+ if (!pgstat_lock_entry (entry_ref , nowait ))
89+ return false;
90+
91+ /* Flush requested statistics */
92+ if (flags & PGSTAT_BACKEND_FLUSH_IO )
93+ pgstat_flush_backend_entry_io (entry_ref );
7894
7995 pgstat_unlock_entry (entry_ref );
8096
8197 return true;
8298}
8399
84100/*
85- * Simpler wrapper of pgstat_backend_flush_cb()
101+ * Callback to flush out locally pending backend statistics.
102+ *
103+ * If no stats have been recorded, this function returns false.
104+ */
105+ bool
106+ pgstat_backend_flush_cb (PgStat_EntryRef * entry_ref , bool nowait )
107+ {
108+ return pgstat_flush_backend_entry (entry_ref , nowait , PGSTAT_BACKEND_FLUSH_ALL );
109+ }
110+
111+ /*
112+ * Flush out locally pending backend statistics
113+ *
114+ * "flags" parameter controls which statistics to flush.
86115 */
87116void
88- pgstat_flush_backend (bool nowait )
117+ pgstat_flush_backend (bool nowait , bits32 flags )
89118{
90119 PgStat_EntryRef * entry_ref ;
91120
@@ -94,7 +123,7 @@ pgstat_flush_backend(bool nowait)
94123
95124 entry_ref = pgstat_get_entry_ref (PGSTAT_KIND_BACKEND , InvalidOid ,
96125 MyProcNumber , false, NULL );
97- (void ) pgstat_backend_flush_cb (entry_ref , nowait );
126+ (void ) pgstat_flush_backend_entry (entry_ref , nowait , flags );
98127}
99128
100129/*
@@ -119,9 +148,9 @@ pgstat_create_backend(ProcNumber procnum)
119148}
120149
121150/*
122- * Find or create a local PgStat_BackendPendingIO entry for proc number.
151+ * Find or create a local PgStat_BackendPending entry for proc number.
123152 */
124- PgStat_BackendPendingIO *
153+ PgStat_BackendPending *
125154pgstat_prep_backend_pending (ProcNumber procnum )
126155{
127156 PgStat_EntryRef * entry_ref ;
0 commit comments