Revert "Format sources"

This reverts commit 6ef992d9f0.
pull/475/head
Artem Gavrilov 2024-07-18 15:43:50 +02:00
parent 3e0b194764
commit 6a70322858
4 changed files with 62 additions and 63 deletions

2
guc.c
View File

@ -48,7 +48,7 @@ static bool check_overflow_targer(int *newval, void **extra, GucSource source);
void
init_guc(void)
{
pgsm_track = PGSM_TRACK_TOP;
pgsm_track = PGSM_TRACK_TOP;
DefineCustomIntVariable("pg_stat_monitor.pgsm_max", /* name */
"Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.", /* short_desc */

View File

@ -19,9 +19,9 @@
#include "pg_stat_monitor.h"
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 void InitializeSharedState(pgsmSharedState *pgsm);
static void InitializeSharedState(pgsmSharedState * pgsm);
#define PGSM_BUCKET_INFO_SIZE (sizeof(TimestampTz) * pgsm_max_buckets)
#define PGSM_SHARED_STATE_SIZE (sizeof(pgsmSharedState) + PGSM_BUCKET_INFO_SIZE)
@ -142,9 +142,9 @@ pgsm_startup(void)
*/
dsa_detach(dsa);
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
"pg_stat_monitor local store",
ALLOCSET_DEFAULT_SIZES);
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
"pg_stat_monitor local store",
ALLOCSET_DEFAULT_SIZES);
}
#ifdef BENCHMARK
@ -161,7 +161,7 @@ pgsm_startup(void)
}
static void
InitializeSharedState(pgsmSharedState *pgsm)
InitializeSharedState(pgsmSharedState * pgsm)
{
pg_atomic_init_u64(&pgsm->current_wbucket, 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.
*/
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;
@ -238,8 +238,7 @@ pgsm_attach_shmem(void)
MemoryContextSwitchTo(oldcontext);
}
MemoryContext
GetPgsmMemoryContext(void)
MemoryContext GetPgsmMemoryContext(void)
{
return pgsmStateLocal.pgsm_mem_cxt;
}
@ -288,7 +287,7 @@ pgsm_shmem_shutdown(int code, Datum arg)
}
pgsmEntry *
hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding)
{
pgsmEntry *entry = NULL;
bool found = false;
@ -392,7 +391,7 @@ IsSystemOOM(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
void *entry;
@ -405,7 +404,7 @@ pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey *key, bool *
}
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
return dshash_find(shared_hash, key, false);

View File

@ -32,7 +32,7 @@ typedef enum pgsmVersion
{
PGSM_V1_0 = 0,
PGSM_V2_0
} pgsmVersion;
} pgsmVersion;
PG_MODULE_MAGIC;
@ -202,9 +202,9 @@ char *unpack_sql_state(int sql_state);
!IsA(n, DeallocateStmt))
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 pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create);
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 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 void pgsm_cleanup_callback(void *arg);
@ -218,13 +218,13 @@ MemoryContextCallback mem_cxt_reset_callback =
};
volatile bool callback_setup = false;
static void pgsm_update_entry(pgsmEntry *entry,
static void pgsm_update_entry(pgsmEntry * entry,
const char *query,
char *comments,
int comments_len,
PlanInfo *plan_info,
SysInfo *sys_info,
ErrorInfo *error_info,
PlanInfo * plan_info,
SysInfo * sys_info,
ErrorInfo * error_info,
double plan_total_time,
double exec_total_time,
uint64 rows,
@ -233,7 +233,7 @@ static void pgsm_update_entry(pgsmEntry *entry,
const struct JitInstrumentation *jitusage,
bool reset,
pgsmStoreKind kind);
static void pgsm_store(pgsmEntry *entry);
static void pgsm_store(pgsmEntry * entry);
static void pg_stat_monitor_internal(FunctionCallInfo fcinfo,
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 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
@ -696,7 +696,7 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
/* Extract the plan information in case of SELECT statement */
if (queryDesc->operation == CMD_SELECT && pgsm_enable_query_plan)
{
int rv;
int rv;
MemoryContext oldctx;
/*
@ -806,9 +806,9 @@ pgsm_ExecutorCheckPerms(List *rt, List *rp, bool abort)
if (rte->rtekind != RTE_RELATION
#if PG_VERSION_NUM >= 160000
&& (rte->rtekind != RTE_SUBQUERY && rte->relkind != 'v')
&& (rte->rtekind != RTE_SUBQUERY && rte->relkind != 'v')
#endif
)
)
continue;
if (i < REL_LST)
@ -1336,13 +1336,13 @@ pg_get_client_addr(bool *ok)
}
static void
pgsm_update_entry(pgsmEntry *entry,
pgsm_update_entry(pgsmEntry * entry,
const char *query,
char *comments,
int comments_len,
PlanInfo *plan_info,
SysInfo *sys_info,
ErrorInfo *error_info,
PlanInfo * plan_info,
SysInfo * sys_info,
ErrorInfo * error_info,
double plan_total_time,
double exec_total_time,
uint64 rows,
@ -1364,7 +1364,7 @@ pgsm_update_entry(pgsmEntry *entry,
/* volatile block */
{
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
if (kind == PGSM_STORE)
SpinLockAcquire(&e->mutex);
@ -1462,7 +1462,7 @@ pgsm_update_entry(pgsmEntry *entry,
if (exec_nested_level >= 0 && exec_nested_level < max_stack_depth)
{
int parent_query_len = nested_query_txts[exec_nested_level - 1] ?
strlen(nested_query_txts[exec_nested_level - 1]) : 0;
strlen(nested_query_txts[exec_nested_level - 1]) : 0;
e->counters.info.parentid = nested_queryids[exec_nested_level - 1];
e->counters.info.parent_query = InvalidDsaPointer;
@ -1606,7 +1606,7 @@ pgsm_store_error(const char *query, ErrorData *edata)
}
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 */
MemoryContext oldctx = MemoryContextSwitchTo(GetPgsmMemoryContext());
@ -1617,7 +1617,7 @@ 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)
pgsm_get_entry_for_query(uint64 queryid, PlanInfo * plan_info, const char *query_text, int query_len, bool create)
{
pgsmEntry *entry = 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.
*/
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;
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.
*/
static void
pgsm_store(pgsmEntry *entry)
pgsm_store(pgsmEntry * entry)
{
pgsmEntry *shared_hash_entry;
pgsmSharedState *pgsm;
@ -1895,9 +1895,9 @@ pgsm_store(pgsmEntry *entry)
{
ereport(WARNING,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
} PGSM_END_DISABLE_ERROR_CAPTURE();
}
@ -1999,7 +1999,7 @@ IsBucketValid(uint64 bucketid)
TimestampDifference(pgsm->bucket_start_time[bucketid], current_tz, &secs, &microsecs);
if (secs > ((int64) pgsm_bucket_time * pgsm_max_buckets))
if (secs > ((int64)pgsm_bucket_time * pgsm_max_buckets))
return false;
return true;
}
@ -2111,7 +2111,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
/* copy counters to a local variable to keep locking time short */
{
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
volatile pgsmEntry *e = (volatile pgsmEntry *) entry;
SpinLockAcquire(&e->mutex);
tmp = e->counters;
@ -2426,7 +2426,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
}
static uint64
get_next_wbucket(pgsmSharedState *pgsm)
get_next_wbucket(pgsmSharedState * pgsm)
{
struct timeval tv;
uint64 current_bucket_sec;

View File

@ -195,7 +195,7 @@ typedef enum pgsmStoreKind
PGSM_ERROR,
PGSM_NUMKIND /* Must be last value of this enum */
} pgsmStoreKind;
} pgsmStoreKind;
/* the assumption of query max nested level */
#define DEFAULT_MAX_NESTED_LEVEL 10
@ -208,7 +208,7 @@ typedef enum AGG_KEY
AGG_KEY_DATABASE = 0,
AGG_KEY_USER,
AGG_KEY_HOST
} AGG_KEY;
} AGG_KEY;
#define MAX_QUERY_LEN 1024
@ -220,7 +220,7 @@ typedef struct CallTime
double max_time; /* maximum execution time in msec */
double mean_time; /* mean execution time in msec */
double sum_var_time; /* sum of variances in execution time in msec */
} CallTime;
} CallTime;
typedef struct PlanInfo
@ -228,7 +228,7 @@ typedef struct PlanInfo
uint64 planid; /* plan identifier */
char plan_text[PLAN_TEXT_LEN]; /* plan text */
size_t plan_len; /* strlen(plan_text) */
} PlanInfo;
} PlanInfo;
typedef struct pgsmHashKey
{
@ -240,7 +240,7 @@ typedef struct pgsmHashKey
Oid dbid; /* database OID */
uint32 ip; /* client ip address */
bool toplevel; /* query executed at top level */
} pgsmHashKey;
} pgsmHashKey;
typedef struct QueryInfo
{
@ -262,14 +262,14 @@ typedef struct ErrorInfo
int64 elevel; /* error elevel */
char sqlcode[SQLCODE_LEN]; /* error sqlcode */
char message[ERROR_MESSAGE_LEN]; /* error message text */
} ErrorInfo;
} ErrorInfo;
typedef struct Calls
{
int64 calls; /* # of times executed */
int64 rows; /* total # of retrieved or affected rows */
double usage; /* usage factor */
} Calls;
} Calls;
typedef struct Blocks
@ -299,7 +299,7 @@ typedef struct 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 */
} Blocks;
} Blocks;
typedef struct JitInfo
{
@ -323,20 +323,20 @@ typedef struct JitInfo
instr_time instr_inlining_counter; /* inlining counter */
instr_time instr_optimization_counter; /* optimization counter */
instr_time instr_emission_counter; /* emission counter */
} JitInfo;
} JitInfo;
typedef struct SysInfo
{
double utime; /* user cpu time */
double stime; /* system cpu time */
} SysInfo;
} SysInfo;
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;
} Wal_Usage;
typedef struct Counters
{
@ -376,7 +376,7 @@ typedef struct pgsmEntry
dsa_pointer query_pos; /* query location within query buffer */
char *query_pointer;
} query_text;
} pgsmEntry;
} pgsmEntry;
/*
* Global shared state
@ -399,8 +399,8 @@ typedef struct pgsmSharedState
*/
bool pgsm_oom;
TimestampTz bucket_start_time[]; /* start time of the bucket */
} pgsmSharedState;
TimestampTz bucket_start_time[]; /* start time of the bucket */
} pgsmSharedState;
typedef struct pgsmLocalState
{
@ -408,9 +408,9 @@ typedef struct pgsmLocalState
dsa_area *dsa; /* local dsa area for backend attached to the
* dsa area created by postmaster at startup. */
PGSM_HASH_TABLE *shared_hash;
MemoryContext pgsm_mem_cxt;
MemoryContext pgsm_mem_cxt;
} pgsmLocalState;
} pgsmLocalState;
#if PG_VERSION_NUM < 140000
/*
@ -465,7 +465,7 @@ pgsmSharedState *pgsm_get_ss(void);
void hash_query_entries();
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);
pgsmEntry *hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding);
pgsmEntry *hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding);
Size pgsm_ShmemSize(void);
void pgsm_startup(void);
@ -483,7 +483,7 @@ typedef enum
PSGM_TRACK_NONE = 0, /* track no statements */
PGSM_TRACK_TOP, /* only top level statements */
PGSM_TRACK_ALL /* all statements, including nested ones */
} PGSMTrackLevel;
} PGSMTrackLevel;
static const struct config_enum_entry track_options[] =
{
{"none", PSGM_TRACK_NONE, false},
@ -497,7 +497,7 @@ typedef enum
HISTOGRAM_START,
HISTOGRAM_END,
HISTOGRAM_COUNT
} HistogramTimingType;
} HistogramTimingType;
extern int pgsm_max;
extern int pgsm_query_max_len;
@ -522,8 +522,8 @@ extern int pgsm_track;
#define HOOK_STATS_SIZE 0
#endif
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_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_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_term(PGSM_HASH_SEQ_STATUS * hstat);