PG-586: pg_stat_monitor: CPU and user timing should be captured
for utility statements as well Added the necessary capture of resource usage in the process utility function. We are now storing CPU and user timings for a utility statement.pull/367/head
parent
ac8800a637
commit
ee18c16149
|
@ -710,6 +710,7 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
|
||||||
* levels of hook all do this.)
|
* levels of hook all do this.)
|
||||||
*/
|
*/
|
||||||
InstrEndLoop(queryDesc->totaltime);
|
InstrEndLoop(queryDesc->totaltime);
|
||||||
|
|
||||||
if (getrusage(RUSAGE_SELF, &rusage_end) != 0)
|
if (getrusage(RUSAGE_SELF, &rusage_end) != 0)
|
||||||
elog(DEBUG1, "pg_stat_monitor: failed to execute getrusage");
|
elog(DEBUG1, "pg_stat_monitor: failed to execute getrusage");
|
||||||
|
|
||||||
|
@ -932,6 +933,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
||||||
{
|
{
|
||||||
Node *parsetree = pstmt->utilityStmt;
|
Node *parsetree = pstmt->utilityStmt;
|
||||||
uint64 queryId = 0;
|
uint64 queryId = 0;
|
||||||
|
SysInfo sys_info;
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 140000
|
#if PG_VERSION_NUM >= 140000
|
||||||
queryId = pstmt->queryId;
|
queryId = pstmt->queryId;
|
||||||
|
@ -975,8 +977,13 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
||||||
WalUsage walusage;
|
WalUsage walusage;
|
||||||
WalUsage walusage_start = pgWalUsage;
|
WalUsage walusage_start = pgWalUsage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (getrusage(RUSAGE_SELF, &rusage_start) != 0)
|
||||||
|
elog(DEBUG1, "pg_stat_monitor: failed to execute getrusage");
|
||||||
|
|
||||||
INSTR_TIME_SET_CURRENT(start);
|
INSTR_TIME_SET_CURRENT(start);
|
||||||
exec_nested_level++;
|
exec_nested_level++;
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
#if PG_VERSION_NUM >= 140000
|
#if PG_VERSION_NUM >= 140000
|
||||||
|
@ -1024,6 +1031,13 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
||||||
}
|
}
|
||||||
|
|
||||||
PG_END_TRY();
|
PG_END_TRY();
|
||||||
|
|
||||||
|
if (getrusage(RUSAGE_SELF, &rusage_end) != 0)
|
||||||
|
elog(DEBUG1, "pg_stat_monitor: failed to execute getrusage");
|
||||||
|
|
||||||
|
sys_info.utime = time_diff(rusage_end.ru_utime, rusage_start.ru_utime);
|
||||||
|
sys_info.stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime);
|
||||||
|
|
||||||
INSTR_TIME_SET_CURRENT(duration);
|
INSTR_TIME_SET_CURRENT(duration);
|
||||||
INSTR_TIME_SUBTRACT(duration, start);
|
INSTR_TIME_SUBTRACT(duration, start);
|
||||||
|
|
||||||
|
@ -1059,7 +1073,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
|
||||||
pstmt->stmt_len, /* query length */
|
pstmt->stmt_len, /* query length */
|
||||||
NULL, /* PlanInfo */
|
NULL, /* PlanInfo */
|
||||||
0, /* CmdType */
|
0, /* CmdType */
|
||||||
NULL, /* SysInfo */
|
&sys_info, /* SysInfo */
|
||||||
NULL, /* ErrorInfo */
|
NULL, /* ErrorInfo */
|
||||||
INSTR_TIME_GET_MILLISEC(duration), /* total_time */
|
INSTR_TIME_GET_MILLISEC(duration), /* total_time */
|
||||||
rows, /* rows */
|
rows, /* rows */
|
||||||
|
|
Loading…
Reference in New Issue