@ -1365,38 +1365,20 @@ pg_stat_us_to_ms(PgStat_Counter val_ms)
return val_ms * ( double ) 0.001 ;
return val_ms * ( double ) 0.001 ;
}
}
Datum
/*
pg_stat_get_io ( PG_FUNCTION_ARGS )
* pg_stat_io_build_tuples
*
* Helper routine for pg_stat_get_io ( ) filling a result tuplestore with one
* tuple for each object and each context supported by the caller , based on the
* contents of bktype_stats .
*/
static void
pg_stat_io_build_tuples ( ReturnSetInfo * rsinfo ,
PgStat_BktypeIO * bktype_stats ,
BackendType bktype ,
TimestampTz stat_reset_timestamp )
{
{
ReturnSetInfo * rsinfo ;
PgStat_IO * backends_io_stats ;
Datum reset_time ;
InitMaterializedSRF ( fcinfo , 0 ) ;
rsinfo = ( ReturnSetInfo * ) fcinfo - > resultinfo ;
backends_io_stats = pgstat_fetch_stat_io ( ) ;
reset_time = TimestampTzGetDatum ( backends_io_stats - > stat_reset_timestamp ) ;
for ( int bktype = 0 ; bktype < BACKEND_NUM_TYPES ; bktype + + )
{
Datum bktype_desc = CStringGetTextDatum ( GetBackendTypeDesc ( bktype ) ) ;
Datum bktype_desc = CStringGetTextDatum ( GetBackendTypeDesc ( bktype ) ) ;
PgStat_BktypeIO * bktype_stats = & backends_io_stats - > stats [ bktype ] ;
/*
* In Assert builds , we can afford an extra loop through all of the
* counters checking that only expected stats are non - zero , since it
* keeps the non - Assert code cleaner .
*/
Assert ( pgstat_bktype_io_stats_valid ( bktype_stats , bktype ) ) ;
/*
* For those BackendTypes without IO Operation stats , skip
* representing them in the view altogether .
*/
if ( ! pgstat_tracks_io_bktype ( bktype ) )
continue ;
for ( int io_obj = 0 ; io_obj < IOOBJECT_NUM_TYPES ; io_obj + + )
for ( int io_obj = 0 ; io_obj < IOOBJECT_NUM_TYPES ; io_obj + + )
{
{
@ -1410,9 +1392,9 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
bool nulls [ IO_NUM_COLUMNS ] = { 0 } ;
bool nulls [ IO_NUM_COLUMNS ] = { 0 } ;
/*
/*
* Some combinations of BackendType , IOObject , and IOContext
* Some combinations of BackendType , IOObject , and IOContext are
* are not valid for any type of IOOp . In such cases , omit the
* not valid for any type of IOOp . In such cases , omit the entir e
* entire row from the view .
* row from the view .
*/
*/
if ( ! pgstat_tracks_io_object ( bktype , io_obj , io_context ) )
if ( ! pgstat_tracks_io_object ( bktype , io_obj , io_context ) )
continue ;
continue ;
@ -1420,13 +1402,16 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
values [ IO_COL_BACKEND_TYPE ] = bktype_desc ;
values [ IO_COL_BACKEND_TYPE ] = bktype_desc ;
values [ IO_COL_CONTEXT ] = CStringGetTextDatum ( context_name ) ;
values [ IO_COL_CONTEXT ] = CStringGetTextDatum ( context_name ) ;
values [ IO_COL_OBJECT ] = CStringGetTextDatum ( obj_name ) ;
values [ IO_COL_OBJECT ] = CStringGetTextDatum ( obj_name ) ;
values [ IO_COL_RESET_TIME ] = reset_time ;
if ( stat_reset_timestamp ! = 0 )
values [ IO_COL_RESET_TIME ] = TimestampTzGetDatum ( stat_reset_timestamp ) ;
else
nulls [ IO_COL_RESET_TIME ] = true ;
/*
/*
* Hard - code this to the value of BLCKSZ for now . Future
* Hard - code this to the value of BLCKSZ for now . Future values
* values could include XLOG_BLCKSZ , once WAL IO is tracked ,
* could include XLOG_BLCKSZ , once WAL IO is tracked , and constant
* and constant multipliers , once non - block - oriented IO ( e . g .
* multipliers , once non - block - oriented IO ( e . g . temporary file
* temporary file IO ) is tracked .
* IO ) is tracked .
*/
*/
values [ IO_COL_CONVERSION ] = Int64GetDatum ( BLCKSZ ) ;
values [ IO_COL_CONVERSION ] = Int64GetDatum ( BLCKSZ ) ;
@ -1436,9 +1421,9 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
int time_idx = pgstat_get_io_time_index ( io_op ) ;
int time_idx = pgstat_get_io_time_index ( io_op ) ;
/*
/*
* Some combinations of BackendType and IOOp , of IOContext
* Some combinations of BackendType and IOOp , of IOContext and
* and IOOp , and of IOObject and IOOp are not tracked . Set
* IOOp , and of IOObject and IOOp are not tracked . Set these
* these cells in the view NULL .
* cells in the view NULL .
*/
*/
if ( pgstat_tracks_io_op ( bktype , io_obj , io_context , io_op ) )
if ( pgstat_tracks_io_op ( bktype , io_obj , io_context , io_op ) )
{
{
@ -1469,6 +1454,41 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
values , nulls ) ;
values , nulls ) ;
}
}
}
}
}
Datum
pg_stat_get_io ( PG_FUNCTION_ARGS )
{
ReturnSetInfo * rsinfo ;
PgStat_IO * backends_io_stats ;
InitMaterializedSRF ( fcinfo , 0 ) ;
rsinfo = ( ReturnSetInfo * ) fcinfo - > resultinfo ;
backends_io_stats = pgstat_fetch_stat_io ( ) ;
for ( int bktype = 0 ; bktype < BACKEND_NUM_TYPES ; bktype + + )
{
PgStat_BktypeIO * bktype_stats = & backends_io_stats - > stats [ bktype ] ;
/*
* In Assert builds , we can afford an extra loop through all of the
* counters ( in pg_stat_io_build_tuples ( ) ) , checking that only
* expected stats are non - zero , since it keeps the non - Assert code
* cleaner .
*/
Assert ( pgstat_bktype_io_stats_valid ( bktype_stats , bktype ) ) ;
/*
* For those BackendTypes without IO Operation stats , skip
* representing them in the view altogether .
*/
if ( ! pgstat_tracks_io_bktype ( bktype ) )
continue ;
/* save tuples with data from this PgStat_BktypeIO */
pg_stat_io_build_tuples ( rsinfo , bktype_stats , bktype ,
backends_io_stats - > stat_reset_timestamp ) ;
}
}
return ( Datum ) 0 ;
return ( Datum ) 0 ;