Revert "Println debug"

This reverts commit c8cbf0f28d.
pull/583/head
Artem Gavrilov 2025-11-20 18:20:01 +02:00
parent c8cbf0f28d
commit 1c18b0b21f
1 changed files with 3 additions and 58 deletions

View File

@ -283,7 +283,6 @@ static void pgsm_lock_release(pgsmSharedState *pgsm);
void void
_PG_init(void) _PG_init(void)
{ {
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
elog(DEBUG2, "[pg_stat_monitor] pg_stat_monitor: %s().", __FUNCTION__); elog(DEBUG2, "[pg_stat_monitor] pg_stat_monitor: %s().", __FUNCTION__);
/* /*
@ -297,29 +296,22 @@ _PG_init(void)
if (!process_shared_preload_libraries_in_progress) if (!process_shared_preload_libraries_in_progress)
return; return;
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
/* Inilize the GUC variables */ /* Inilize the GUC variables */
init_guc(); init_guc();
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
set_histogram_bucket_timings(); set_histogram_bucket_timings();
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
#if PG_VERSION_NUM >= 140000 #if PG_VERSION_NUM >= 140000
/* /*
* Inform the postmaster that we want to enable query_id calculation if * Inform the postmaster that we want to enable query_id calculation if
* compute_query_id is set to auto. * compute_query_id is set to auto.
*/ */
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
EnableQueryId(); EnableQueryId();
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
#endif #endif
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
EmitWarningsOnPlaceholders("pg_stat_monitor"); EmitWarningsOnPlaceholders("pg_stat_monitor");
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
/* /*
* Install hooks. * Install hooks.
*/ */
@ -350,7 +342,6 @@ _PG_init(void)
prev_ExecutorCheckPerms_hook = ExecutorCheckPerms_hook; prev_ExecutorCheckPerms_hook = ExecutorCheckPerms_hook;
ExecutorCheckPerms_hook = HOOK(pgsm_ExecutorCheckPerms); ExecutorCheckPerms_hook = HOOK(pgsm_ExecutorCheckPerms);
printf("pg_stat_monitor _PG_init: %s().\n", __LINE__);
nested_queryids = (int64 *) malloc(sizeof(int64) * max_stack_depth); nested_queryids = (int64 *) malloc(sizeof(int64) * max_stack_depth);
nested_query_txts = (char **) malloc(sizeof(char *) * max_stack_depth); nested_query_txts = (char **) malloc(sizeof(char *) * max_stack_depth);
@ -366,19 +357,15 @@ _PG_init(void)
void void
pgsm_shmem_startup(void) pgsm_shmem_startup(void)
{ {
printf("pg_stat_monitor pgsm_shmem_startup: %s().\n", __LINE__);
if (prev_shmem_startup_hook) if (prev_shmem_startup_hook)
prev_shmem_startup_hook(); prev_shmem_startup_hook();
printf("pg_stat_monitor pgsm_shmem_startup: %s().\n", __LINE__);
pgsm_startup(); pgsm_startup();
printf("pg_stat_monitor pgsm_shmem_startup: %s().\n", __LINE__);
} }
static void static void
request_additional_shared_resources(void) request_additional_shared_resources(void)
{ {
printf("pg_stat_monitor request_additional_shared_resources: %s().\n", __LINE__);
/* /*
* Request additional shared resources. (These are no-ops if we're not in * Request additional shared resources. (These are no-ops if we're not in
* the postmaster process.) We'll allocate or attach to the shared * the postmaster process.) We'll allocate or attach to the shared
@ -405,19 +392,15 @@ pg_stat_monitor_version(PG_FUNCTION_ARGS)
static void static void
pgsm_shmem_request(void) pgsm_shmem_request(void)
{ {
printf("pg_stat_monitor pgsm_shmem_request: %s().\n", __LINE__);
if (prev_shmem_request_hook) if (prev_shmem_request_hook)
prev_shmem_request_hook(); prev_shmem_request_hook();
printf("pg_stat_monitor pgsm_shmem_request: %s().\n", __LINE__);
request_additional_shared_resources(); request_additional_shared_resources();
printf("pg_stat_monitor pgsm_shmem_request: %s().\n", __LINE__);
} }
#endif #endif
static void static void
pgsm_post_parse_analyze_internal(ParseState *pstate, Query *query, JumbleState *jstate) pgsm_post_parse_analyze_internal(ParseState *pstate, Query *query, JumbleState *jstate)
{ {
printf("pg_stat_monitor pgsm_post_parse_analyze_internal: %s().\n", __LINE__);
pgsmEntry *entry; pgsmEntry *entry;
const char *query_text; const char *query_text;
char *norm_query = NULL; char *norm_query = NULL;
@ -426,11 +409,9 @@ pgsm_post_parse_analyze_internal(ParseState *pstate, Query *query, JumbleState *
int query_len; int query_len;
/* Safety check... */ /* Safety check... */
printf("pg_stat_monitor pgsm_post_parse_analyze_internal: %s().\n", __LINE__);
if (!IsSystemInitialized()) if (!IsSystemInitialized())
return; return;
printf("pg_stat_monitor pgsm_post_parse_analyze_internal: %s().\n", __LINE__);
if (callback_setup == false) if (callback_setup == false)
{ {
/* /*
@ -444,11 +425,9 @@ pgsm_post_parse_analyze_internal(ParseState *pstate, Query *query, JumbleState *
} }
} }
printf("pg_stat_monitor pgsm_post_parse_analyze_internal: %s().\n", __LINE__);
if (!pgsm_enabled(nesting_level)) if (!pgsm_enabled(nesting_level))
return; return;
printf("pg_stat_monitor pgsm_post_parse_analyze_internal: %s().\n", __LINE__);
/* /*
* If it's EXECUTE, clear the queryId so that stats will accumulate for * If it's EXECUTE, clear the queryId so that stats will accumulate for
* the underlying PREPARE. But don't do this if we're not tracking * the underlying PREPARE. But don't do this if we're not tracking
@ -630,7 +609,7 @@ pgsm_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
nested_queryids[nesting_level] = queryDesc->plannedstmt->queryId; nested_queryids[nesting_level] = queryDesc->plannedstmt->queryId;
nested_query_txts[nesting_level] = strdup(queryDesc->sourceText); nested_query_txts[nesting_level] = strdup(queryDesc->sourceText);
} }
printf("pg_stat_monitor pgsm_ExecutorRun: %s().\n", __LINE__);
nesting_level++; nesting_level++;
PG_TRY(); PG_TRY();
{ {
@ -672,7 +651,6 @@ pgsm_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
PG_RE_THROW(); PG_RE_THROW();
} }
PG_END_TRY(); PG_END_TRY();
printf("pg_stat_monitor pgsm_ExecutorRun: %s().\n", __LINE__);
} }
/* /*
@ -682,7 +660,7 @@ static void
pgsm_ExecutorFinish(QueryDesc *queryDesc) pgsm_ExecutorFinish(QueryDesc *queryDesc)
{ {
nesting_level++; nesting_level++;
printf("pg_stat_monitor pgsm_ExecutorFinish: %s().\n", __LINE__);
PG_TRY(); PG_TRY();
{ {
if (prev_ExecutorFinish) if (prev_ExecutorFinish)
@ -732,7 +710,6 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
PlanInfo *plan_ptr = NULL; PlanInfo *plan_ptr = NULL;
pgsmEntry *entry = NULL; pgsmEntry *entry = NULL;
printf("pg_stat_monitor pgsm_ExecutorEnd: %s().\n", __LINE__);
/* Extract the plan information in case of SELECT statement */ /* Extract the plan information in case of SELECT statement */
if (queryDesc->operation == CMD_SELECT && pgsm_enable_query_plan) if (queryDesc->operation == CMD_SELECT && pgsm_enable_query_plan)
{ {
@ -762,7 +739,6 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
MemoryContextSwitchTo(oldctx); MemoryContextSwitchTo(oldctx);
} }
printf("pg_stat_monitor pgsm_ExecutorEnd: %s().\n", __LINE__);
if (queryId != INT64CONST(0) && queryDesc->totaltime && pgsm_enabled(nesting_level)) if (queryId != INT64CONST(0) && queryDesc->totaltime && pgsm_enabled(nesting_level))
{ {
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true, queryDesc->operation); entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true, queryDesc->operation);
@ -824,14 +800,13 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
pgsm_store(entry); pgsm_store(entry);
} }
printf("pg_stat_monitor pgsm_ExecutorEnd: %s().\n", __LINE__);
if (prev_ExecutorEnd) if (prev_ExecutorEnd)
prev_ExecutorEnd(queryDesc); prev_ExecutorEnd(queryDesc);
else else
standard_ExecutorEnd(queryDesc); standard_ExecutorEnd(queryDesc);
pgsm_delete_entry(queryDesc->plannedstmt->queryId); pgsm_delete_entry(queryDesc->plannedstmt->queryId);
printf("pg_stat_monitor pgsm_ExecutorEnd: %s().\n", __LINE__);
num_relations = 0; num_relations = 0;
} }
@ -1071,7 +1046,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
int64 queryId = 0; int64 queryId = 0;
bool enabled = pgsm_track_utility && pgsm_enabled(nesting_level); bool enabled = pgsm_track_utility && pgsm_enabled(nesting_level);
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
#if PG_VERSION_NUM < 140000 #if PG_VERSION_NUM < 140000
int len = strlen(queryString); int len = strlen(queryString);
@ -1079,7 +1053,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
#else #else
queryId = pstmt->queryId; queryId = pstmt->queryId;
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
/* /*
* Force utility statements to get queryId zero. We do this even in cases * Force utility statements to get queryId zero. We do this even in cases
* where the statement contains an optimizable statement for which a * where the statement contains an optimizable statement for which a
@ -1093,7 +1066,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
pstmt->queryId = INT64CONST(0); pstmt->queryId = INT64CONST(0);
#endif #endif
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
/* /*
* If it's an EXECUTE statement, we don't track it and don't increment the * If it's an EXECUTE statement, we don't track it and don't increment the
* nesting level. This allows the cycles to be charged to the underlying * nesting level. This allows the cycles to be charged to the underlying
@ -1133,7 +1105,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
INSTR_TIME_SET_CURRENT(start); INSTR_TIME_SET_CURRENT(start);
nesting_level++; nesting_level++;
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
PG_TRY(); PG_TRY();
{ {
#if PG_VERSION_NUM >= 140000 #if PG_VERSION_NUM >= 140000
@ -1166,17 +1137,14 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
PG_CATCH(); PG_CATCH();
{ {
nesting_level--; nesting_level--;
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
PG_RE_THROW(); PG_RE_THROW();
} }
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
sys_info.utime = 0; sys_info.utime = 0;
sys_info.stime = 0; sys_info.stime = 0;
PG_END_TRY(); PG_END_TRY();
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
if (getrusage(RUSAGE_SELF, &rusage_end) != 0) if (getrusage(RUSAGE_SELF, &rusage_end) != 0)
elog(DEBUG1, "[pg_stat_monitor] pgsm_ProcessUtility: Failed to execute getrusage."); elog(DEBUG1, "[pg_stat_monitor] pgsm_ProcessUtility: Failed to execute getrusage.");
else else
@ -1185,7 +1153,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
sys_info.stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime); sys_info.stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime);
} }
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
INSTR_TIME_SET_CURRENT(duration); INSTR_TIME_SET_CURRENT(duration);
INSTR_TIME_SUBTRACT(duration, start); INSTR_TIME_SUBTRACT(duration, start);
@ -1203,12 +1170,10 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
memset(&walusage, 0, sizeof(WalUsage)); memset(&walusage, 0, sizeof(WalUsage));
WalUsageAccumDiff(&walusage, &pgWalUsage, &walusage_start); WalUsageAccumDiff(&walusage, &pgWalUsage, &walusage_start);
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
/* calc differences of buffer counters. */ /* calc differences of buffer counters. */
memset(&bufusage, 0, sizeof(BufferUsage)); memset(&bufusage, 0, sizeof(BufferUsage));
BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start); BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start);
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
/* Create an entry for this query */ /* Create an entry for this query */
entry = pgsm_create_hash_entry(0, queryId, NULL); entry = pgsm_create_hash_entry(0, queryId, NULL);
@ -1219,13 +1184,11 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len); entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len);
entry->counters.info.cmd_type = pstmt->commandType; entry->counters.info.cmd_type = pstmt->commandType;
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
pgsm_add_to_list(entry, query_text, query_len); pgsm_add_to_list(entry, query_text, query_len);
/* Check that we've not exceeded max_stack_depth */ /* Check that we've not exceeded max_stack_depth */
Assert(list_length(lentries) <= max_stack_depth); Assert(list_length(lentries) <= max_stack_depth);
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
/* The plan details are captured when the query finishes */ /* The plan details are captured when the query finishes */
pgsm_update_entry(entry, /* entry */ pgsm_update_entry(entry, /* entry */
(char *) query_text, /* query */ (char *) query_text, /* query */
@ -1277,7 +1240,6 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
{ {
#endif #endif
#if PG_VERSION_NUM >= 140000 #if PG_VERSION_NUM >= 140000
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
if (prev_ProcessUtility) if (prev_ProcessUtility)
prev_ProcessUtility(pstmt, queryString, prev_ProcessUtility(pstmt, queryString,
readOnlyTree, readOnlyTree,
@ -1315,9 +1277,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
PG_END_TRY(); PG_END_TRY();
#endif #endif
} }
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
pgsm_delete_entry(pstmt->queryId); pgsm_delete_entry(pstmt->queryId);
printf("pg_stat_monitor pgsm_ProcessUtility: %s().\n", __LINE__);
} }
/* /*
@ -1441,7 +1401,6 @@ pgsm_update_entry(pgsmEntry *entry,
int sqlcode_len = error_info ? strlen(error_info->sqlcode) : 0; int sqlcode_len = error_info ? strlen(error_info->sqlcode) : 0;
int plan_text_len = plan_info ? plan_info->plan_len : 0; int plan_text_len = plan_info ? plan_info->plan_len : 0;
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
/* /*
* Start collecting data for next bucket and reset all counters and * Start collecting data for next bucket and reset all counters and
* timestamps * timestamps
@ -1453,11 +1412,9 @@ pgsm_update_entry(pgsmEntry *entry,
entry->minmax_stats_since = entry->stats_since; entry->minmax_stats_since = entry->stats_since;
} }
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
if (kind == PGSM_STORE) if (kind == PGSM_STORE)
SpinLockAcquire(&entry->mutex); SpinLockAcquire(&entry->mutex);
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
/* /*
* Extract comments if enabled and only when the query has completed with * Extract comments if enabled and only when the query has completed with
* or without error * or without error
@ -1497,8 +1454,6 @@ pgsm_update_entry(pgsmEntry *entry,
} }
} }
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
if (kind == PGSM_EXEC || kind == PGSM_STORE) if (kind == PGSM_EXEC || kind == PGSM_STORE)
{ {
if (entry->counters.calls.calls == 0) if (entry->counters.calls.calls == 0)
@ -1532,7 +1487,6 @@ pgsm_update_entry(pgsmEntry *entry,
entry->counters.resp_calls[index]++; entry->counters.resp_calls[index]++;
} }
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
if (plan_text_len > 0 && !entry->counters.planinfo.plan_text[0]) if (plan_text_len > 0 && !entry->counters.planinfo.plan_text[0])
{ {
entry->counters.planinfo.planid = plan_info->planid; entry->counters.planinfo.planid = plan_info->planid;
@ -1595,7 +1549,6 @@ pgsm_update_entry(pgsmEntry *entry,
entry->counters.calls.rows += rows; entry->counters.calls.rows += rows;
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
if (bufusage) if (bufusage)
{ {
entry->counters.blocks.shared_blks_hit += bufusage->shared_blks_hit; entry->counters.blocks.shared_blks_hit += bufusage->shared_blks_hit;
@ -1641,7 +1594,6 @@ pgsm_update_entry(pgsmEntry *entry,
#endif #endif
} }
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
entry->counters.calls.usage += USAGE_EXEC(exec_total_time + plan_total_time); entry->counters.calls.usage += USAGE_EXEC(exec_total_time + plan_total_time);
if (sys_info) if (sys_info)
@ -1695,7 +1647,6 @@ pgsm_update_entry(pgsmEntry *entry,
} }
} }
printf("pg_stat_monitor pgsm_update_entry: %s().\n", __LINE__);
/* parallel worker counters */ /* parallel worker counters */
entry->counters.parallel_workers_to_launch += parallel_workers_to_launch; entry->counters.parallel_workers_to_launch += parallel_workers_to_launch;
entry->counters.parallel_workers_launched += parallel_workers_launched; entry->counters.parallel_workers_launched += parallel_workers_launched;
@ -1744,14 +1695,12 @@ pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len)
static void static void
pgsm_delete_entry(uint64 queryid) pgsm_delete_entry(uint64 queryid)
{ {
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
pgsmEntry *entry = NULL; pgsmEntry *entry = NULL;
ListCell *lc = NULL; ListCell *lc = NULL;
if (lentries == NIL) if (lentries == NIL)
return; return;
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
entry = (pgsmEntry *) llast(lentries); entry = (pgsmEntry *) llast(lentries);
if (entry->key.queryid == queryid) if (entry->key.queryid == queryid)
{ {
@ -1761,14 +1710,12 @@ pgsm_delete_entry(uint64 queryid)
return; return;
} }
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
/* /*
* The rest of the code is just paranoia. In theory this list is a stack, * The rest of the code is just paranoia. In theory this list is a stack,
* and we always want to remove the last item. Similarly, in the getter * and we always want to remove the last item. Similarly, in the getter
* method we are always looking for the last item. * method we are always looking for the last item.
*/ */
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
foreach(lc, lentries) foreach(lc, lentries)
{ {
entry = lfirst(lc); entry = lfirst(lc);
@ -1777,11 +1724,9 @@ pgsm_delete_entry(uint64 queryid)
pfree(entry->query_text.query_pointer); pfree(entry->query_text.query_pointer);
entry->query_text.query_pointer = NULL; entry->query_text.query_pointer = NULL;
lentries = list_delete_cell(lentries, lc); lentries = list_delete_cell(lentries, lc);
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
return; return;
} }
} }
printf("pg_stat_monitor pgsm_delete_entry: %s().\n", __LINE__);
} }
static pgsmEntry * static pgsmEntry *