Fixing code indentation with pgindent

pull/389/head
Hamid Akhtar 2023-02-27 14:18:19 +05:00 committed by Muhammad Usama
parent 1883b05fc7
commit faa938b8f1
4 changed files with 3440 additions and 3576 deletions

View File

@ -40,8 +40,7 @@ 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 */
@ -53,8 +52,7 @@ pgsm_query_area_size(void)
* 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
@ -72,8 +70,7 @@ 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();
@ -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;
@ -121,9 +117,10 @@ pgsm_startup(void)
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);
@ -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);
@ -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); 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 */
@ -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;

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -169,8 +175,7 @@ extern volatile bool __pgsm_do_not_capture_error;
#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,8 +364,7 @@ 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;
@ -380,8 +373,7 @@ typedef struct 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,25 +385,25 @@ 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;
@ -419,8 +411,7 @@ typedef struct pgsmLocalState
/* /*
* 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;
@ -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