LCOV - code coverage report
Current view: top level - pgxn/neon/communicator/src/worker_process - callbacks.rs (source / functions) Coverage Total Hit
Test: 4be46b1c0003aa3bbac9ade362c676b419df4c20.info Lines: 0.0 % 10 0
Test Date: 2025-07-22 17:50:06 Functions: 0.0 % 4 0

            Line data    Source code
       1              : //! C callbacks to PostgreSQL facilities that the neon extension needs to provide. These
       2              : //! are implemented in `neon/pgxn/communicator_process.c`. The function signatures better
       3              : //! match!
       4              : //!
       5              : //! These are called from the communicator threads! Careful what you do, most Postgres
       6              : //! functions are not safe to call in that context.
       7              : 
       8              : #[cfg(not(test))]
       9              : unsafe extern "C" {
      10              :     pub fn callback_set_my_latch_unsafe();
      11              :     pub fn callback_get_lfc_metrics_unsafe() -> LfcMetrics;
      12              : }
      13              : 
      14              : // Compile unit tests with dummy versions of the functions. Unit tests cannot call back
      15              : // into the C code. (As of this writing, no unit tests even exists in the communicator
      16              : // package, but the code coverage build still builds these and tries to link with the
      17              : // external C code.)
      18              : #[cfg(test)]
      19            0 : unsafe fn callback_set_my_latch_unsafe() {
      20            0 :     panic!("not usable in unit tests");
      21              : }
      22              : #[cfg(test)]
      23            0 : unsafe fn callback_get_lfc_metrics_unsafe() -> LfcMetrics {
      24            0 :     panic!("not usable in unit tests");
      25              : }
      26              : 
      27              : // safe wrappers
      28              : 
      29            0 : pub(super) fn callback_set_my_latch() {
      30            0 :     unsafe { callback_set_my_latch_unsafe() };
      31            0 : }
      32              : 
      33            0 : pub(super) fn callback_get_lfc_metrics() -> LfcMetrics {
      34            0 :     unsafe { callback_get_lfc_metrics_unsafe() }
      35            0 : }
      36              : 
      37              : /// Return type of the callback_get_lfc_metrics() function.
      38              : #[repr(C)]
      39              : pub struct LfcMetrics {
      40              :     pub lfc_cache_size_limit: i64,
      41              :     pub lfc_hits: i64,
      42              :     pub lfc_misses: i64,
      43              :     pub lfc_used: i64,
      44              :     pub lfc_writes: i64,
      45              : 
      46              :     // working set size looking back 1..60 minutes.
      47              :     //
      48              :     // Index 0 is the size of the working set accessed within last 1 minute,
      49              :     // index 59 is the size of the working set accessed within last 60 minutes.
      50              :     pub lfc_approximate_working_set_size_windows: [i64; 60],
      51              : }
        

Generated by: LCOV version 2.1-beta