From 93f94e356d47ea20ca7c2fcb65cbb746049fe4d1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 28 Apr 2012 16:03:57 -0400 Subject: [PATCH] Adjust timing units in pg_stat_statements. Display total time and I/O timings in milliseconds, for consistency with the units used for timings in the core statistics views. The columns remain of float8 type, so that sub-msec precision is available. (At some point we will probably want to convert the core views to use float8 type for the same reason, but this patch does not touch that issue.) This is a release-note-requiring change in the meaning of the total_time column. The I/O timing columns are new as of 9.2, so there is no compatibility impact from redefining them. Do some minor copy-editing in the documentation, too. --- .../pg_stat_statements/pg_stat_statements.c | 16 ++++----- doc/src/sgml/pgstatstatements.sgml | 34 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 5264d14294..6f936b7b26 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -101,7 +101,7 @@ typedef struct pgssHashKey typedef struct Counters { int64 calls; /* # of times executed */ - double total_time; /* total execution time in seconds */ + double total_time; /* total execution time, in msec */ int64 rows; /* total # of retrieved or affected rows */ int64 shared_blks_hit; /* # of shared buffer hits */ int64 shared_blks_read; /* # of shared disk blocks read */ @@ -113,8 +113,8 @@ typedef struct Counters int64 local_blks_written; /* # of local disk blocks written */ int64 temp_blks_read; /* # of temp blocks read */ int64 temp_blks_written; /* # of temp blocks written */ - double time_read; /* time spent reading in seconds */ - double time_write; /* time spent writing in seconds */ + double time_read; /* time spent reading, in msec */ + double time_write; /* time spent writing, in msec */ double usage; /* usage factor */ } Counters; @@ -752,7 +752,7 @@ pgss_ExecutorEnd(QueryDesc *queryDesc) pgss_store(queryDesc->sourceText, queryId, - queryDesc->totaltime->total, + queryDesc->totaltime->total * 1000.0, /* convert to msec */ queryDesc->estate->es_processed, &queryDesc->totaltime->bufusage, NULL); @@ -856,7 +856,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString, pgss_store(queryString, queryId, - INSTR_TIME_GET_DOUBLE(duration), + INSTR_TIME_GET_MILLISEC(duration), rows, &bufusage, NULL); @@ -1021,9 +1021,9 @@ pgss_store(const char *query, uint32 queryId, e->counters.local_blks_written += bufusage->local_blks_written; e->counters.temp_blks_read += bufusage->temp_blks_read; e->counters.temp_blks_written += bufusage->temp_blks_written; - e->counters.time_read += INSTR_TIME_GET_DOUBLE(bufusage->time_read); - e->counters.time_write += INSTR_TIME_GET_DOUBLE(bufusage->time_write); - e->counters.usage += USAGE_EXEC(duration); + e->counters.time_read += INSTR_TIME_GET_MILLISEC(bufusage->time_read); + e->counters.time_write += INSTR_TIME_GET_MILLISEC(bufusage->time_write); + e->counters.usage += USAGE_EXEC(total_time); SpinLockRelease(&e->mutex); } diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml index a6064727fc..1dd42de781 100644 --- a/doc/src/sgml/pgstatstatements.sgml +++ b/doc/src/sgml/pgstatstatements.sgml @@ -75,7 +75,7 @@ total_time double precision - Total time spent in the statement, in seconds + Total time spent in the statement, in milliseconds @@ -89,14 +89,14 @@ shared_blks_hit bigint - Total number of shared blocks hits by the statement + Total number of shared block cache hits by the statement shared_blks_read bigint - Total number of shared blocks reads by the statement + Total number of shared blocks read by the statement @@ -110,21 +110,21 @@ shared_blks_written bigint - Total number of shared blocks writes by the statement + Total number of shared blocks written by the statement local_blks_hit bigint - Total number of local blocks hits by the statement + Total number of local block cache hits by the statement local_blks_read bigint - Total number of local blocks reads by the statement + Total number of local blocks read by the statement @@ -138,21 +138,21 @@ local_blks_written bigint - Total number of local blocks writes by the statement + Total number of local blocks written by the statement temp_blks_read bigint - Total number of temp blocks reads by the statement + Total number of temp blocks read by the statement temp_blks_written bigint - Total number of temp blocks writes by the statement + Total number of temp blocks written by the statement @@ -160,7 +160,7 @@ double precision - Total time the statement spent reading blocks, in seconds + Total time the statement spent reading blocks, in milliseconds (if is enabled, otherwise zero) @@ -170,7 +170,7 @@ double precision - Total time the statement spent writing blocks, in seconds + Total time the statement spent writing blocks, in milliseconds (if is enabled, otherwise zero) @@ -285,7 +285,7 @@ Specify top to track top-level statements (those issued directly by clients), all to also track nested statements (such as statements invoked within functions), or none to - disable. + disable statement statistics collection. The default value is top. Only superusers can change this setting. @@ -366,31 +366,31 @@ bench=# SELECT query, calls, total_time, rows, 100.0 * shared_blks_hit / -[ RECORD 1 ]--------------------------------------------------------------------- query | UPDATE pgbench_branches SET bbalance = bbalance + ? WHERE bid = ?; calls | 3000 -total_time | 9.60900100000002 +total_time | 9609.00100000002 rows | 2836 hit_percent | 99.9778970000200936 -[ RECORD 2 ]--------------------------------------------------------------------- query | UPDATE pgbench_tellers SET tbalance = tbalance + ? WHERE tid = ?; calls | 3000 -total_time | 8.015156 +total_time | 8015.156 rows | 2990 hit_percent | 99.9731126579631345 -[ RECORD 3 ]--------------------------------------------------------------------- query | copy pgbench_accounts from stdin calls | 1 -total_time | 0.310624 +total_time | 310.624 rows | 100000 hit_percent | 0.30395136778115501520 -[ RECORD 4 ]--------------------------------------------------------------------- query | UPDATE pgbench_accounts SET abalance = abalance + ? WHERE aid = ?; calls | 3000 -total_time | 0.271741999999997 +total_time | 271.741999999997 rows | 3000 hit_percent | 93.7968855088209426 -[ RECORD 5 ]--------------------------------------------------------------------- query | alter table pgbench_accounts add primary key (aid) calls | 1 -total_time | 0.08142 +total_time | 81.42 rows | 0 hit_percent | 34.4947735191637631 -- 2.40.0