Fixing code indentation with pgindent
parent
1883b05fc7
commit
faa938b8f1
2
guc.c
2
guc.c
|
@ -297,6 +297,6 @@ static bool
|
||||||
check_overflow_targer(int *newval, void **extra, GucSource source)
|
check_overflow_targer(int *newval, void **extra, GucSource source)
|
||||||
{
|
{
|
||||||
if (source != PGC_S_DEFAULT)
|
if (source != PGC_S_DEFAULT)
|
||||||
elog(WARNING,"pg_stat_monitor.pgsm_overflow_target is deprecated, use pgsm_enable_overflow");
|
elog(WARNING, "pg_stat_monitor.pgsm_overflow_target is deprecated, use pgsm_enable_overflow");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
112
hash_query.c
112
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);
|
||||||
|
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
/* parameter for the shared hash */
|
/* parameter for the shared hash */
|
||||||
|
@ -40,28 +40,26 @@ static dshash_parameters dsh_params = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Size
|
static Size
|
||||||
pgsm_query_area_size(void)
|
pgsm_query_area_size(void) {
|
||||||
{
|
|
||||||
Size sz = MAX_QUERY_BUF;
|
Size sz = MAX_QUERY_BUF;
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
/* Dynamic hash also lives DSA area */
|
/* Dynamic hash also lives DSA area */
|
||||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||||
#endif
|
#endif
|
||||||
return MAXALIGN(sz);
|
return MAXALIGN(sz);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Total shared memory area required by pgsm
|
* Total shared memory area required by pgsm
|
||||||
*/
|
*/
|
||||||
Size
|
Size
|
||||||
pgsm_ShmemSize(void)
|
pgsm_ShmemSize(void) {
|
||||||
{
|
|
||||||
Size sz = MAXALIGN(sizeof(pgsmSharedState));
|
Size sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||||
sz = add_size(sz, MAX_QUERY_BUF);
|
sz = add_size(sz, MAX_QUERY_BUF);
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||||
#else
|
#else
|
||||||
sz = add_size(sz, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgsmEntry)));
|
sz = add_size(sz, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgsmEntry)));
|
||||||
#endif
|
#endif
|
||||||
return MAXALIGN(sz);
|
return MAXALIGN(sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,15 +70,14 @@ pgsm_ShmemSize(void)
|
||||||
* get allocated as a single shared memory chunk.
|
* get allocated as a single shared memory chunk.
|
||||||
*/
|
*/
|
||||||
static Size
|
static Size
|
||||||
pgsm_get_shared_area_size(void)
|
pgsm_get_shared_area_size(void) {
|
||||||
{
|
|
||||||
Size sz;
|
Size sz;
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
sz = pgsm_ShmemSize();
|
sz = pgsm_ShmemSize();
|
||||||
#else
|
#else
|
||||||
sz = MAXALIGN(sizeof(pgsmSharedState));
|
sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||||
sz = add_size(sz, pgsm_query_area_size());
|
sz = add_size(sz, pgsm_query_area_size());
|
||||||
#endif
|
#endif
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +97,7 @@ pgsm_startup(void)
|
||||||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||||
|
|
||||||
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
||||||
if (!found)
|
if (!found) {
|
||||||
{
|
|
||||||
/* First time through ... */
|
/* First time through ... */
|
||||||
dsa_area *dsa;
|
dsa_area *dsa;
|
||||||
char *p = (char *) pgsm;
|
char *p = (char *) pgsm;
|
||||||
|
@ -119,11 +115,12 @@ pgsm_startup(void)
|
||||||
dsa_pin(dsa);
|
dsa_pin(dsa);
|
||||||
dsa_set_size_limit(dsa, pgsm_query_area_size());
|
dsa_set_size_limit(dsa, pgsm_query_area_size());
|
||||||
|
|
||||||
pgsm->hash_handle = pgsm_create_bucket_hash(pgsm,dsa);
|
pgsm->hash_handle = pgsm_create_bucket_hash(pgsm, dsa);
|
||||||
|
|
||||||
/* If overflow is enabled, set the DSA size to unlimited,
|
/*
|
||||||
* and allow the DSA to grow beyond the shared memory space
|
* If overflow is enabled, set the DSA size to unlimited, and allow
|
||||||
* into the swap area*/
|
* the DSA to grow beyond the shared memory space into the swap area
|
||||||
|
*/
|
||||||
if (pgsm_enable_overflow)
|
if (pgsm_enable_overflow)
|
||||||
dsa_set_size_limit(dsa, -1);
|
dsa_set_size_limit(dsa, -1);
|
||||||
|
|
||||||
|
@ -149,7 +146,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);
|
||||||
|
@ -164,8 +161,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;
|
||||||
|
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
|
@ -202,15 +198,16 @@ pgsm_attach_shmem(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want the dsa to remain valid throughout the lifecycle of this process.
|
* We want the dsa to remain valid throughout the lifecycle of this
|
||||||
* so switch to TopMemoryContext before attaching
|
* process. so switch to TopMemoryContext before attaching
|
||||||
*/
|
*/
|
||||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||||
|
|
||||||
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
||||||
NULL);
|
NULL);
|
||||||
/* pin the attached area to keep the area attached until end of
|
/*
|
||||||
* session or explicit detach.
|
* pin the attached area to keep the area attached until end of session or
|
||||||
|
* explicit detach.
|
||||||
*/
|
*/
|
||||||
dsa_pin_mapping(pgsmStateLocal.dsa);
|
dsa_pin_mapping(pgsmStateLocal.dsa);
|
||||||
|
|
||||||
|
@ -225,14 +222,14 @@ pgsm_attach_shmem(void)
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
dsa_area*
|
dsa_area *
|
||||||
get_dsa_area_for_query_text(void)
|
get_dsa_area_for_query_text(void)
|
||||||
{
|
{
|
||||||
pgsm_attach_shmem();
|
pgsm_attach_shmem();
|
||||||
return pgsmStateLocal.dsa;
|
return pgsmStateLocal.dsa;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGSM_HASH_TABLE*
|
PGSM_HASH_TABLE *
|
||||||
get_pgsmHash(void)
|
get_pgsmHash(void)
|
||||||
{
|
{
|
||||||
pgsm_attach_shmem();
|
pgsm_attach_shmem();
|
||||||
|
@ -257,7 +254,7 @@ void
|
||||||
pgsm_shmem_shutdown(int code, Datum arg)
|
pgsm_shmem_shutdown(int code, Datum arg)
|
||||||
{
|
{
|
||||||
/* Don't try to dump during a crash. */
|
/* Don't try to dump during a crash. */
|
||||||
elog(LOG,"[pg_stat_monitor] pgsm_shmem_shutdown: Shutdown initiated.");
|
elog(LOG, "[pg_stat_monitor] pgsm_shmem_shutdown: Shutdown initiated.");
|
||||||
|
|
||||||
if (code)
|
if (code)
|
||||||
return;
|
return;
|
||||||
|
@ -269,16 +266,15 @@ 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;
|
||||||
/* Find or create an entry with desired hash code */
|
/* Find or create an entry with desired hash code */
|
||||||
entry = (pgsmEntry*) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
entry = (pgsmEntry *) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
elog(DEBUG1, "[pg_stat_monitor] hash_entry_alloc: OUT OF MEMORY.");
|
elog(DEBUG1, "[pg_stat_monitor] hash_entry_alloc: OUT OF MEMORY.");
|
||||||
else if (!found)
|
else if (!found) {
|
||||||
{
|
|
||||||
pgsm->bucket_entry[pg_atomic_read_u64(&pgsm->current_wbucket)]++;
|
pgsm->bucket_entry[pg_atomic_read_u64(&pgsm->current_wbucket)]++;
|
||||||
/* New entry, initialize it */
|
/* New entry, initialize it */
|
||||||
/* reset the statistics */
|
/* reset the statistics */
|
||||||
|
@ -292,10 +288,10 @@ hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
||||||
/* ... and don't forget the query text metadata */
|
/* ... and don't forget the query text metadata */
|
||||||
entry->encoding = encoding;
|
entry->encoding = encoding;
|
||||||
}
|
}
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
if(entry)
|
if (entry)
|
||||||
dshash_release_lock(pgsmStateLocal.shared_hash, entry);
|
dshash_release_lock(pgsmStateLocal.shared_hash, entry);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -325,8 +321,7 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
|
||||||
/* Iterate over the hash table. */
|
/* Iterate over the hash table. */
|
||||||
pgsm_hash_seq_init(&hstat, pgsmStateLocal.shared_hash, true);
|
pgsm_hash_seq_init(&hstat, pgsmStateLocal.shared_hash, true);
|
||||||
|
|
||||||
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL)
|
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL) {
|
||||||
{
|
|
||||||
dsa_pointer pdsa;
|
dsa_pointer pdsa;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -334,8 +329,7 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
|
||||||
* in new_bucket_id if it has finished already.
|
* in new_bucket_id if it has finished already.
|
||||||
*/
|
*/
|
||||||
if (new_bucket_id < 0 ||
|
if (new_bucket_id < 0 ||
|
||||||
(entry->key.bucket_id == new_bucket_id ))
|
(entry->key.bucket_id == new_bucket_id)) {
|
||||||
{
|
|
||||||
dsa_pointer parent_qdsa = entry->counters.info.parent_query;
|
dsa_pointer parent_qdsa = entry->counters.info.parent_query;
|
||||||
pdsa = entry->query_text.query_pos;
|
pdsa = entry->query_text.query_pos;
|
||||||
|
|
||||||
|
@ -371,29 +365,29 @@ 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;
|
||||||
entry = dshash_find_or_insert(shared_hash, key, found);
|
entry = dshash_find_or_insert(shared_hash, key, found);
|
||||||
return entry;
|
return entry;
|
||||||
#else
|
#else
|
||||||
return hash_search(shared_hash, key, HASH_ENTER_NULL, found);
|
return hash_search(shared_hash, key, HASH_ENTER_NULL, found);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
#else
|
#else
|
||||||
return hash_search(shared_hash, key, HASH_FIND, found);
|
return hash_search(shared_hash, key, HASH_FIND, found);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, bool lock)
|
pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
dshash_seq_init(hstat, shared_hash, lock);
|
dshash_seq_init(hstat, shared_hash, lock);
|
||||||
|
@ -402,8 +396,8 @@ pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, bo
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void *
|
||||||
pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS *hstat)
|
pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
return dshash_seq_next(hstat);
|
return dshash_seq_next(hstat);
|
||||||
|
@ -413,7 +407,7 @@ pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS *hstat)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS *hstat)
|
pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
dshash_seq_term(hstat);
|
dshash_seq_term(hstat);
|
||||||
|
@ -421,11 +415,11 @@ pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS *hstat)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, void *key)
|
pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, void *key)
|
||||||
{
|
{
|
||||||
#if USE_DYNAMIC_HASH
|
#if USE_DYNAMIC_HASH
|
||||||
dshash_delete_current(hstat);
|
dshash_delete_current(hstat);
|
||||||
#else
|
#else
|
||||||
hash_search(shared_hash, key, HASH_REMOVE, NULL);
|
hash_search(shared_hash, key, HASH_REMOVE, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -66,13 +66,16 @@
|
||||||
|
|
||||||
/* XXX: Should USAGE_EXEC reflect execution time and/or buffer usage? */
|
/* XXX: Should USAGE_EXEC reflect execution time and/or buffer usage? */
|
||||||
#define USAGE_EXEC(duration) (1.0)
|
#define USAGE_EXEC(duration) (1.0)
|
||||||
#define USAGE_INIT (1.0) /* including initial planning */
|
#define USAGE_INIT (1.0) /* including initial
|
||||||
#define ASSUMED_LENGTH_INIT 1024 /* initial assumed mean query length */
|
* planning */
|
||||||
|
#define ASSUMED_LENGTH_INIT 1024 /* initial assumed mean query
|
||||||
|
* length */
|
||||||
#define USAGE_DECREASE_FACTOR (0.99) /* decreased every entry_dealloc */
|
#define USAGE_DECREASE_FACTOR (0.99) /* decreased every entry_dealloc */
|
||||||
#define STICKY_DECREASE_FACTOR (0.50) /* factor for sticky entries */
|
#define STICKY_DECREASE_FACTOR (0.50) /* factor for sticky entries */
|
||||||
#define USAGE_DEALLOC_PERCENT 5 /* free this % of entries at once */
|
#define USAGE_DEALLOC_PERCENT 5 /* free this % of entries at once */
|
||||||
|
|
||||||
#define JUMBLE_SIZE 1024 /* query serialization buffer size */
|
#define JUMBLE_SIZE 1024 /* query serialization
|
||||||
|
* buffer size */
|
||||||
|
|
||||||
#define HISTOGRAM_MAX_TIME 50000000
|
#define HISTOGRAM_MAX_TIME 50000000
|
||||||
#define MAX_RESPONSE_BUCKET 50
|
#define MAX_RESPONSE_BUCKET 50
|
||||||
|
@ -82,7 +85,10 @@
|
||||||
#define ERROR_MESSAGE_LEN 100
|
#define ERROR_MESSAGE_LEN 100
|
||||||
#define REL_TYPENAME_LEN 64
|
#define REL_TYPENAME_LEN 64
|
||||||
#define REL_LST 10
|
#define REL_LST 10
|
||||||
#define REL_LEN 132 /* REL_TYPENAME_LEN * 2 (relname + schema) + 1 (for view indication) + 1 and dot and string terminator */
|
#define REL_LEN 132 /* REL_TYPENAME_LEN * 2
|
||||||
|
* (relname + schema) + 1 (for
|
||||||
|
* view indication) + 1 and
|
||||||
|
* dot and string terminator */
|
||||||
#define CMD_LST 10
|
#define CMD_LST 10
|
||||||
#define CMD_LEN 20
|
#define CMD_LEN 20
|
||||||
#define APPLICATIONNAME_LEN NAMEDATALEN
|
#define APPLICATIONNAME_LEN NAMEDATALEN
|
||||||
|
@ -158,19 +164,18 @@ extern volatile bool __pgsm_do_not_capture_error;
|
||||||
* the classic shared memory hash table.
|
* the classic shared memory hash table.
|
||||||
*/
|
*/
|
||||||
#ifdef USE_DYNAMIC_HASH
|
#ifdef USE_DYNAMIC_HASH
|
||||||
#define PGSM_HASH_TABLE dshash_table
|
#define PGSM_HASH_TABLE dshash_table
|
||||||
#define PGSM_HASH_TABLE_HANDLE dshash_table_handle
|
#define PGSM_HASH_TABLE_HANDLE dshash_table_handle
|
||||||
#define PGSM_HASH_SEQ_STATUS dshash_seq_status
|
#define PGSM_HASH_SEQ_STATUS dshash_seq_status
|
||||||
#else
|
#else
|
||||||
#define PGSM_HASH_TABLE HTAB
|
#define PGSM_HASH_TABLE HTAB
|
||||||
#define PGSM_HASH_TABLE_HANDLE HTAB*
|
#define PGSM_HASH_TABLE_HANDLE HTAB*
|
||||||
#define PGSM_HASH_SEQ_STATUS HASH_SEQ_STATUS
|
#define PGSM_HASH_SEQ_STATUS HASH_SEQ_STATUS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 130000
|
#if PG_VERSION_NUM < 130000
|
||||||
typedef struct WalUsage
|
typedef struct WalUsage {
|
||||||
{
|
|
||||||
long wal_records; /* # of WAL records produced */
|
long wal_records; /* # of WAL records produced */
|
||||||
long wal_fpi; /* # of WAL full page images produced */
|
long wal_fpi; /* # of WAL full page images produced */
|
||||||
uint64 wal_bytes; /* size of WAL records produced */
|
uint64 wal_bytes; /* size of WAL records produced */
|
||||||
|
@ -178,8 +183,7 @@ typedef struct WalUsage
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef enum pgsmStoreKind
|
typedef enum pgsmStoreKind {
|
||||||
{
|
|
||||||
PGSM_INVALID = -1,
|
PGSM_INVALID = -1,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -202,8 +206,7 @@ typedef enum pgsmStoreKind
|
||||||
/*
|
/*
|
||||||
* Type of aggregate keys
|
* Type of aggregate keys
|
||||||
*/
|
*/
|
||||||
typedef enum AGG_KEY
|
typedef enum AGG_KEY {
|
||||||
{
|
|
||||||
AGG_KEY_DATABASE = 0,
|
AGG_KEY_DATABASE = 0,
|
||||||
AGG_KEY_USER,
|
AGG_KEY_USER,
|
||||||
AGG_KEY_HOST
|
AGG_KEY_HOST
|
||||||
|
@ -212,8 +215,7 @@ typedef enum AGG_KEY
|
||||||
#define MAX_QUERY_LEN 1024
|
#define MAX_QUERY_LEN 1024
|
||||||
|
|
||||||
/* shared memory storage for the query */
|
/* shared memory storage for the query */
|
||||||
typedef struct CallTime
|
typedef struct CallTime {
|
||||||
{
|
|
||||||
double total_time; /* total execution time, in msec */
|
double total_time; /* total execution time, in msec */
|
||||||
double min_time; /* minimum execution time in msec */
|
double min_time; /* minimum execution time in msec */
|
||||||
double max_time; /* maximum execution time in msec */
|
double max_time; /* maximum execution time in msec */
|
||||||
|
@ -222,15 +224,13 @@ typedef struct CallTime
|
||||||
} CallTime;
|
} CallTime;
|
||||||
|
|
||||||
|
|
||||||
typedef struct PlanInfo
|
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 {
|
||||||
{
|
|
||||||
uint64 bucket_id; /* bucket number */
|
uint64 bucket_id; /* bucket number */
|
||||||
uint64 queryid; /* query identifier */
|
uint64 queryid; /* query identifier */
|
||||||
uint64 planid; /* plan identifier */
|
uint64 planid; /* plan identifier */
|
||||||
|
@ -241,8 +241,7 @@ typedef struct pgsmHashKey
|
||||||
bool toplevel; /* query executed at top level */
|
bool toplevel; /* query executed at top level */
|
||||||
} pgsmHashKey;
|
} pgsmHashKey;
|
||||||
|
|
||||||
typedef struct QueryInfo
|
typedef struct QueryInfo {
|
||||||
{
|
|
||||||
uint64 parentid; /* parent queryid of current query */
|
uint64 parentid; /* parent queryid of current query */
|
||||||
dsa_pointer parent_query;
|
dsa_pointer parent_query;
|
||||||
int64 type; /* type of query, options are query, info,
|
int64 type; /* type of query, options are query, info,
|
||||||
|
@ -256,23 +255,20 @@ typedef struct QueryInfo
|
||||||
* SELECT/UPDATE/DELETE/INSERT */
|
* SELECT/UPDATE/DELETE/INSERT */
|
||||||
} QueryInfo;
|
} QueryInfo;
|
||||||
|
|
||||||
typedef struct ErrorInfo
|
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 */
|
||||||
|
@ -286,7 +282,8 @@ typedef struct Blocks
|
||||||
double blk_read_time; /* time spent reading, in msec */
|
double blk_read_time; /* time spent reading, in msec */
|
||||||
double blk_write_time; /* time spent writing, in msec */
|
double blk_write_time; /* time spent writing, in msec */
|
||||||
|
|
||||||
double temp_blk_read_time; /* time spent reading temp 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
|
double temp_blk_write_time; /* time spent writing temp blocks, in
|
||||||
* msec */
|
* msec */
|
||||||
|
|
||||||
|
@ -296,22 +293,23 @@ typedef struct Blocks
|
||||||
*/
|
*/
|
||||||
instr_time instr_blk_read_time; /* time spent reading blocks */
|
instr_time instr_blk_read_time; /* time spent reading blocks */
|
||||||
instr_time instr_blk_write_time; /* time spent writing blocks */
|
instr_time instr_blk_write_time; /* time spent writing blocks */
|
||||||
instr_time instr_temp_blk_read_time; /* time spent reading temp blocks */
|
instr_time instr_temp_blk_read_time; /* time spent reading temp
|
||||||
instr_time instr_temp_blk_write_time; /* time spent writing temp blocks */
|
* blocks */
|
||||||
|
instr_time instr_temp_blk_write_time; /* time spent writing temp
|
||||||
|
* blocks */
|
||||||
} Blocks;
|
} Blocks;
|
||||||
|
|
||||||
typedef struct JitInfo
|
typedef struct JitInfo {
|
||||||
{
|
|
||||||
int64 jit_functions; /* total number of JIT functions emitted */
|
int64 jit_functions; /* total number of JIT functions emitted */
|
||||||
double jit_generation_time; /* total time to generate jit code */
|
double jit_generation_time; /* total time to generate jit code */
|
||||||
int64 jit_inlining_count; /* number of times inlining time has been
|
int64 jit_inlining_count; /* number of times inlining time has
|
||||||
* > 0 */
|
* been > 0 */
|
||||||
double jit_inlining_time; /* total time to inline jit code */
|
double jit_inlining_time; /* total time to inline jit code */
|
||||||
int64 jit_optimization_count; /* number of times optimization time
|
int64 jit_optimization_count; /* number of times optimization time
|
||||||
* has been > 0 */
|
* has been > 0 */
|
||||||
double jit_optimization_time; /* total time to optimize jit code */
|
double jit_optimization_time; /* total time to optimize jit code */
|
||||||
int64 jit_emission_count; /* number of times emission time has been
|
int64 jit_emission_count; /* number of times emission time has
|
||||||
* > 0 */
|
* been > 0 */
|
||||||
double jit_emission_time; /* total time to emit jit code */
|
double jit_emission_time; /* total time to emit jit code */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -324,21 +322,18 @@ typedef struct JitInfo
|
||||||
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 {
|
||||||
{
|
|
||||||
Calls calls;
|
Calls calls;
|
||||||
QueryInfo info;
|
QueryInfo info;
|
||||||
CallTime time;
|
CallTime time;
|
||||||
|
@ -361,8 +356,7 @@ typedef struct Counters
|
||||||
/*
|
/*
|
||||||
* Statistics per statement
|
* Statistics per statement
|
||||||
*/
|
*/
|
||||||
typedef struct pgsmEntry
|
typedef struct pgsmEntry {
|
||||||
{
|
|
||||||
pgsmHashKey key; /* hash key of entry - MUST BE FIRST */
|
pgsmHashKey key; /* hash key of entry - MUST BE FIRST */
|
||||||
uint64 pgsm_query_id; /* pgsm generate normalized query hash */
|
uint64 pgsm_query_id; /* pgsm generate normalized query hash */
|
||||||
char datname[NAMEDATALEN]; /* database name */
|
char datname[NAMEDATALEN]; /* database name */
|
||||||
|
@ -370,18 +364,16 @@ typedef struct pgsmEntry
|
||||||
Counters counters; /* the statistics for this query */
|
Counters counters; /* the statistics for this query */
|
||||||
int encoding; /* query text encoding */
|
int encoding; /* query text encoding */
|
||||||
slock_t mutex; /* protects the counters only */
|
slock_t mutex; /* protects the counters only */
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
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
|
||||||
*/
|
*/
|
||||||
typedef struct pgsmSharedState
|
typedef struct pgsmSharedState {
|
||||||
{
|
|
||||||
LWLock *lock; /* protects hashtable search/modification */
|
LWLock *lock; /* protects hashtable search/modification */
|
||||||
slock_t mutex; /* protects following fields only: */
|
slock_t mutex; /* protects following fields only: */
|
||||||
pg_atomic_uint64 current_wbucket;
|
pg_atomic_uint64 current_wbucket;
|
||||||
|
@ -393,34 +385,33 @@ typedef struct pgsmSharedState
|
||||||
* dshash also lives in this memory when
|
* dshash also lives in this memory when
|
||||||
* USE_DYNAMIC_HASH is enabled */
|
* USE_DYNAMIC_HASH is enabled */
|
||||||
PGSM_HASH_TABLE_HANDLE hash_handle;
|
PGSM_HASH_TABLE_HANDLE hash_handle;
|
||||||
/* hash table handle. can be either
|
/*
|
||||||
* classic shared memory hash or dshash
|
* hash table handle. can be either classic shared memory hash or dshash
|
||||||
* (if we are using USE_DYNAMIC_HASH)
|
* (if we are using USE_DYNAMIC_HASH)
|
||||||
*/
|
*/
|
||||||
MemoryContext pgsm_mem_cxt;
|
MemoryContext pgsm_mem_cxt;
|
||||||
/* context to store stats in local
|
/*
|
||||||
* memory until they are pushed to shared hash
|
* context to store stats in local memory until they are pushed to shared
|
||||||
|
* hash
|
||||||
*/
|
*/
|
||||||
int resp_calls[MAX_RESPONSE_BUCKET + 2]; /* execution time's in
|
int resp_calls[MAX_RESPONSE_BUCKET + 2]; /* execution time's in
|
||||||
* msec; including 2 outlier buckets */
|
* msec; including 2
|
||||||
|
* outlier buckets */
|
||||||
bool pgsm_oom;
|
bool pgsm_oom;
|
||||||
} pgsmSharedState;
|
} pgsmSharedState;
|
||||||
|
|
||||||
typedef struct pgsmLocalState
|
typedef struct pgsmLocalState {
|
||||||
{
|
|
||||||
pgsmSharedState *shared_pgsmState;
|
pgsmSharedState *shared_pgsmState;
|
||||||
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;
|
||||||
}pgsmLocalState;
|
} pgsmLocalState;
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 140000
|
#if PG_VERSION_NUM < 140000
|
||||||
/*
|
/*
|
||||||
* Struct for tracking locations/lengths of constants during normalization
|
* Struct for tracking locations/lengths of constants during normalization
|
||||||
*/
|
*/
|
||||||
typedef struct LocationLen
|
typedef struct LocationLen {
|
||||||
{
|
|
||||||
int location; /* start offset in query text */
|
int location; /* start offset in query text */
|
||||||
int length; /* length in bytes, or -1 to ignore */
|
int length; /* length in bytes, or -1 to ignore */
|
||||||
} LocationLen;
|
} LocationLen;
|
||||||
|
@ -429,8 +420,7 @@ typedef struct LocationLen
|
||||||
* Working state for computing a query jumble and producing a normalized
|
* Working state for computing a query jumble and producing a normalized
|
||||||
* query string
|
* query string
|
||||||
*/
|
*/
|
||||||
typedef struct JumbleState
|
typedef struct JumbleState {
|
||||||
{
|
|
||||||
/* Jumble of current query tree */
|
/* Jumble of current query tree */
|
||||||
unsigned char *jumble;
|
unsigned char *jumble;
|
||||||
|
|
||||||
|
@ -468,7 +458,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);
|
||||||
|
|
||||||
|
@ -480,8 +470,7 @@ void init_guc(void);
|
||||||
|
|
||||||
/* GUC variables*/
|
/* GUC variables*/
|
||||||
/*---- GUC variables ----*/
|
/*---- GUC variables ----*/
|
||||||
typedef enum
|
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 */
|
||||||
|
@ -494,8 +483,7 @@ static const struct config_enum_entry track_options[] =
|
||||||
{NULL, 0, false}
|
{NULL, 0, false}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
HISTOGRAM_START,
|
HISTOGRAM_START,
|
||||||
HISTOGRAM_END,
|
HISTOGRAM_END,
|
||||||
HISTOGRAM_COUNT
|
HISTOGRAM_COUNT
|
||||||
|
@ -524,9 +512,9 @@ 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);
|
||||||
void pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, void *key);
|
void pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, void *key);
|
||||||
|
|
Loading…
Reference in New Issue