---------- * pgstat_send_wal() - * * Send WAL statistics to the collector. * * If 'force' is not set, WAL stats message is only sent if enough time has * passed since last one was sent to reach PGSTAT_STAT_INTERVAL. * ---------- */
| 3361 | * ---------- |
| 3362 | */ |
| 3363 | void |
| 3364 | pgstat_send_wal(bool force) |
| 3365 | { |
| 3366 | static TimestampTz sendTime = 0; |
| 3367 | |
| 3368 | /* |
| 3369 | * This function can be called even if nothing at all has happened. In |
| 3370 | * this case, avoid sending a completely empty message to the stats |
| 3371 | * collector. |
| 3372 | * |
| 3373 | * Check wal_records counter to determine whether any WAL activity has |
| 3374 | * happened since last time. Note that other WalUsage counters don't need |
| 3375 | * to be checked because they are incremented always together with |
| 3376 | * wal_records counter. |
| 3377 | * |
| 3378 | * m_wal_buffers_full also doesn't need to be checked because it's |
| 3379 | * incremented only when at least one WAL record is generated (i.e., |
| 3380 | * wal_records counter is incremented). But for safely, we assert that |
| 3381 | * m_wal_buffers_full is always zero when no WAL record is generated |
| 3382 | * |
| 3383 | * This function can be called by a process like walwriter that normally |
| 3384 | * generates no WAL records. To determine whether any WAL activity has |
| 3385 | * happened at that process since the last time, the numbers of WAL writes |
| 3386 | * and syncs are also checked. |
| 3387 | */ |
| 3388 | if (pgWalUsage.wal_records == prevWalUsage.wal_records && |
| 3389 | WalStats.m_wal_write == 0 && WalStats.m_wal_sync == 0) |
| 3390 | { |
| 3391 | Assert(WalStats.m_wal_buffers_full == 0); |
| 3392 | return; |
| 3393 | } |
| 3394 | |
| 3395 | if (!force) |
| 3396 | { |
| 3397 | TimestampTz now = GetCurrentTimestamp(); |
| 3398 | |
| 3399 | /* |
| 3400 | * Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL |
| 3401 | * msec since we last sent one to avoid overloading the stats |
| 3402 | * collector. |
| 3403 | */ |
| 3404 | if (!TimestampDifferenceExceeds(sendTime, now, PGSTAT_STAT_INTERVAL)) |
| 3405 | return; |
| 3406 | sendTime = now; |
| 3407 | } |
| 3408 | |
| 3409 | /* |
| 3410 | * Set the counters related to generated WAL data if the counters were |
| 3411 | * updated. |
| 3412 | */ |
| 3413 | if (pgWalUsage.wal_records != prevWalUsage.wal_records) |
| 3414 | { |
| 3415 | WalUsage walusage; |
| 3416 | |
| 3417 | /* |
| 3418 | * Calculate how much WAL usage counters were increased by |
| 3419 | * substracting the previous counters from the current ones. Fill the |
| 3420 | * results in WAL stats message. |
no test coverage detected