Branch data Line data Source code
1 : : /* ----------
2 : : * pgstat_kind.h
3 : : *
4 : : * Definitions related to the statistics kinds for the PostgreSQL
5 : : * cumulative statistics system. Can be included in backend or
6 : : * frontend code.
7 : : *
8 : : * Copyright (c) 2001-2026, PostgreSQL Global Development Group
9 : : *
10 : : * src/include/utils/pgstat_kind.h
11 : : * ----------
12 : : */
13 : : #ifndef PGSTAT_KIND_H
14 : : #define PGSTAT_KIND_H
15 : :
16 : : /* The types of statistics entries */
17 : : #define PgStat_Kind uint32
18 : :
19 : : /* Range of IDs allowed, for built-in and custom kinds */
20 : : #define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */
21 : : #define PGSTAT_KIND_MAX 32 /* Maximum ID allowed */
22 : :
23 : : /* use 0 for INVALID, to catch zero-initialized data */
24 : : #define PGSTAT_KIND_INVALID 0
25 : :
26 : : /* stats for variable-numbered objects */
27 : : #define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */
28 : : #define PGSTAT_KIND_RELATION 2 /* per-table statistics */
29 : : #define PGSTAT_KIND_INDEX 3 /* per-index statistics */
30 : : #define PGSTAT_KIND_FUNCTION 4 /* per-function statistics */
31 : : #define PGSTAT_KIND_REPLSLOT 5 /* per-slot statistics */
32 : : #define PGSTAT_KIND_SUBSCRIPTION 6 /* per-subscription statistics */
33 : : #define PGSTAT_KIND_BACKEND 7 /* per-backend statistics */
34 : :
35 : : /* stats for fixed-numbered objects */
36 : : #define PGSTAT_KIND_ARCHIVER 8
37 : : #define PGSTAT_KIND_BGWRITER 9
38 : : #define PGSTAT_KIND_CHECKPOINTER 10
39 : : #define PGSTAT_KIND_IO 11
40 : : #define PGSTAT_KIND_LOCK 12
41 : : #define PGSTAT_KIND_SLRU 13
42 : : #define PGSTAT_KIND_WAL 14
43 : :
44 : : #define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
45 : : #define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
46 : : #define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
47 : :
48 : : /* Custom stats kinds */
49 : :
50 : : /* Range of IDs allowed for custom stats kinds */
51 : : #define PGSTAT_KIND_CUSTOM_MIN 24
52 : : #define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
53 : : #define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
54 : :
55 : : /*
56 : : * PgStat_Kind to use for extensions that require an ID, but are still in
57 : : * development and have not reserved their own unique kind ID yet. See:
58 : : * https://wiki.postgresql.org/wiki/CustomCumulativeStats
59 : : */
60 : : #define PGSTAT_KIND_EXPERIMENTAL 24
61 : :
62 : : static inline bool
63 : 9530495 : pgstat_is_kind_builtin(PgStat_Kind kind)
64 : : {
65 [ + - + + ]: 9530495 : return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX;
66 : : }
67 : :
68 : : static inline bool
69 : 1511748 : pgstat_is_kind_custom(PgStat_Kind kind)
70 : : {
71 [ + + + - ]: 1511748 : return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX;
72 : : }
73 : :
74 : : #endif /* PGSTAT_KIND_H */
|