Format sources (#475)
* Temporary disable workflows * Add indent target to makefiel * Add CI workflow to check if sources formatted * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Format sources * Add comments * Revert "Temporary disable workflows" This reverts commitpull/483/head7e11cf6154
. * Revert "Format sources" This reverts commit6ef992d9f0
. * Use PG17 for code formatt * Format sources * Revert "Format sources" This reverts commit34061e1f82
. * Format sources
parent
130d6b5fce
commit
3bb65798fd
|
@ -35,6 +35,49 @@ jobs:
|
||||||
set -x
|
set -x
|
||||||
cppcheck --enable=all --inline-suppr --template='{file}:{line},{severity},{id},{message}' --error-exitcode=1 --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unmatchedSuppression:pg_stat_monitor.c --check-config .
|
cppcheck --enable=all --inline-suppr --template='{file}:{line},{severity},{id},{message}' --error-exitcode=1 --suppress=missingIncludeSystem --suppress=missingInclude --suppress=unmatchedSuppression:pg_stat_monitor.c --check-config .
|
||||||
|
|
||||||
|
format:
|
||||||
|
name: Format
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Clone postgres repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: 'postgres/postgres'
|
||||||
|
ref: 'REL_17_STABLE'
|
||||||
|
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: 'contrib/pg_stat_monitor'
|
||||||
|
|
||||||
|
- name: Configure postgres
|
||||||
|
run: ./configure
|
||||||
|
|
||||||
|
- name: Install perltidy
|
||||||
|
run: sudo cpan -T SHANCOCK/Perl-Tidy-20230309.tar.gz
|
||||||
|
|
||||||
|
- name: Install pg_bsd_indent
|
||||||
|
working-directory: src/tools/pg_bsd_indent
|
||||||
|
run: sudo make install
|
||||||
|
|
||||||
|
- name: Add pg_bsd_indent and pgindent to path
|
||||||
|
run: |
|
||||||
|
echo "/usr/local/pgsql/bin" >> $GITHUB_PATH
|
||||||
|
echo "${{ github.workspace }}/src/tools/pgindent" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Format sources
|
||||||
|
working-directory: contrib/pg_stat_monitor
|
||||||
|
run: |
|
||||||
|
make update-typedefs
|
||||||
|
make indent
|
||||||
|
|
||||||
|
- name: Check files are formatted and no source code changes
|
||||||
|
working-directory: contrib/pg_stat_monitor
|
||||||
|
run: |
|
||||||
|
git status
|
||||||
|
git diff --exit-code
|
||||||
|
|
||||||
license:
|
license:
|
||||||
name: License
|
name: License
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
|
@ -60,3 +60,6 @@ dkms.conf
|
||||||
## .vscode
|
## .vscode
|
||||||
.vscode/
|
.vscode/
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|
||||||
|
# tools files
|
||||||
|
typedefs-full.list
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -30,3 +30,14 @@ top_builddir = ../..
|
||||||
include $(top_builddir)/src/Makefile.global
|
include $(top_builddir)/src/Makefile.global
|
||||||
include $(top_srcdir)/contrib/contrib-global.mk
|
include $(top_srcdir)/contrib/contrib-global.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Fetches typedefs list for PostgreSQL core and merges it with typedefs defined in this project.
|
||||||
|
# https://wiki.postgresql.org/wiki/Running_pgindent_on_non-core_code_or_development_code
|
||||||
|
update-typedefs:
|
||||||
|
wget -q -O - "https://buildfarm.postgresql.org/cgi-bin/typedefs.pl?branch=REL_17_STABLE" | cat - typedefs.list | sort | uniq > typedefs-full.list
|
||||||
|
|
||||||
|
# Indents projects sources.
|
||||||
|
indent:
|
||||||
|
pgindent --typedefs=typedefs-full.list .
|
||||||
|
|
||||||
|
.PHONY: update-typedefs indent
|
2
guc.c
2
guc.c
|
@ -49,7 +49,7 @@ static bool check_overflow_targer(int *newval, void **extra, GucSource source);
|
||||||
void
|
void
|
||||||
init_guc(void)
|
init_guc(void)
|
||||||
{
|
{
|
||||||
pgsm_track = PGSM_TRACK_TOP;
|
pgsm_track = PGSM_TRACK_TOP;
|
||||||
|
|
||||||
DefineCustomIntVariable("pg_stat_monitor.pgsm_max", /* name */
|
DefineCustomIntVariable("pg_stat_monitor.pgsm_max", /* name */
|
||||||
"Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.", /* short_desc */
|
"Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.", /* short_desc */
|
||||||
|
|
23
hash_query.c
23
hash_query.c
|
@ -19,9 +19,9 @@
|
||||||
#include "pg_stat_monitor.h"
|
#include "pg_stat_monitor.h"
|
||||||
|
|
||||||
static pgsmLocalState pgsmStateLocal;
|
static pgsmLocalState pgsmStateLocal;
|
||||||
static PGSM_HASH_TABLE_HANDLE pgsm_create_bucket_hash(pgsmSharedState * pgsm, dsa_area *dsa);
|
static PGSM_HASH_TABLE_HANDLE pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa);
|
||||||
static Size pgsm_get_shared_area_size(void);
|
static Size pgsm_get_shared_area_size(void);
|
||||||
static void InitializeSharedState(pgsmSharedState * pgsm);
|
static void InitializeSharedState(pgsmSharedState *pgsm);
|
||||||
|
|
||||||
#define PGSM_BUCKET_INFO_SIZE (sizeof(TimestampTz) * pgsm_max_buckets)
|
#define PGSM_BUCKET_INFO_SIZE (sizeof(TimestampTz) * pgsm_max_buckets)
|
||||||
#define PGSM_SHARED_STATE_SIZE (sizeof(pgsmSharedState) + PGSM_BUCKET_INFO_SIZE)
|
#define PGSM_SHARED_STATE_SIZE (sizeof(pgsmSharedState) + PGSM_BUCKET_INFO_SIZE)
|
||||||
|
@ -142,9 +142,9 @@ pgsm_startup(void)
|
||||||
*/
|
*/
|
||||||
dsa_detach(dsa);
|
dsa_detach(dsa);
|
||||||
|
|
||||||
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
|
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
|
||||||
"pg_stat_monitor local store",
|
"pg_stat_monitor local store",
|
||||||
ALLOCSET_DEFAULT_SIZES);
|
ALLOCSET_DEFAULT_SIZES);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BENCHMARK
|
#ifdef BENCHMARK
|
||||||
|
@ -161,7 +161,7 @@ pgsm_startup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitializeSharedState(pgsmSharedState * pgsm)
|
InitializeSharedState(pgsmSharedState *pgsm)
|
||||||
{
|
{
|
||||||
pg_atomic_init_u64(&pgsm->current_wbucket, 0);
|
pg_atomic_init_u64(&pgsm->current_wbucket, 0);
|
||||||
pg_atomic_init_u64(&pgsm->prev_bucket_sec, 0);
|
pg_atomic_init_u64(&pgsm->prev_bucket_sec, 0);
|
||||||
|
@ -172,7 +172,7 @@ InitializeSharedState(pgsmSharedState * pgsm)
|
||||||
* Create the classic or dshahs hash table for storing the query statistics.
|
* Create the classic or dshahs hash table for storing the query statistics.
|
||||||
*/
|
*/
|
||||||
static PGSM_HASH_TABLE_HANDLE
|
static PGSM_HASH_TABLE_HANDLE
|
||||||
pgsm_create_bucket_hash(pgsmSharedState * pgsm, dsa_area *dsa)
|
pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa)
|
||||||
{
|
{
|
||||||
PGSM_HASH_TABLE_HANDLE bucket_hash;
|
PGSM_HASH_TABLE_HANDLE bucket_hash;
|
||||||
|
|
||||||
|
@ -238,7 +238,8 @@ pgsm_attach_shmem(void)
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryContext GetPgsmMemoryContext(void)
|
MemoryContext
|
||||||
|
GetPgsmMemoryContext(void)
|
||||||
{
|
{
|
||||||
return pgsmStateLocal.pgsm_mem_cxt;
|
return pgsmStateLocal.pgsm_mem_cxt;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +288,7 @@ pgsm_shmem_shutdown(int code, Datum arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pgsmEntry *
|
pgsmEntry *
|
||||||
hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding)
|
hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
||||||
{
|
{
|
||||||
pgsmEntry *entry = NULL;
|
pgsmEntry *entry = NULL;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
@ -393,7 +394,7 @@ IsSystemOOM(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *
|
void *
|
||||||
pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found)
|
pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
void *entry;
|
void *entry;
|
||||||
|
@ -406,7 +407,7 @@ pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found)
|
pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
return dshash_find(shared_hash, key, false);
|
return dshash_find(shared_hash, key, false);
|
||||||
|
|
|
@ -33,7 +33,7 @@ typedef enum pgsmVersion
|
||||||
PGSM_V1_0 = 0,
|
PGSM_V1_0 = 0,
|
||||||
PGSM_V2_0,
|
PGSM_V2_0,
|
||||||
PGSM_V2_1
|
PGSM_V2_1
|
||||||
} pgsmVersion;
|
} pgsmVersion;
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
|
@ -201,9 +201,9 @@ DECLARE_HOOK(void pgsm_ProcessUtility, PlannedStmt *pstmt, const char *queryStri
|
||||||
static uint64 pgsm_hash_string(const char *str, int len);
|
static uint64 pgsm_hash_string(const char *str, int len);
|
||||||
char *unpack_sql_state(int sql_state);
|
char *unpack_sql_state(int sql_state);
|
||||||
|
|
||||||
static pgsmEntry * pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo * plan_info);
|
static pgsmEntry *pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info);
|
||||||
static void pgsm_add_to_list(pgsmEntry * entry, char *query_text, int query_len);
|
static void pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len);
|
||||||
static pgsmEntry * pgsm_get_entry_for_query(uint64 queryid, PlanInfo * plan_info, const char *query_text, int query_len, bool create);
|
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create);
|
||||||
static uint64 get_pgsm_query_id_hash(const char *norm_query, int len);
|
static uint64 get_pgsm_query_id_hash(const char *norm_query, int len);
|
||||||
|
|
||||||
static void pgsm_cleanup_callback(void *arg);
|
static void pgsm_cleanup_callback(void *arg);
|
||||||
|
@ -217,13 +217,13 @@ MemoryContextCallback mem_cxt_reset_callback =
|
||||||
};
|
};
|
||||||
volatile bool callback_setup = false;
|
volatile bool callback_setup = false;
|
||||||
|
|
||||||
static void pgsm_update_entry(pgsmEntry * entry,
|
static void pgsm_update_entry(pgsmEntry *entry,
|
||||||
const char *query,
|
const char *query,
|
||||||
char *comments,
|
char *comments,
|
||||||
int comments_len,
|
int comments_len,
|
||||||
PlanInfo * plan_info,
|
PlanInfo *plan_info,
|
||||||
SysInfo * sys_info,
|
SysInfo *sys_info,
|
||||||
ErrorInfo * error_info,
|
ErrorInfo *error_info,
|
||||||
double plan_total_time,
|
double plan_total_time,
|
||||||
double exec_total_time,
|
double exec_total_time,
|
||||||
uint64 rows,
|
uint64 rows,
|
||||||
|
@ -232,7 +232,7 @@ static void pgsm_update_entry(pgsmEntry * entry,
|
||||||
const struct JitInstrumentation *jitusage,
|
const struct JitInstrumentation *jitusage,
|
||||||
bool reset,
|
bool reset,
|
||||||
pgsmStoreKind kind);
|
pgsmStoreKind kind);
|
||||||
static void pgsm_store(pgsmEntry * entry);
|
static void pgsm_store(pgsmEntry *entry);
|
||||||
|
|
||||||
static void pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
static void pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
pgsmVersion api_version,
|
pgsmVersion api_version,
|
||||||
|
@ -259,7 +259,7 @@ static char *generate_normalized_query(JumbleState *jstate, const char *query,
|
||||||
static void fill_in_constant_lengths(JumbleState *jstate, const char *query, int query_loc);
|
static void fill_in_constant_lengths(JumbleState *jstate, const char *query, int query_loc);
|
||||||
static int comp_location(const void *a, const void *b);
|
static int comp_location(const void *a, const void *b);
|
||||||
|
|
||||||
static uint64 get_next_wbucket(pgsmSharedState * pgsm);
|
static uint64 get_next_wbucket(pgsmSharedState *pgsm);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Module load callback
|
* Module load callback
|
||||||
|
@ -696,7 +696,7 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
|
||||||
/* Extract the plan information in case of SELECT statement */
|
/* Extract the plan information in case of SELECT statement */
|
||||||
if (queryDesc->operation == CMD_SELECT && pgsm_enable_query_plan)
|
if (queryDesc->operation == CMD_SELECT && pgsm_enable_query_plan)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
MemoryContext oldctx;
|
MemoryContext oldctx;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -806,9 +806,9 @@ pgsm_ExecutorCheckPerms(List *rt, List *rp, bool abort)
|
||||||
|
|
||||||
if (rte->rtekind != RTE_RELATION
|
if (rte->rtekind != RTE_RELATION
|
||||||
#if PG_VERSION_NUM >= 160000
|
#if PG_VERSION_NUM >= 160000
|
||||||
&& (rte->rtekind != RTE_SUBQUERY && rte->relkind != 'v')
|
&& (rte->rtekind != RTE_SUBQUERY && rte->relkind != 'v')
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (i < REL_LST)
|
if (i < REL_LST)
|
||||||
|
@ -1417,13 +1417,13 @@ pg_get_client_addr(bool *ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgsm_update_entry(pgsmEntry * entry,
|
pgsm_update_entry(pgsmEntry *entry,
|
||||||
const char *query,
|
const char *query,
|
||||||
char *comments,
|
char *comments,
|
||||||
int comments_len,
|
int comments_len,
|
||||||
PlanInfo * plan_info,
|
PlanInfo *plan_info,
|
||||||
SysInfo * sys_info,
|
SysInfo *sys_info,
|
||||||
ErrorInfo * error_info,
|
ErrorInfo *error_info,
|
||||||
double plan_total_time,
|
double plan_total_time,
|
||||||
double exec_total_time,
|
double exec_total_time,
|
||||||
uint64 rows,
|
uint64 rows,
|
||||||
|
@ -1439,7 +1439,10 @@ pgsm_update_entry(pgsmEntry * entry,
|
||||||
int sqlcode_len = error_info ? strlen(error_info->sqlcode) : 0;
|
int sqlcode_len = error_info ? strlen(error_info->sqlcode) : 0;
|
||||||
int plan_text_len = plan_info ? plan_info->plan_len : 0;
|
int plan_text_len = plan_info ? plan_info->plan_len : 0;
|
||||||
|
|
||||||
/* Start collecting data for next bucket and reset all counters and timestamps */
|
/*
|
||||||
|
* Start collecting data for next bucket and reset all counters and
|
||||||
|
* timestamps
|
||||||
|
*/
|
||||||
if (reset)
|
if (reset)
|
||||||
{
|
{
|
||||||
memset(&entry->counters, 0, sizeof(Counters));
|
memset(&entry->counters, 0, sizeof(Counters));
|
||||||
|
@ -1449,7 +1452,7 @@ pgsm_update_entry(pgsmEntry * entry,
|
||||||
|
|
||||||
/* volatile block */
|
/* volatile block */
|
||||||
{
|
{
|
||||||
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
|
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
|
||||||
|
|
||||||
if (kind == PGSM_STORE)
|
if (kind == PGSM_STORE)
|
||||||
SpinLockAcquire(&e->mutex);
|
SpinLockAcquire(&e->mutex);
|
||||||
|
@ -1575,7 +1578,7 @@ pgsm_update_entry(pgsmEntry * entry,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert(!DsaPointerIsValid(e->counters.info.parent_query));
|
Assert(!DsaPointerIsValid(e->counters.info.parent_query));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1715,7 +1718,7 @@ pgsm_store_error(const char *query, ErrorData *edata)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgsm_add_to_list(pgsmEntry * entry, char *query_text, int query_len)
|
pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len)
|
||||||
{
|
{
|
||||||
/* Switch to pgsm memory context */
|
/* Switch to pgsm memory context */
|
||||||
MemoryContext oldctx = MemoryContextSwitchTo(GetPgsmMemoryContext());
|
MemoryContext oldctx = MemoryContextSwitchTo(GetPgsmMemoryContext());
|
||||||
|
@ -1726,7 +1729,7 @@ pgsm_add_to_list(pgsmEntry * entry, char *query_text, int query_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
static pgsmEntry *
|
static pgsmEntry *
|
||||||
pgsm_get_entry_for_query(uint64 queryid, PlanInfo * plan_info, const char *query_text, int query_len, bool create)
|
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create)
|
||||||
{
|
{
|
||||||
pgsmEntry *entry = NULL;
|
pgsmEntry *entry = NULL;
|
||||||
ListCell *lc = NULL;
|
ListCell *lc = NULL;
|
||||||
|
@ -1784,7 +1787,7 @@ pgsm_cleanup_callback(void *arg)
|
||||||
* The bucket_id may not be known at this stage. So pass any value that you may wish.
|
* The bucket_id may not be known at this stage. So pass any value that you may wish.
|
||||||
*/
|
*/
|
||||||
static pgsmEntry *
|
static pgsmEntry *
|
||||||
pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo * plan_info)
|
pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info)
|
||||||
{
|
{
|
||||||
pgsmEntry *entry;
|
pgsmEntry *entry;
|
||||||
int sec_ctx;
|
int sec_ctx;
|
||||||
|
@ -1870,7 +1873,7 @@ pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo * plan_info)
|
||||||
* query string. total_time, rows, bufusage are ignored in this case.
|
* query string. total_time, rows, bufusage are ignored in this case.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
pgsm_store(pgsmEntry * entry)
|
pgsm_store(pgsmEntry *entry)
|
||||||
{
|
{
|
||||||
pgsmEntry *shared_hash_entry;
|
pgsmEntry *shared_hash_entry;
|
||||||
pgsmSharedState *pgsm;
|
pgsmSharedState *pgsm;
|
||||||
|
@ -1946,8 +1949,8 @@ pgsm_store(pgsmEntry * entry)
|
||||||
memcpy(&jitusage.emission_counter, &entry->counters.jitinfo.instr_emission_counter, sizeof(instr_time));
|
memcpy(&jitusage.emission_counter, &entry->counters.jitinfo.instr_emission_counter, sizeof(instr_time));
|
||||||
|
|
||||||
|
|
||||||
// Update parent id if needed
|
/* Update parent id if needed */
|
||||||
if(pgsm_track == PGSM_TRACK_ALL && nesting_level > 0 && nesting_level < max_stack_depth)
|
if (pgsm_track == PGSM_TRACK_ALL && nesting_level > 0 && nesting_level < max_stack_depth)
|
||||||
{
|
{
|
||||||
entry->key.parentid = nested_queryids[nesting_level - 1];
|
entry->key.parentid = nested_queryids[nesting_level - 1];
|
||||||
}
|
}
|
||||||
|
@ -2033,9 +2036,9 @@ pgsm_store(pgsmEntry * entry)
|
||||||
{
|
{
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||||
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
|
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
|
||||||
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
|
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
|
||||||
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
|
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
|
||||||
} PGSM_END_DISABLE_ERROR_CAPTURE();
|
} PGSM_END_DISABLE_ERROR_CAPTURE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2243,7 +2246,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
bool nulls[PG_STAT_MONITOR_COLS] = {0};
|
bool nulls[PG_STAT_MONITOR_COLS] = {0};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Counters tmp;
|
Counters tmp;
|
||||||
pgsmHashKey tmpkey;
|
pgsmHashKey tmpkey;
|
||||||
double stddev;
|
double stddev;
|
||||||
uint64 queryid = entry->key.queryid;
|
uint64 queryid = entry->key.queryid;
|
||||||
int64 bucketid = entry->key.bucket_id;
|
int64 bucketid = entry->key.bucket_id;
|
||||||
|
@ -2276,7 +2279,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
|
|
||||||
/* copy counters to a local variable to keep locking time short */
|
/* copy counters to a local variable to keep locking time short */
|
||||||
{
|
{
|
||||||
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
|
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
|
||||||
|
|
||||||
SpinLockAcquire(&e->mutex);
|
SpinLockAcquire(&e->mutex);
|
||||||
tmp = e->counters;
|
tmp = e->counters;
|
||||||
|
@ -2603,7 +2606,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64
|
static uint64
|
||||||
get_next_wbucket(pgsmSharedState * pgsm)
|
get_next_wbucket(pgsmSharedState *pgsm)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
uint64 current_bucket_sec;
|
uint64 current_bucket_sec;
|
||||||
|
|
|
@ -195,7 +195,7 @@ typedef enum pgsmStoreKind
|
||||||
PGSM_ERROR,
|
PGSM_ERROR,
|
||||||
|
|
||||||
PGSM_NUMKIND /* Must be last value of this enum */
|
PGSM_NUMKIND /* Must be last value of this enum */
|
||||||
} pgsmStoreKind;
|
} pgsmStoreKind;
|
||||||
|
|
||||||
/* the assumption of query max nested level */
|
/* the assumption of query max nested level */
|
||||||
#define DEFAULT_MAX_NESTED_LEVEL 10
|
#define DEFAULT_MAX_NESTED_LEVEL 10
|
||||||
|
@ -208,7 +208,7 @@ typedef enum AGG_KEY
|
||||||
AGG_KEY_DATABASE = 0,
|
AGG_KEY_DATABASE = 0,
|
||||||
AGG_KEY_USER,
|
AGG_KEY_USER,
|
||||||
AGG_KEY_HOST
|
AGG_KEY_HOST
|
||||||
} AGG_KEY;
|
} AGG_KEY;
|
||||||
|
|
||||||
#define MAX_QUERY_LEN 1024
|
#define MAX_QUERY_LEN 1024
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ typedef struct CallTime
|
||||||
double max_time; /* maximum execution time in msec */
|
double max_time; /* maximum execution time in msec */
|
||||||
double mean_time; /* mean execution time in msec */
|
double mean_time; /* mean execution time in msec */
|
||||||
double sum_var_time; /* sum of variances in execution time in msec */
|
double sum_var_time; /* sum of variances in execution time in msec */
|
||||||
} CallTime;
|
} CallTime;
|
||||||
|
|
||||||
|
|
||||||
typedef struct PlanInfo
|
typedef struct PlanInfo
|
||||||
|
@ -228,7 +228,7 @@ typedef struct PlanInfo
|
||||||
uint64 planid; /* plan identifier */
|
uint64 planid; /* plan identifier */
|
||||||
char plan_text[PLAN_TEXT_LEN]; /* plan text */
|
char plan_text[PLAN_TEXT_LEN]; /* plan text */
|
||||||
size_t plan_len; /* strlen(plan_text) */
|
size_t plan_len; /* strlen(plan_text) */
|
||||||
} PlanInfo;
|
} PlanInfo;
|
||||||
|
|
||||||
typedef struct pgsmHashKey
|
typedef struct pgsmHashKey
|
||||||
{
|
{
|
||||||
|
@ -241,7 +241,7 @@ typedef struct pgsmHashKey
|
||||||
uint32 ip; /* client ip address */
|
uint32 ip; /* client ip address */
|
||||||
bool toplevel; /* query executed at top level */
|
bool toplevel; /* query executed at top level */
|
||||||
uint64 parentid; /* parent queryid of current query */
|
uint64 parentid; /* parent queryid of current query */
|
||||||
} pgsmHashKey;
|
} pgsmHashKey;
|
||||||
|
|
||||||
typedef struct QueryInfo
|
typedef struct QueryInfo
|
||||||
{
|
{
|
||||||
|
@ -262,46 +262,53 @@ typedef struct ErrorInfo
|
||||||
int64 elevel; /* error elevel */
|
int64 elevel; /* error elevel */
|
||||||
char sqlcode[SQLCODE_LEN]; /* error sqlcode */
|
char sqlcode[SQLCODE_LEN]; /* error sqlcode */
|
||||||
char message[ERROR_MESSAGE_LEN]; /* error message text */
|
char message[ERROR_MESSAGE_LEN]; /* error message text */
|
||||||
} ErrorInfo;
|
} ErrorInfo;
|
||||||
|
|
||||||
typedef struct Calls
|
typedef struct Calls
|
||||||
{
|
{
|
||||||
int64 calls; /* # of times executed */
|
int64 calls; /* # of times executed */
|
||||||
int64 rows; /* total # of retrieved or affected rows */
|
int64 rows; /* total # of retrieved or affected rows */
|
||||||
double usage; /* usage factor */
|
double usage; /* usage factor */
|
||||||
} Calls;
|
} Calls;
|
||||||
|
|
||||||
|
|
||||||
typedef struct Blocks
|
typedef struct Blocks
|
||||||
{
|
{
|
||||||
int64 shared_blks_hit; /* # of shared buffer hits */
|
int64 shared_blks_hit; /* # of shared buffer hits */
|
||||||
int64 shared_blks_read; /* # of shared disk blocks read */
|
int64 shared_blks_read; /* # of shared disk blocks read */
|
||||||
int64 shared_blks_dirtied; /* # of shared disk blocks dirtied */
|
int64 shared_blks_dirtied; /* # of shared disk blocks dirtied */
|
||||||
int64 shared_blks_written; /* # of shared disk blocks written */
|
int64 shared_blks_written; /* # of shared disk blocks written */
|
||||||
int64 local_blks_hit; /* # of local buffer hits */
|
int64 local_blks_hit; /* # of local buffer hits */
|
||||||
int64 local_blks_read; /* # of local disk blocks read */
|
int64 local_blks_read; /* # of local disk blocks read */
|
||||||
int64 local_blks_dirtied; /* # of local disk blocks dirtied */
|
int64 local_blks_dirtied; /* # of local disk blocks dirtied */
|
||||||
int64 local_blks_written; /* # of local disk blocks written */
|
int64 local_blks_written; /* # of local disk blocks written */
|
||||||
int64 temp_blks_read; /* # of temp blocks read */
|
int64 temp_blks_read; /* # of temp blocks read */
|
||||||
int64 temp_blks_written; /* # of temp blocks written */
|
int64 temp_blks_written; /* # of temp blocks written */
|
||||||
double shared_blk_read_time; /* time spent reading shared blocks, in msec */
|
double shared_blk_read_time; /* time spent reading shared blocks,
|
||||||
double shared_blk_write_time; /* time spent writing shared blocks, in msec */
|
* in msec */
|
||||||
double local_blk_read_time; /* time spent reading local blocks, in msec */
|
double shared_blk_write_time; /* time spent writing shared blocks,
|
||||||
double local_blk_write_time; /* time spent writing local blocks, in msec */
|
* in msec */
|
||||||
double temp_blk_read_time; /* time spent reading temp blocks, in msec */
|
double local_blk_read_time; /* time spent reading local blocks, in
|
||||||
double temp_blk_write_time; /* time spent writing temp blocks, in msec */
|
* msec */
|
||||||
|
double local_blk_write_time; /* time spent writing local blocks, in
|
||||||
|
* msec */
|
||||||
|
double temp_blk_read_time; /* time spent reading temp blocks, in msec */
|
||||||
|
double temp_blk_write_time; /* time spent writing temp blocks, in
|
||||||
|
* msec */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables for local entry. The values to be passed to pgsm_update_entry
|
* Variables for local entry. The values to be passed to pgsm_update_entry
|
||||||
* from pgsm_store.
|
* from pgsm_store.
|
||||||
*/
|
*/
|
||||||
instr_time instr_shared_blk_read_time; /* time spent reading shared blocks */
|
instr_time instr_shared_blk_read_time; /* time spent reading shared
|
||||||
instr_time instr_shared_blk_write_time; /* time spent writing shared blocks */
|
* blocks */
|
||||||
instr_time instr_local_blk_read_time; /* time spent reading local blocks */
|
instr_time instr_shared_blk_write_time; /* time spent writing shared
|
||||||
instr_time instr_local_blk_write_time; /* time spent writing local blocks */
|
* blocks */
|
||||||
instr_time instr_temp_blk_read_time; /* time spent reading temp blocks */
|
instr_time instr_local_blk_read_time; /* time spent reading local blocks */
|
||||||
instr_time instr_temp_blk_write_time; /* time spent writing temp blocks */
|
instr_time instr_local_blk_write_time; /* time spent writing local blocks */
|
||||||
} Blocks;
|
instr_time instr_temp_blk_read_time; /* time spent reading temp blocks */
|
||||||
|
instr_time instr_temp_blk_write_time; /* time spent writing temp blocks */
|
||||||
|
} Blocks;
|
||||||
|
|
||||||
typedef struct JitInfo
|
typedef struct JitInfo
|
||||||
{
|
{
|
||||||
|
@ -326,23 +333,23 @@ typedef struct JitInfo
|
||||||
*/
|
*/
|
||||||
instr_time instr_generation_counter; /* generation counter */
|
instr_time instr_generation_counter; /* generation counter */
|
||||||
instr_time instr_inlining_counter; /* inlining counter */
|
instr_time instr_inlining_counter; /* inlining counter */
|
||||||
instr_time instr_deform_counter; /* deform counter */
|
instr_time instr_deform_counter; /* deform counter */
|
||||||
instr_time instr_optimization_counter; /* optimization counter */
|
instr_time instr_optimization_counter; /* optimization counter */
|
||||||
instr_time instr_emission_counter; /* emission counter */
|
instr_time instr_emission_counter; /* emission counter */
|
||||||
} JitInfo;
|
} JitInfo;
|
||||||
|
|
||||||
typedef struct SysInfo
|
typedef struct SysInfo
|
||||||
{
|
{
|
||||||
double utime; /* user cpu time */
|
double utime; /* user cpu time */
|
||||||
double stime; /* system cpu time */
|
double stime; /* system cpu time */
|
||||||
} SysInfo;
|
} SysInfo;
|
||||||
|
|
||||||
typedef struct Wal_Usage
|
typedef struct Wal_Usage
|
||||||
{
|
{
|
||||||
int64 wal_records; /* # of WAL records generated */
|
int64 wal_records; /* # of WAL records generated */
|
||||||
int64 wal_fpi; /* # of WAL full page images generated */
|
int64 wal_fpi; /* # of WAL full page images generated */
|
||||||
uint64 wal_bytes; /* total amount of WAL bytes generated */
|
uint64 wal_bytes; /* total amount of WAL bytes generated */
|
||||||
} Wal_Usage;
|
} Wal_Usage;
|
||||||
|
|
||||||
typedef struct Counters
|
typedef struct Counters
|
||||||
{
|
{
|
||||||
|
@ -384,7 +391,7 @@ typedef struct pgsmEntry
|
||||||
dsa_pointer query_pos; /* query location within query buffer */
|
dsa_pointer query_pos; /* query location within query buffer */
|
||||||
char *query_pointer;
|
char *query_pointer;
|
||||||
} query_text;
|
} query_text;
|
||||||
} pgsmEntry;
|
} pgsmEntry;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global shared state
|
* Global shared state
|
||||||
|
@ -407,8 +414,8 @@ typedef struct pgsmSharedState
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool pgsm_oom;
|
bool pgsm_oom;
|
||||||
TimestampTz bucket_start_time[]; /* start time of the bucket */
|
TimestampTz bucket_start_time[]; /* start time of the bucket */
|
||||||
} pgsmSharedState;
|
} pgsmSharedState;
|
||||||
|
|
||||||
typedef struct pgsmLocalState
|
typedef struct pgsmLocalState
|
||||||
{
|
{
|
||||||
|
@ -416,9 +423,9 @@ typedef struct pgsmLocalState
|
||||||
dsa_area *dsa; /* local dsa area for backend attached to the
|
dsa_area *dsa; /* local dsa area for backend attached to the
|
||||||
* dsa area created by postmaster at startup. */
|
* dsa area created by postmaster at startup. */
|
||||||
PGSM_HASH_TABLE *shared_hash;
|
PGSM_HASH_TABLE *shared_hash;
|
||||||
MemoryContext pgsm_mem_cxt;
|
MemoryContext pgsm_mem_cxt;
|
||||||
|
|
||||||
} pgsmLocalState;
|
} pgsmLocalState;
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 140000
|
#if PG_VERSION_NUM < 140000
|
||||||
/*
|
/*
|
||||||
|
@ -473,7 +480,7 @@ pgsmSharedState *pgsm_get_ss(void);
|
||||||
void hash_query_entries();
|
void hash_query_entries();
|
||||||
void hash_query_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer[]);
|
void hash_query_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer[]);
|
||||||
void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer);
|
void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer);
|
||||||
pgsmEntry *hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding);
|
pgsmEntry *hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding);
|
||||||
Size pgsm_ShmemSize(void);
|
Size pgsm_ShmemSize(void);
|
||||||
void pgsm_startup(void);
|
void pgsm_startup(void);
|
||||||
|
|
||||||
|
@ -491,7 +498,7 @@ typedef enum
|
||||||
PSGM_TRACK_NONE = 0, /* track no statements */
|
PSGM_TRACK_NONE = 0, /* track no statements */
|
||||||
PGSM_TRACK_TOP, /* only top level statements */
|
PGSM_TRACK_TOP, /* only top level statements */
|
||||||
PGSM_TRACK_ALL /* all statements, including nested ones */
|
PGSM_TRACK_ALL /* all statements, including nested ones */
|
||||||
} PGSMTrackLevel;
|
} PGSMTrackLevel;
|
||||||
static const struct config_enum_entry track_options[] =
|
static const struct config_enum_entry track_options[] =
|
||||||
{
|
{
|
||||||
{"none", PSGM_TRACK_NONE, false},
|
{"none", PSGM_TRACK_NONE, false},
|
||||||
|
@ -505,7 +512,7 @@ typedef enum
|
||||||
HISTOGRAM_START,
|
HISTOGRAM_START,
|
||||||
HISTOGRAM_END,
|
HISTOGRAM_END,
|
||||||
HISTOGRAM_COUNT
|
HISTOGRAM_COUNT
|
||||||
} HistogramTimingType;
|
} HistogramTimingType;
|
||||||
|
|
||||||
extern int pgsm_max;
|
extern int pgsm_max;
|
||||||
extern int pgsm_query_max_len;
|
extern int pgsm_query_max_len;
|
||||||
|
@ -531,8 +538,8 @@ extern int pgsm_track;
|
||||||
#define HOOK_STATS_SIZE 0
|
#define HOOK_STATS_SIZE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found);
|
void *pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found);
|
||||||
void *pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found);
|
void *pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *found);
|
||||||
void pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock);
|
void pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock);
|
||||||
void *pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat);
|
void *pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat);
|
||||||
void pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat);
|
void pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat);
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
AGG_KEY
|
||||||
|
Blocks
|
||||||
|
CallTime
|
||||||
|
Calls
|
||||||
|
Counters
|
||||||
|
ErrorInfo
|
||||||
|
HistogramTimingType
|
||||||
|
JitInfo
|
||||||
|
JumbleState
|
||||||
|
LocationLen
|
||||||
|
PGSMTrackLevel
|
||||||
|
PlanInfo
|
||||||
|
QueryInfo
|
||||||
|
SysInfo
|
||||||
|
WalUsage
|
||||||
|
Wal_Usage
|
||||||
|
pgsmEntry
|
||||||
|
pgsmHashKey
|
||||||
|
pgsmLocalState
|
||||||
|
pgsmSharedState
|
||||||
|
pgsmStoreKind
|
||||||
|
pgsmVersion
|
Loading…
Reference in New Issue