Fixing code indentation with pgindent
parent
1883b05fc7
commit
faa938b8f1
40
hash_query.c
40
hash_query.c
|
@ -40,8 +40,7 @@ static dshash_parameters dsh_params = {
|
|||
*/
|
||||
|
||||
static Size
|
||||
pgsm_query_area_size(void)
|
||||
{
|
||||
pgsm_query_area_size(void) {
|
||||
Size sz = MAX_QUERY_BUF;
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* Dynamic hash also lives DSA area */
|
||||
|
@ -53,8 +52,7 @@ pgsm_query_area_size(void)
|
|||
* Total shared memory area required by pgsm
|
||||
*/
|
||||
Size
|
||||
pgsm_ShmemSize(void)
|
||||
{
|
||||
pgsm_ShmemSize(void) {
|
||||
Size sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||
sz = add_size(sz, MAX_QUERY_BUF);
|
||||
#if USE_DYNAMIC_HASH
|
||||
|
@ -72,8 +70,7 @@ pgsm_ShmemSize(void)
|
|||
* get allocated as a single shared memory chunk.
|
||||
*/
|
||||
static Size
|
||||
pgsm_get_shared_area_size(void)
|
||||
{
|
||||
pgsm_get_shared_area_size(void) {
|
||||
Size sz;
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = pgsm_ShmemSize();
|
||||
|
@ -100,8 +97,7 @@ pgsm_startup(void)
|
|||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||
|
||||
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
||||
if (!found)
|
||||
{
|
||||
if (!found) {
|
||||
/* First time through ... */
|
||||
dsa_area *dsa;
|
||||
char *p = (char *) pgsm;
|
||||
|
@ -121,9 +117,10 @@ pgsm_startup(void)
|
|||
|
||||
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
|
||||
* into the swap area*/
|
||||
/*
|
||||
* If overflow is enabled, set the DSA size to unlimited, and allow
|
||||
* the DSA to grow beyond the shared memory space into the swap area
|
||||
*/
|
||||
if (pgsm_enable_overflow)
|
||||
dsa_set_size_limit(dsa, -1);
|
||||
|
||||
|
@ -164,8 +161,7 @@ InitializeSharedState(pgsmSharedState *pgsm)
|
|||
* Create the classic or dshahs hash table for storing the query statistics.
|
||||
*/
|
||||
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;
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
|
@ -202,15 +198,16 @@ pgsm_attach_shmem(void)
|
|||
return;
|
||||
|
||||
/*
|
||||
* We want the dsa to remain valid throughout the lifecycle of this process.
|
||||
* so switch to TopMemoryContext before attaching
|
||||
* We want the dsa to remain valid throughout the lifecycle of this
|
||||
* process. so switch to TopMemoryContext before attaching
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
||||
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);
|
||||
|
||||
|
@ -277,8 +274,7 @@ hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
|||
entry = (pgsmEntry *) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
||||
if (entry == NULL)
|
||||
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)]++;
|
||||
/* New entry, initialize it */
|
||||
/* reset the statistics */
|
||||
|
@ -325,8 +321,7 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
|
|||
/* Iterate over the hash table. */
|
||||
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;
|
||||
|
||||
/*
|
||||
|
@ -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.
|
||||
*/
|
||||
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;
|
||||
pdsa = entry->query_text.query_pos;
|
||||
|
||||
|
|
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? */
|
||||
#define USAGE_EXEC(duration) (1.0)
|
||||
#define USAGE_INIT (1.0) /* including initial planning */
|
||||
#define ASSUMED_LENGTH_INIT 1024 /* initial assumed mean query length */
|
||||
#define USAGE_INIT (1.0) /* including initial
|
||||
* planning */
|
||||
#define ASSUMED_LENGTH_INIT 1024 /* initial assumed mean query
|
||||
* length */
|
||||
#define USAGE_DECREASE_FACTOR (0.99) /* decreased every entry_dealloc */
|
||||
#define STICKY_DECREASE_FACTOR (0.50) /* factor for sticky entries */
|
||||
#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 MAX_RESPONSE_BUCKET 50
|
||||
|
@ -82,7 +85,10 @@
|
|||
#define ERROR_MESSAGE_LEN 100
|
||||
#define REL_TYPENAME_LEN 64
|
||||
#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_LEN 20
|
||||
#define APPLICATIONNAME_LEN NAMEDATALEN
|
||||
|
@ -169,8 +175,7 @@ extern volatile bool __pgsm_do_not_capture_error;
|
|||
|
||||
|
||||
#if PG_VERSION_NUM < 130000
|
||||
typedef struct WalUsage
|
||||
{
|
||||
typedef struct WalUsage {
|
||||
long wal_records; /* # of WAL records produced */
|
||||
long wal_fpi; /* # of WAL full page images produced */
|
||||
uint64 wal_bytes; /* size of WAL records produced */
|
||||
|
@ -178,8 +183,7 @@ typedef struct WalUsage
|
|||
#endif
|
||||
|
||||
|
||||
typedef enum pgsmStoreKind
|
||||
{
|
||||
typedef enum pgsmStoreKind {
|
||||
PGSM_INVALID = -1,
|
||||
|
||||
/*
|
||||
|
@ -202,8 +206,7 @@ typedef enum pgsmStoreKind
|
|||
/*
|
||||
* Type of aggregate keys
|
||||
*/
|
||||
typedef enum AGG_KEY
|
||||
{
|
||||
typedef enum AGG_KEY {
|
||||
AGG_KEY_DATABASE = 0,
|
||||
AGG_KEY_USER,
|
||||
AGG_KEY_HOST
|
||||
|
@ -212,8 +215,7 @@ typedef enum AGG_KEY
|
|||
#define MAX_QUERY_LEN 1024
|
||||
|
||||
/* shared memory storage for the query */
|
||||
typedef struct CallTime
|
||||
{
|
||||
typedef struct CallTime {
|
||||
double total_time; /* total execution time, in msec */
|
||||
double min_time; /* minimum execution time in msec */
|
||||
double max_time; /* maximum execution time in msec */
|
||||
|
@ -222,15 +224,13 @@ typedef struct CallTime
|
|||
} CallTime;
|
||||
|
||||
|
||||
typedef struct PlanInfo
|
||||
{
|
||||
typedef struct PlanInfo {
|
||||
uint64 planid; /* plan identifier */
|
||||
char plan_text[PLAN_TEXT_LEN]; /* plan text */
|
||||
size_t plan_len; /* strlen(plan_text) */
|
||||
} PlanInfo;
|
||||
|
||||
typedef struct pgsmHashKey
|
||||
{
|
||||
typedef struct pgsmHashKey {
|
||||
uint64 bucket_id; /* bucket number */
|
||||
uint64 queryid; /* query identifier */
|
||||
uint64 planid; /* plan identifier */
|
||||
|
@ -241,8 +241,7 @@ typedef struct pgsmHashKey
|
|||
bool toplevel; /* query executed at top level */
|
||||
} pgsmHashKey;
|
||||
|
||||
typedef struct QueryInfo
|
||||
{
|
||||
typedef struct QueryInfo {
|
||||
uint64 parentid; /* parent queryid of current query */
|
||||
dsa_pointer parent_query;
|
||||
int64 type; /* type of query, options are query, info,
|
||||
|
@ -256,23 +255,20 @@ typedef struct QueryInfo
|
|||
* SELECT/UPDATE/DELETE/INSERT */
|
||||
} QueryInfo;
|
||||
|
||||
typedef struct ErrorInfo
|
||||
{
|
||||
typedef struct ErrorInfo {
|
||||
int64 elevel; /* error elevel */
|
||||
char sqlcode[SQLCODE_LEN]; /* error sqlcode */
|
||||
char message[ERROR_MESSAGE_LEN]; /* error message text */
|
||||
} ErrorInfo;
|
||||
|
||||
typedef struct Calls
|
||||
{
|
||||
typedef struct Calls {
|
||||
int64 calls; /* # of times executed */
|
||||
int64 rows; /* total # of retrieved or affected rows */
|
||||
double usage; /* usage factor */
|
||||
} Calls;
|
||||
|
||||
|
||||
typedef struct Blocks
|
||||
{
|
||||
typedef struct Blocks {
|
||||
int64 shared_blks_hit; /* # of shared buffer hits */
|
||||
int64 shared_blks_read; /* # of shared disk blocks read */
|
||||
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_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
|
||||
* msec */
|
||||
|
||||
|
@ -296,22 +293,23 @@ typedef struct Blocks
|
|||
*/
|
||||
instr_time instr_blk_read_time; /* time spent reading 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_write_time; /* time spent writing temp 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 {
|
||||
int64 jit_functions; /* total number of JIT functions emitted */
|
||||
double jit_generation_time; /* total time to generate jit code */
|
||||
int64 jit_inlining_count; /* number of times inlining time has been
|
||||
* > 0 */
|
||||
int64 jit_inlining_count; /* number of times inlining time has
|
||||
* been > 0 */
|
||||
double jit_inlining_time; /* total time to inline jit code */
|
||||
int64 jit_optimization_count; /* number of times optimization time
|
||||
* has been > 0 */
|
||||
double jit_optimization_time; /* total time to optimize jit code */
|
||||
int64 jit_emission_count; /* number of times emission time has been
|
||||
* > 0 */
|
||||
int64 jit_emission_count; /* number of times emission time has
|
||||
* been > 0 */
|
||||
double jit_emission_time; /* total time to emit jit code */
|
||||
|
||||
/*
|
||||
|
@ -324,21 +322,18 @@ typedef struct JitInfo
|
|||
instr_time instr_emission_counter; /* emission counter */
|
||||
} JitInfo;
|
||||
|
||||
typedef struct SysInfo
|
||||
{
|
||||
typedef struct SysInfo {
|
||||
double utime; /* user cpu time */
|
||||
double stime; /* system cpu time */
|
||||
} SysInfo;
|
||||
|
||||
typedef struct Wal_Usage
|
||||
{
|
||||
typedef struct Wal_Usage {
|
||||
int64 wal_records; /* # of WAL records generated */
|
||||
int64 wal_fpi; /* # of WAL full page images generated */
|
||||
uint64 wal_bytes; /* total amount of WAL bytes generated */
|
||||
} Wal_Usage;
|
||||
|
||||
typedef struct Counters
|
||||
{
|
||||
typedef struct Counters {
|
||||
Calls calls;
|
||||
QueryInfo info;
|
||||
CallTime time;
|
||||
|
@ -361,8 +356,7 @@ typedef struct Counters
|
|||
/*
|
||||
* Statistics per statement
|
||||
*/
|
||||
typedef struct pgsmEntry
|
||||
{
|
||||
typedef struct pgsmEntry {
|
||||
pgsmHashKey key; /* hash key of entry - MUST BE FIRST */
|
||||
uint64 pgsm_query_id; /* pgsm generate normalized query hash */
|
||||
char datname[NAMEDATALEN]; /* database name */
|
||||
|
@ -370,8 +364,7 @@ typedef struct pgsmEntry
|
|||
Counters counters; /* the statistics for this query */
|
||||
int encoding; /* query text encoding */
|
||||
slock_t mutex; /* protects the counters only */
|
||||
union
|
||||
{
|
||||
union {
|
||||
dsa_pointer query_pos; /* query location within query buffer */
|
||||
char *query_pointer;
|
||||
} query_text;
|
||||
|
@ -380,8 +373,7 @@ typedef struct pgsmEntry
|
|||
/*
|
||||
* Global shared state
|
||||
*/
|
||||
typedef struct pgsmSharedState
|
||||
{
|
||||
typedef struct pgsmSharedState {
|
||||
LWLock *lock; /* protects hashtable search/modification */
|
||||
slock_t mutex; /* protects following fields only: */
|
||||
pg_atomic_uint64 current_wbucket;
|
||||
|
@ -393,25 +385,25 @@ typedef struct pgsmSharedState
|
|||
* dshash also lives in this memory when
|
||||
* USE_DYNAMIC_HASH is enabled */
|
||||
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)
|
||||
*/
|
||||
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
|
||||
* msec; including 2 outlier buckets */
|
||||
* msec; including 2
|
||||
* outlier buckets */
|
||||
bool pgsm_oom;
|
||||
} pgsmSharedState;
|
||||
|
||||
typedef struct pgsmLocalState
|
||||
{
|
||||
typedef struct pgsmLocalState {
|
||||
pgsmSharedState *shared_pgsmState;
|
||||
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;
|
||||
} pgsmLocalState;
|
||||
|
||||
|
@ -419,8 +411,7 @@ typedef struct pgsmLocalState
|
|||
/*
|
||||
* Struct for tracking locations/lengths of constants during normalization
|
||||
*/
|
||||
typedef struct LocationLen
|
||||
{
|
||||
typedef struct LocationLen {
|
||||
int location; /* start offset in query text */
|
||||
int length; /* length in bytes, or -1 to ignore */
|
||||
} LocationLen;
|
||||
|
@ -429,8 +420,7 @@ typedef struct LocationLen
|
|||
* Working state for computing a query jumble and producing a normalized
|
||||
* query string
|
||||
*/
|
||||
typedef struct JumbleState
|
||||
{
|
||||
typedef struct JumbleState {
|
||||
/* Jumble of current query tree */
|
||||
unsigned char *jumble;
|
||||
|
||||
|
@ -480,8 +470,7 @@ void init_guc(void);
|
|||
|
||||
/* GUC variables*/
|
||||
/*---- GUC variables ----*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
PSGM_TRACK_NONE = 0, /* track no statements */
|
||||
PGSM_TRACK_TOP, /* only top level statements */
|
||||
PGSM_TRACK_ALL /* all statements, including nested ones */
|
||||
|
@ -494,8 +483,7 @@ static const struct config_enum_entry track_options[] =
|
|||
{NULL, 0, false}
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
HISTOGRAM_START,
|
||||
HISTOGRAM_END,
|
||||
HISTOGRAM_COUNT
|
||||
|
|
Loading…
Reference in New Issue