parent
3e0b194764
commit
6a70322858
17
hash_query.c
17
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)
|
||||||
|
@ -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,8 +238,7 @@ pgsm_attach_shmem(void)
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryContext
|
MemoryContext GetPgsmMemoryContext(void)
|
||||||
GetPgsmMemoryContext(void)
|
|
||||||
{
|
{
|
||||||
return pgsmStateLocal.pgsm_mem_cxt;
|
return pgsmStateLocal.pgsm_mem_cxt;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +287,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;
|
||||||
|
@ -392,7 +391,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;
|
||||||
|
@ -405,7 +404,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);
|
||||||
|
|
|
@ -202,9 +202,9 @@ char *unpack_sql_state(int sql_state);
|
||||||
!IsA(n, DeallocateStmt))
|
!IsA(n, DeallocateStmt))
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -218,13 +218,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,
|
||||||
|
@ -233,7 +233,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,
|
||||||
|
@ -260,7 +260,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
|
||||||
|
@ -1336,13 +1336,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,
|
||||||
|
@ -1606,7 +1606,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());
|
||||||
|
@ -1617,7 +1617,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;
|
||||||
|
@ -1675,7 +1675,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;
|
||||||
|
@ -1754,7 +1754,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;
|
||||||
|
@ -1999,7 +1999,7 @@ IsBucketValid(uint64 bucketid)
|
||||||
|
|
||||||
TimestampDifference(pgsm->bucket_start_time[bucketid], current_tz, &secs, µsecs);
|
TimestampDifference(pgsm->bucket_start_time[bucketid], current_tz, &secs, µsecs);
|
||||||
|
|
||||||
if (secs > ((int64) pgsm_bucket_time * pgsm_max_buckets))
|
if (secs > ((int64)pgsm_bucket_time * pgsm_max_buckets))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2426,7 +2426,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;
|
||||||
|
|
|
@ -465,7 +465,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);
|
||||||
|
|
||||||
|
@ -522,8 +522,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);
|
||||||
|
|
Loading…
Reference in New Issue