1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

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.
This commit is contained in:
Tom Lane
2012-04-30 14:02:47 -04:00
parent 26471a51fc
commit 809e7e21af
9 changed files with 80 additions and 78 deletions

View File

@ -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));
}