aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-04-30 14:02:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-04-30 14:03:33 -0400
commit809e7e21af8cd24855f1802524a13bbaa823f929 (patch)
tree450387adf177bd65f21de4c29d6428852608a8b4 /src/backend/utils/adt/pgstatfuncs.c
parent26471a51fc833e2ce58a2f16f891256d57dd28c6 (diff)
downloadpostgresql-809e7e21af8cd24855f1802524a13bbaa823f929.tar.gz
postgresql-809e7e21af8cd24855f1802524a13bbaa823f929.zip
Converge all SQL-level statistics timing values to float8 milliseconds.
This patch adjusts the core statistics views to match the decision already taken for pg_stat_statements, that values representing elapsed time should be represented as float8 and measured in milliseconds. By using float8, we are no longer tied to a specific maximum precision of timing data. (Internally, it's still microseconds, but we could now change that without needing changes at the SQL level.) The columns affected are pg_stat_bgwriter.checkpoint_write_time pg_stat_bgwriter.checkpoint_sync_time pg_stat_database.blk_read_time pg_stat_database.blk_write_time pg_stat_user_functions.total_time pg_stat_user_functions.self_time pg_stat_xact_user_functions.total_time pg_stat_xact_user_functions.self_time The first four of these are new in 9.2, so there is no compatibility issue from changing them. The others require a release note comment that they are now double precision (and can show a fractional part) rather than bigint as before; also their underlying statistics functions now match the column definitions, instead of returning bigint microseconds.
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 0be55e007ca..83d0c229917 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -45,7 +45,7 @@ extern Datum pg_stat_get_analyze_count(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS);
-extern Datum pg_stat_get_function_time(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_function_total_time(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_function_self_time(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS);
@@ -108,7 +108,7 @@ extern Datum pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS);
-extern Datum pg_stat_get_xact_function_time(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS);
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
@@ -439,14 +439,15 @@ pg_stat_get_function_calls(PG_FUNCTION_ARGS)
}
Datum
-pg_stat_get_function_time(PG_FUNCTION_ARGS)
+pg_stat_get_function_total_time(PG_FUNCTION_ARGS)
{
Oid funcid = PG_GETARG_OID(0);
PgStat_StatFuncEntry *funcentry;
if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
PG_RETURN_NULL();
- PG_RETURN_INT64(funcentry->f_time);
+ /* convert counter from microsec to millisec for display */
+ PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
}
Datum
@@ -457,7 +458,8 @@ pg_stat_get_function_self_time(PG_FUNCTION_ARGS)
if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
PG_RETURN_NULL();
- PG_RETURN_INT64(funcentry->f_time_self);
+ /* convert counter from microsec to millisec for display */
+ PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
}
Datum
@@ -1365,30 +1367,32 @@ Datum
pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
- int64 result;
+ double result;
PgStat_StatDBEntry *dbentry;
+ /* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
- result = (int64) (dbentry->n_block_read_time);
+ result = ((double) dbentry->n_block_read_time) / 1000.0;
- PG_RETURN_INT64(result);
+ PG_RETURN_FLOAT8(result);
}
Datum
pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
{
Oid dbid = PG_GETARG_OID(0);
- int64 result;
+ double result;
PgStat_StatDBEntry *dbentry;
+ /* convert counter from microsec to millisec for display */
if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
result = 0;
else
- result = (int64) (dbentry->n_block_write_time);
+ result = ((double) dbentry->n_block_write_time) / 1000.0;
- PG_RETURN_INT64(result);
+ PG_RETURN_FLOAT8(result);
}
Datum
@@ -1424,13 +1428,15 @@ pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
Datum
pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
{
- PG_RETURN_INT64(pgstat_fetch_global()->checkpoint_write_time);
+ /* time is already in msec, just convert to double for presentation */
+ PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
}
Datum
pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
{
- PG_RETURN_INT64(pgstat_fetch_global()->checkpoint_sync_time);
+ /* time is already in msec, just convert to double for presentation */
+ PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
}
Datum
@@ -1622,14 +1628,14 @@ pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
}
Datum
-pg_stat_get_xact_function_time(PG_FUNCTION_ARGS)
+pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
{
Oid funcid = PG_GETARG_OID(0);
PgStat_BackendFunctionEntry *funcentry;
if ((funcentry = find_funcstat_entry(funcid)) == NULL)
PG_RETURN_NULL();
- PG_RETURN_INT64(INSTR_TIME_GET_MICROSEC(funcentry->f_counts.f_time));
+ PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_total_time));
}
Datum
@@ -1640,7 +1646,7 @@ pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
if ((funcentry = find_funcstat_entry(funcid)) == NULL)
PG_RETURN_NULL();
- PG_RETURN_INT64(INSTR_TIME_GET_MICROSEC(funcentry->f_counts.f_time_self));
+ PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_self_time));
}