Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7507a0

Browse files
authored
Merge pull request#79 from postgrespro/process_utility_hook
Add a ProcessUtility hook to track utility statements' wait events
2 parents1b714f4 +970e1c1 commitc7507a0

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

‎pg_wait_sampling.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include"storage/shm_mq.h"
2626
#include"storage/shm_toc.h"
2727
#include"storage/spin.h"
28+
#include"tcop/utility.h"
2829
#include"utils/builtins.h"
2930
#include"utils/datetime.h"
3031
#include"utils/guc_tables.h"
@@ -47,6 +48,7 @@ static ExecutorRun_hook_type prev_ExecutorRun = NULL;
4748
staticExecutorFinish_hook_typeprev_ExecutorFinish=NULL;
4849
staticExecutorEnd_hook_typeprev_ExecutorEnd=NULL;
4950
staticplanner_hook_typeplanner_hook_next=NULL;
51+
staticProcessUtility_hook_typeprev_ProcessUtility=NULL;
5052

5153
/* Current nesting depth of planner/Executor calls */
5254
staticintnesting_level=0;
@@ -77,6 +79,21 @@ static void pgws_ExecutorRun(QueryDesc *queryDesc,
7779
uint64count,boolexecute_once);
7880
staticvoidpgws_ExecutorFinish(QueryDesc*queryDesc);
7981
staticvoidpgws_ExecutorEnd(QueryDesc*queryDesc);
82+
staticvoidpgws_ProcessUtility(PlannedStmt*pstmt,
83+
constchar*queryString,
84+
#ifPG_VERSION_NUM >=140000
85+
boolreadOnlyTree,
86+
#endif
87+
ProcessUtilityContextcontext,
88+
ParamListInfoparams,
89+
QueryEnvironment*queryEnv,
90+
DestReceiver*dest,
91+
#ifPG_VERSION_NUM >=130000
92+
QueryCompletion*qc
93+
#else
94+
char*completionTag
95+
#endif
96+
);
8097

8198
/*
8299
* Calculate max processes count.
@@ -424,6 +441,8 @@ _PG_init(void)
424441
ExecutorFinish_hook=pgws_ExecutorFinish;
425442
prev_ExecutorEnd=ExecutorEnd_hook;
426443
ExecutorEnd_hook=pgws_ExecutorEnd;
444+
prev_ProcessUtility=ProcessUtility_hook;
445+
ProcessUtility_hook=pgws_ProcessUtility;
427446
}
428447

429448
/*
@@ -1024,3 +1043,68 @@ pgws_ExecutorEnd(QueryDesc *queryDesc)
10241043
else
10251044
standard_ExecutorEnd(queryDesc);
10261045
}
1046+
1047+
staticvoid
1048+
pgws_ProcessUtility(PlannedStmt*pstmt,
1049+
constchar*queryString,
1050+
#ifPG_VERSION_NUM >=140000
1051+
boolreadOnlyTree,
1052+
#endif
1053+
ProcessUtilityContextcontext,
1054+
ParamListInfoparams,
1055+
QueryEnvironment*queryEnv,
1056+
DestReceiver*dest,
1057+
#ifPG_VERSION_NUM >=130000
1058+
QueryCompletion*qc
1059+
#else
1060+
char*completionTag
1061+
#endif
1062+
)
1063+
{
1064+
inti=MyProc-ProcGlobal->allProcs;
1065+
1066+
if (nesting_level==0)
1067+
pgws_proc_queryids[i]=pstmt->queryId;
1068+
1069+
nesting_level++;
1070+
PG_TRY();
1071+
{
1072+
if (prev_ProcessUtility)
1073+
prev_ProcessUtility (pstmt,queryString,
1074+
#ifPG_VERSION_NUM >=140000
1075+
readOnlyTree,
1076+
#endif
1077+
context,params,queryEnv,
1078+
dest,
1079+
#ifPG_VERSION_NUM >=130000
1080+
qc
1081+
#else
1082+
completionTag
1083+
#endif
1084+
);
1085+
else
1086+
standard_ProcessUtility(pstmt,queryString,
1087+
#ifPG_VERSION_NUM >=140000
1088+
readOnlyTree,
1089+
#endif
1090+
context,params,queryEnv,
1091+
dest,
1092+
#ifPG_VERSION_NUM >=130000
1093+
qc
1094+
#else
1095+
completionTag
1096+
#endif
1097+
);
1098+
nesting_level--;
1099+
if (nesting_level==0)
1100+
pgws_proc_queryids[i]=UINT64CONST(0);
1101+
}
1102+
PG_CATCH();
1103+
{
1104+
nesting_level--;
1105+
if (nesting_level==0)
1106+
pgws_proc_queryids[i]=UINT64CONST(0);
1107+
PG_RE_THROW();
1108+
}
1109+
PG_END_TRY();
1110+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp