Updating formatting of source code

pull/392/head
Hamid Akhtar 2023-03-01 18:02:16 +05:00 committed by Muhammad Usama
parent c7cb3d08be
commit 9ecd2ccbb7
4 changed files with 3507 additions and 3312 deletions

1
guc.c
View File

@ -41,6 +41,7 @@ static int pgsm_overflow_target; /* Not used since 2.0 */
static bool check_histogram_min(double *newval, void **extra, GucSource source);
static bool check_histogram_max(double *newval, void **extra, GucSource source);
static bool check_overflow_targer(int *newval, void **extra, GucSource source);
/*
* Define (or redefine) custom GUC variables.
*/

View File

@ -40,7 +40,8 @@ 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 */
@ -48,12 +49,15 @@ pgsm_query_area_size(void) {
#endif
return MAXALIGN(sz);
}
/*
* 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
sz = add_size(sz, MAX_BUCKETS_MEM);
@ -70,7 +74,8 @@ 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();
@ -86,6 +91,7 @@ pgsm_startup(void)
{
bool found = false;
pgsmSharedState *pgsm;
/* reset in case this is a restart within the postmaster */
pgsmStateLocal.dsa = NULL;
pgsmStateLocal.shared_hash = NULL;
@ -97,7 +103,8 @@ 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;
@ -125,6 +132,7 @@ pgsm_startup(void)
dsa_set_size_limit(dsa, -1);
pgsmStateLocal.shared_pgsmState = pgsm;
/*
* Postmaster will never access the dsa again, thus free it's local
* references.
@ -161,11 +169,13 @@ 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
dshash_table *dsh;
pgsm->hash_tranche_id = LWLockNewTrancheId();
dsh_params.tranche_id = pgsm->hash_tranche_id;
dsh = dshash_create(dsa, &dsh_params, 0);
@ -173,6 +183,7 @@ pgsm_create_bucket_hash(pgsmSharedState * pgsm, dsa_area * dsa) {
dshash_detach(dsh);
#else
HASHCTL info;
memset(&info, 0, sizeof(info));
info.keysize = sizeof(pgsmHashKey);
info.entrysize = sizeof(pgsmEntry);
@ -194,6 +205,7 @@ void
pgsm_attach_shmem(void)
{
MemoryContext oldcontext;
if (pgsmStateLocal.dsa)
return;
@ -205,6 +217,7 @@ pgsm_attach_shmem(void)
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.
@ -270,11 +283,13 @@ hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding)
{
pgsmEntry *entry = NULL;
bool found = false;
/* Find or create an entry with desired hash code */
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 */
@ -313,6 +328,7 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
{
PGSM_HASH_SEQ_STATUS hstat;
pgsmEntry *entry = NULL;
/* Store pending query ids from the previous bucket. */
if (!pgsmStateLocal.shared_hash)
@ -321,7 +337,8 @@ 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;
/*
@ -329,8 +346,10 @@ 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;
pgsm_hash_delete_current(&hstat, pgsmStateLocal.shared_hash, &entry->key);
@ -369,6 +388,7 @@ pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool
{
#if USE_DYNAMIC_HASH
void *entry;
entry = dshash_find_or_insert(shared_hash, key, found);
return entry;
#else

File diff suppressed because it is too large Load Diff

View File

@ -66,16 +66,13 @@
/* 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
@ -85,10 +82,9 @@
#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
@ -175,7 +171,8 @@ 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 */
@ -183,7 +180,8 @@ typedef struct WalUsage {
#endif
typedef enum pgsmStoreKind {
typedef enum pgsmStoreKind
{
PGSM_INVALID = -1,
/*
@ -206,7 +204,8 @@ 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
@ -215,7 +214,8 @@ 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 */
@ -224,13 +224,15 @@ 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,7 +243,8 @@ 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,
@ -255,20 +258,23 @@ 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 */
@ -282,8 +288,7 @@ 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 */
@ -293,23 +298,22 @@ 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 */
/*
@ -322,18 +326,21 @@ 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;
@ -356,7 +363,8 @@ 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 */
@ -364,7 +372,8 @@ 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;
@ -373,7 +382,8 @@ 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;
@ -385,11 +395,13 @@ 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
* (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
@ -400,7 +412,8 @@ typedef struct pgsmSharedState {
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. */
@ -411,7 +424,8 @@ 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;
@ -420,7 +434,8 @@ 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;
@ -470,7 +485,8 @@ 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 */
@ -483,7 +499,8 @@ static const struct config_enum_entry track_options[] =
{NULL, 0, false}
};
typedef enum {
typedef enum
{
HISTOGRAM_START,
HISTOGRAM_END,
HISTOGRAM_COUNT