Skip to content

Commit

Permalink
Format source using pgindent
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfronza committed Aug 15, 2024
1 parent 11e0cd5 commit 36c9980
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ static void pgsm_update_entry(pgsmEntry *entry,
const struct JitInstrumentation *jitusage,
bool reset,
pgsmStoreKind kind);
static void pgsm_store_ex(pgsmEntry * entry, ParamListInfo params);
static void pgsm_store_ex(pgsmEntry *entry, ParamListInfo params);

/* Stores query entry in normalized form */
static inline void pgsm_store(pgsmEntry * entry)
static inline void
pgsm_store(pgsmEntry *entry)
{
pgsm_store_ex(entry, NULL);
}
Expand Down Expand Up @@ -709,7 +710,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;

/*
* Making sure it is a per query context so that there's no memory
Expand Down Expand Up @@ -1889,7 +1890,8 @@ pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info)
* inserted or if the time to execute the query exceeds the average
* time computed for the same query.
*/
void pgsm_store_ex(pgsmEntry *entry, ParamListInfo params)
void
pgsm_store_ex(pgsmEntry *entry, ParamListInfo params)
{
pgsmEntry *shared_hash_entry;
pgsmSharedState *pgsm;
Expand Down Expand Up @@ -1994,7 +1996,8 @@ void pgsm_store_ex(pgsmEntry *entry, ParamListInfo params)
char *query_buff;

/* Denormalize the query if normalization is off */
if (!pgsm_normalized_query && params != NULL) {
if (!pgsm_normalized_query && params != NULL)
{
query_info = get_denormalized_query(params, query);
query = query_info.data;
query_len = query_info.len;
Expand Down Expand Up @@ -2088,15 +2091,19 @@ void pgsm_store_ex(pgsmEntry *entry, ParamListInfo params)
snprintf(shared_hash_entry->datname, sizeof(shared_hash_entry->datname), "%s", entry->datname);
snprintf(shared_hash_entry->username, sizeof(shared_hash_entry->username), "%s", entry->username);
}
/* Entry already exists, if query normalization is disabled and
* the query execution time exceeds the mean time for this query,
* then we denormalize the query so users can inspect which arguments
* caused the query to take more time to execute */

/*
* Entry already exists, if query normalization is disabled and the query
* execution time exceeds the mean time for this query, then we
* denormalize the query so users can inspect which arguments caused the
* query to take more time to execute
*/
else if (
!pgsm_normalized_query &&
params != NULL &&
entry->counters.time.total_time > shared_hash_entry->counters.time.mean_time
){
!pgsm_normalized_query &&
params != NULL &&
entry->counters.time.total_time > shared_hash_entry->counters.time.mean_time
)
{
dsa_pointer dsa_query_pointer;
dsa_area *query_dsa_area;
char *query_buff;
Expand All @@ -2114,7 +2121,10 @@ void pgsm_store_ex(pgsmEntry *entry, ParamListInfo params)
dsa_query_pointer = dsa_allocate_extended(query_dsa_area, query_len + 1, DSA_ALLOC_NO_OOM | DSA_ALLOC_ZERO);
if (DsaPointerIsValid(dsa_query_pointer))
{
/* Get the memory address from DSA pointer and copy the query text to it. */
/*
* Get the memory address from DSA pointer and copy the query text
* to it.
*/
query_buff = dsa_get_address(query_dsa_area, dsa_query_pointer);
memcpy(query_buff, query, query_len);

Expand Down Expand Up @@ -4087,9 +4097,9 @@ get_query_id(JumbleState *jstate, Query *query)
void
get_param_value(const ParamListInfo plist, int idx, StringInfoData *buffer)
{
Oid typoutput;
bool typisvarlena;
char *pstring;
Oid typoutput;
bool typisvarlena;
char *pstring;
ParamExternData *param;

Assert(idx < plist->numParams);
Expand All @@ -4111,11 +4121,11 @@ get_param_value(const ParamListInfo plist, int idx, StringInfoData *buffer)
StringInfoData
get_denormalized_query(const ParamListInfo paramlist, const char *query_text)
{
int current_param;
const char *cursor_ori;
const char *cursor_curr;
StringInfoData result_buf;
ptrdiff_t len;
int current_param;
const char *cursor_ori;
const char *cursor_curr;
StringInfoData result_buf;
ptrdiff_t len;

current_param = 0;
cursor_ori = query_text;
Expand All @@ -4125,35 +4135,35 @@ get_denormalized_query(const ParamListInfo paramlist, const char *query_text)

do
{
// advance cursor until detecting a placeholder '$' start.
/* advance cursor until detecting a placeholder '$' start. */
while (*cursor_ori && *cursor_ori != '$')
++cursor_ori;

// calculate length of query text before placeholder.
/* calculate length of query text before placeholder. */
len = cursor_ori - cursor_curr;

// check if end of string is reached
/* check if end of string is reached */
if (!*cursor_ori)
{
// there may have remaining query data to append
/* there may have remaining query data to append */
if (len > 0)
appendBinaryStringInfo(&result_buf, cursor_curr, len);

break;
}

// append query text before the '$' sign found.
/* append query text before the '$' sign found. */
if (len > 0)
appendBinaryStringInfo(&result_buf, cursor_curr, len);

// skip '$'
/* skip '$' */
++cursor_ori;

/* skip the placeholder */
while(*cursor_ori && *cursor_ori >= '0' && *cursor_ori <= '9')
while (*cursor_ori && *cursor_ori >= '0' && *cursor_ori <= '9')
cursor_ori++;

// advance current cursor
/* advance current cursor */
cursor_curr = cursor_ori;

/* replace the placeholder with actual value */
Expand Down

0 comments on commit 36c9980

Please sign in to comment.