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_read_time,
|
||||||
blk_write_time,
|
blk_write_time,
|
||||||
(string_to_array(resp_calls, ',')) resp_calls,
|
(string_to_array(resp_calls, ',')) resp_calls,
|
||||||
cpu_user_time,
|
round(cpu_user_time::numeric, 4) as cpu_user_time,
|
||||||
cpu_sys_time
|
round(cpu_sys_time::numeric, 4) as cpu_sys_time
|
||||||
FROM pg_stat_monitor(TRUE), pg_database WHERE dbid = oid
|
FROM pg_stat_monitor(TRUE), pg_database WHERE dbid = oid
|
||||||
ORDER BY bucket_start_time;
|
ORDER BY bucket_start_time;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
#define BUILD_VERSION "0.7.0"
|
#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"
|
#define PGSM_TEXT_FILE "/tmp/pg_stat_monitor_query"
|
||||||
|
|
||||||
/*---- Initicalization Function Declarations ----*/
|
/*---- Initicalization Function Declarations ----*/
|
||||||
|
@ -46,6 +46,7 @@ static unsigned char *pgss_qbuf[MAX_BUCKETS];
|
||||||
|
|
||||||
static bool IsSystemInitialized(void);
|
static bool IsSystemInitialized(void);
|
||||||
static void dump_queries_buffer(int bucket_id, unsigned char *buf, int buf_len);
|
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 */
|
/* Saved hook values in case of unload */
|
||||||
static planner_hook_type planner_hook_next = NULL;
|
static planner_hook_type planner_hook_next = NULL;
|
||||||
|
@ -314,9 +315,9 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
|
||||||
static void
|
static void
|
||||||
pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
|
pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
|
||||||
{
|
{
|
||||||
|
if(getrusage(RUSAGE_SELF, &rusage_start) != 0)
|
||||||
getrusage(RUSAGE_SELF, &rusage_start);
|
elog(WARNING, "pg_stat_monitor: failed to execute getrusage");
|
||||||
|
|
||||||
if (prev_ExecutorStart)
|
if (prev_ExecutorStart)
|
||||||
prev_ExecutorStart(queryDesc, eflags);
|
prev_ExecutorStart(queryDesc, eflags);
|
||||||
else
|
else
|
||||||
|
@ -410,9 +411,10 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
|
||||||
* levels of hook all do this.)
|
* levels of hook all do this.)
|
||||||
*/
|
*/
|
||||||
InstrEndLoop(queryDesc->totaltime);
|
InstrEndLoop(queryDesc->totaltime);
|
||||||
getrusage(RUSAGE_SELF, &rusage_end);
|
if(getrusage(RUSAGE_SELF, &rusage_end) != 0)
|
||||||
utime = TIMEVAL_DIFF(rusage_start.ru_utime, rusage_end.ru_utime);
|
elog(WARNING, "pg_stat_monitor: failed to execute getrusage");
|
||||||
stime = TIMEVAL_DIFF(rusage_start.ru_stime, rusage_end.ru_stime);
|
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)
|
if (PGSM_ENABLED == 1)
|
||||||
pgss_store(queryId,
|
pgss_store(queryId,
|
||||||
|
@ -2622,3 +2624,13 @@ exit:
|
||||||
return buf_len;
|
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"
|
#include "utils/guc.h"
|
||||||
|
|
||||||
#define MAX_BACKEND_PROCESES (MaxBackends + NUM_AUXILIARY_PROCS + max_prepared_xacts)
|
#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 TextArrayGetTextDatum(x,y) textarray_get_datum(x,y)
|
||||||
#define IntArrayGetTextDatum(x,y) intarray_get_datum(x,y)
|
#define IntArrayGetTextDatum(x,y) intarray_get_datum(x,y)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue