LCOV - code coverage report
Current view: top level - src/backend/utils/activity - pgstat_kind.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 20 20
Test Date: 2026-07-08 05:15:38 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 6 6

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * pgstat_kind.c
       4                 :             :  *    Functions related to statistics kinds.
       5                 :             :  *
       6                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :             :  *
       9                 :             :  *
      10                 :             :  * IDENTIFICATION
      11                 :             :  *    src/backend/utils/activity/pgstat_kind.c
      12                 :             :  *
      13                 :             :  *-------------------------------------------------------------------------
      14                 :             :  */
      15                 :             : #include "postgres.h"
      16                 :             : 
      17                 :             : #include "fmgr.h"
      18                 :             : #include "funcapi.h"
      19                 :             : #include "utils/builtins.h"
      20                 :             : #include "utils/fmgrprotos.h"
      21                 :             : #include "utils/pgstat_internal.h"
      22                 :             : #include "utils/pgstat_kind.h"
      23                 :             : #include "utils/tuplestore.h"
      24                 :             : 
      25                 :             : 
      26                 :             : /*
      27                 :             :  * pg_stat_get_kind_info
      28                 :             :  *
      29                 :             :  * Get information about the statistics kinds registered into the system.
      30                 :             :  */
      31                 :             : Datum
      32                 :           5 : pg_stat_get_kind_info(PG_FUNCTION_ARGS)
      33                 :             : {
      34                 :             : #define PG_STAT_KIND_INFO_COLS  7
      35                 :             :     ReturnSetInfo *rsinfo;
      36                 :             : 
      37                 :           5 :     InitMaterializedSRF(fcinfo, 0);
      38                 :           5 :     rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
      39                 :             : 
      40         [ +  + ]:         165 :     for (int kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
      41                 :             :     {
      42                 :         160 :         Datum       values[PG_STAT_KIND_INFO_COLS] = {0};
      43                 :         160 :         bool        nulls[PG_STAT_KIND_INFO_COLS] = {0};
      44                 :             :         const PgStat_KindInfo *info;
      45                 :             : 
      46                 :         160 :         info = pgstat_get_kind_info(kind);
      47         [ +  + ]:         160 :         if (info == NULL)
      48                 :          93 :             continue;
      49                 :             : 
      50                 :          67 :         values[0] = Int32GetDatum(kind);
      51                 :          67 :         values[1] = CStringGetTextDatum(info->name);
      52                 :             : 
      53                 :          67 :         values[2] = BoolGetDatum(pgstat_is_kind_builtin(kind));
      54                 :          67 :         values[3] = BoolGetDatum(info->fixed_amount);
      55                 :          67 :         values[4] = BoolGetDatum(info->accessed_across_databases);
      56                 :          67 :         values[5] = BoolGetDatum(info->write_to_file);
      57                 :             : 
      58                 :             :         /*
      59                 :             :          * When track_entry_count is disabled, use NULL.  Fixed-sized stats
      60                 :             :          * kinds report NULL here.
      61                 :             :          */
      62         [ +  + ]:          67 :         if (info->track_entry_count)
      63                 :           1 :             values[6] = Int64GetDatum(pgstat_get_entry_count(kind));
      64                 :             :         else
      65                 :          66 :             nulls[6] = true;
      66                 :             : 
      67                 :          67 :         tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
      68                 :             :     }
      69                 :             : 
      70                 :           5 :     return (Datum) 0;
      71                 :             : #undef PG_STAT_KIND_INFO_COLS
      72                 :             : }
        

Generated by: LCOV version 2.0-1