PG-166: Display actual system time instead of null.
parent
0e8f4c489c
commit
412d9bc9b1
|
@ -134,8 +134,8 @@ CREATE VIEW pg_stat_monitor AS SELECT
|
|||
blk_read_time,
|
||||
blk_write_time,
|
||||
(string_to_array(resp_calls, ',')) resp_calls,
|
||||
cpu_user_time,
|
||||
cpu_sys_time
|
||||
round(cpu_user_time::numeric, 4) as cpu_user_time,
|
||||
round(cpu_sys_time::numeric, 4) as cpu_sys_time
|
||||
FROM pg_stat_monitor(TRUE), pg_database WHERE dbid = oid
|
||||
ORDER BY bucket_start_time;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
PG_MODULE_MAGIC;
|
||||
|
||||
#define BUILD_VERSION "0.7.0"
|
||||
#define PG_STAT_STATEMENTS_COLS 41 /* maximum of above */
|
||||
#define PG_STAT_STATEMENTS_COLS 42 /* maximum of above */
|
||||
#define PGSM_TEXT_FILE "/tmp/pg_stat_monitor_query"
|
||||
|
||||
/*---- Initicalization Function Declarations ----*/
|
||||
|
@ -46,6 +46,7 @@ static unsigned char *pgss_qbuf[MAX_BUCKETS];
|
|||
|
||||
static bool IsSystemInitialized(void);
|
||||
static void dump_queries_buffer(int bucket_id, unsigned char *buf, int buf_len);
|
||||
static double time_diff(struct timeval end, struct timeval start);
|
||||
|
||||
/* Saved hook values in case of unload */
|
||||
static planner_hook_type planner_hook_next = NULL;
|
||||
|
@ -314,8 +315,8 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
|
|||
static void
|
||||
pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
|
||||
{
|
||||
|
||||
getrusage(RUSAGE_SELF, &rusage_start);
|
||||
if(getrusage(RUSAGE_SELF, &rusage_start) != 0)
|
||||
elog(WARNING, "pg_stat_monitor: failed to execute getrusage");
|
||||
|
||||
if (prev_ExecutorStart)
|
||||
prev_ExecutorStart(queryDesc, eflags);
|
||||
|
@ -410,9 +411,10 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
|
|||
* levels of hook all do this.)
|
||||
*/
|
||||
InstrEndLoop(queryDesc->totaltime);
|
||||
getrusage(RUSAGE_SELF, &rusage_end);
|
||||
utime = TIMEVAL_DIFF(rusage_start.ru_utime, rusage_end.ru_utime);
|
||||
stime = TIMEVAL_DIFF(rusage_start.ru_stime, rusage_end.ru_stime);
|
||||
if(getrusage(RUSAGE_SELF, &rusage_end) != 0)
|
||||
elog(WARNING, "pg_stat_monitor: failed to execute getrusage");
|
||||
utime = time_diff(rusage_end.ru_utime, rusage_start.ru_utime);
|
||||
stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime);
|
||||
|
||||
if (PGSM_ENABLED == 1)
|
||||
pgss_store(queryId,
|
||||
|
@ -2622,3 +2624,13 @@ exit:
|
|||
return buf_len;
|
||||
}
|
||||
|
||||
static double
|
||||
time_diff(struct timeval end, struct timeval start)
|
||||
{
|
||||
double mstart;
|
||||
double mend;
|
||||
mend = ((double) end.tv_sec * 1000.0 + (double) end.tv_usec / 1000.0);
|
||||
mstart = ((double) start.tv_sec * 1000.0 + (double) start.tv_usec / 1000.0);
|
||||
return mend - mstart;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,11 +54,6 @@
|
|||
#include "utils/guc.h"
|
||||
|
||||
#define MAX_BACKEND_PROCESES (MaxBackends + NUM_AUXILIARY_PROCS + max_prepared_xacts)
|
||||
|
||||
/* Time difference in miliseconds */
|
||||
#define TIMEVAL_DIFF(start, end) (((double) end.tv_sec + (double) end.tv_usec / 1000000.0) \
|
||||
- ((double) start.tv_sec + (double) start.tv_usec / 1000000.0)) * 1000
|
||||
|
||||
#define TextArrayGetTextDatum(x,y) textarray_get_datum(x,y)
|
||||
#define IntArrayGetTextDatum(x,y) intarray_get_datum(x,y)
|
||||
|
||||
|
|
Loading…
Reference in New Issue