On Wed, Jan 29, 2014 at 10:38 PM, Michael Paquier
<michael.paqu...@gmail.com> wrote:
> On Sat, Jan 25, 2014 at 5:41 AM, Fujii Masao <masao.fu...@gmail.com> wrote:
>> I think that it's time to rename all the variables related to 
>> pg_stat_bgwriter.
>> For example, it's better to change PgStat_GlobalStats to PgStat_Bgwriter.
>> I think that it's okay to make this change as separate patch, though.
> Please find attached a simple patch renaming PgStat_GlobalStats to
> PgStat_BgWriterStats.
And of course I forgot the patch... Now attached.
-- 
Michael
*** a/src/backend/postmaster/pgstat.c
--- b/src/backend/postmaster/pgstat.c
***************
*** 221,228 **** static int	localNumBackends = 0;
   * Contains statistics that are not collected per database
   * or per table.
   */
  static PgStat_ArchiverStats archiverStats;
! static PgStat_GlobalStats globalStats;
  
  /* Write request info for each database */
  typedef struct DBWriteRequest
--- 221,229 ----
   * Contains statistics that are not collected per database
   * or per table.
   */
+ static TimestampTz global_stat_timestamp;
  static PgStat_ArchiverStats archiverStats;
! static PgStat_BgWriterStats bgwriterStats;
  
  /* Write request info for each database */
  typedef struct DBWriteRequest
***************
*** 2344,2361 **** pgstat_fetch_stat_archiver(void)
  
  /*
   * ---------
!  * pgstat_fetch_global() -
   *
   *	Support function for the SQL-callable pgstat* functions. Returns
!  *	a pointer to the global statistics struct.
   * ---------
   */
! PgStat_GlobalStats *
! pgstat_fetch_global(void)
  {
  	backend_read_statsfile();
  
! 	return &globalStats;
  }
  
  
--- 2345,2362 ----
  
  /*
   * ---------
!  * pgstat_fetch_stat_bgwriter() -
   *
   *	Support function for the SQL-callable pgstat* functions. Returns
!  *	a pointer to the bgwriter statistics struct.
   * ---------
   */
! PgStat_BgWriterStats *
! pgstat_fetch_stat_bgwriter(void)
  {
  	backend_read_statsfile();
  
! 	return &bgwriterStats;
  }
  
  
***************
*** 3594,3600 **** pgstat_write_statsfiles(bool permanent, bool allDbs)
  	/*
  	 * Set the timestamp of the stats file.
  	 */
! 	globalStats.stats_timestamp = GetCurrentTimestamp();
  
  	/*
  	 * Write the file header --- currently just a format ID.
--- 3595,3601 ----
  	/*
  	 * Set the timestamp of the stats file.
  	 */
! 	global_stat_timestamp = GetCurrentTimestamp();
  
  	/*
  	 * Write the file header --- currently just a format ID.
***************
*** 3604,3612 **** pgstat_write_statsfiles(bool permanent, bool allDbs)
  	(void) rc;					/* we'll check for error with ferror */
  
  	/*
! 	 * Write global stats struct
  	 */
! 	rc = fwrite(&globalStats, sizeof(globalStats), 1, fpout);
  	(void) rc;					/* we'll check for error with ferror */
  
  	/*
--- 3605,3613 ----
  	(void) rc;					/* we'll check for error with ferror */
  
  	/*
! 	 * Write bgwriter stats struct
  	 */
! 	rc = fwrite(&bgwriterStats, sizeof(bgwriterStats), 1, fpout);
  	(void) rc;					/* we'll check for error with ferror */
  
  	/*
***************
*** 3630,3636 **** pgstat_write_statsfiles(bool permanent, bool allDbs)
  		 */
  		if (allDbs || pgstat_db_requested(dbentry->databaseid))
  		{
! 			dbentry->stats_timestamp = globalStats.stats_timestamp;
  			pgstat_write_db_statsfile(dbentry, permanent);
  		}
  
--- 3631,3637 ----
  		 */
  		if (allDbs || pgstat_db_requested(dbentry->databaseid))
  		{
! 			dbentry->stats_timestamp = global_stat_timestamp;
  			pgstat_write_db_statsfile(dbentry, permanent);
  		}
  
***************
*** 3881,3898 **** pgstat_read_statsfiles(Oid onlydb, bool permanent, bool deep)
  						 HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
  
  	/*
! 	 * Clear out global and archiver statistics so they start from zero
  	 * in case we can't load an existing statsfile.
  	 */
! 	memset(&globalStats, 0, sizeof(globalStats));
  	memset(&archiverStats, 0, sizeof(archiverStats));
  
  	/*
  	 * Set the current timestamp (will be kept only in case we can't load an
  	 * existing statsfile).
  	 */
! 	globalStats.stat_reset_timestamp = GetCurrentTimestamp();
! 	archiverStats.stat_reset_timestamp = globalStats.stat_reset_timestamp;
  
  	/*
  	 * Try to open the stats file. If it doesn't exist, the backends simply
--- 3882,3899 ----
  						 HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
  
  	/*
! 	 * Clear out bgwriter and archiver statistics so they start from zero
  	 * in case we can't load an existing statsfile.
  	 */
! 	memset(&bgwriterStats, 0, sizeof(bgwriterStats));
  	memset(&archiverStats, 0, sizeof(archiverStats));
  
  	/*
  	 * Set the current timestamp (will be kept only in case we can't load an
  	 * existing statsfile).
  	 */
! 	bgwriterStats.stat_reset_timestamp = GetCurrentTimestamp();
! 	archiverStats.stat_reset_timestamp = bgwriterStats.stat_reset_timestamp;
  
  	/*
  	 * Try to open the stats file. If it doesn't exist, the backends simply
***************
*** 3925,3933 **** pgstat_read_statsfiles(Oid onlydb, bool permanent, bool deep)
  	}
  
  	/*
! 	 * Read global stats struct
  	 */
! 	if (fread(&globalStats, 1, sizeof(globalStats), fpin) != sizeof(globalStats))
  	{
  		ereport(pgStatRunningInCollector ? LOG : WARNING,
  				(errmsg("corrupted statistics file \"%s\"", statfile)));
--- 3926,3934 ----
  	}
  
  	/*
! 	 * Read bgwriter stats struct
  	 */
! 	if (fread(&bgwriterStats, 1, sizeof(bgwriterStats), fpin) != sizeof(bgwriterStats))
  	{
  		ereport(pgStatRunningInCollector ? LOG : WARNING,
  				(errmsg("corrupted statistics file \"%s\"", statfile)));
***************
*** 4233,4239 **** pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent,
  								   TimestampTz *ts)
  {
  	PgStat_StatDBEntry dbentry;
! 	PgStat_GlobalStats myGlobalStats;
  	PgStat_ArchiverStats myArchiverStats;
  	FILE	   *fpin;
  	int32		format_id;
--- 4234,4240 ----
  								   TimestampTz *ts)
  {
  	PgStat_StatDBEntry dbentry;
! 	PgStat_BgWriterStats myBgWriterStats;
  	PgStat_ArchiverStats myArchiverStats;
  	FILE	   *fpin;
  	int32		format_id;
***************
*** 4266,4275 **** pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent,
  	}
  
  	/*
! 	 * Read global stats struct
  	 */
! 	if (fread(&myGlobalStats, 1, sizeof(myGlobalStats),
! 			  fpin) != sizeof(myGlobalStats))
  	{
  		ereport(pgStatRunningInCollector ? LOG : WARNING,
  				(errmsg("corrupted statistics file \"%s\"", statfile)));
--- 4267,4276 ----
  	}
  
  	/*
! 	 * Read bgwriter stats struct
  	 */
! 	if (fread(&myBgWriterStats, 1, sizeof(myBgWriterStats),
! 			  fpin) != sizeof(myBgWriterStats))
  	{
  		ereport(pgStatRunningInCollector ? LOG : WARNING,
  				(errmsg("corrupted statistics file \"%s\"", statfile)));
***************
*** 4290,4296 **** pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent,
  	}
  
  	/* By default, we're going to return the timestamp of the global file. */
! 	*ts = myGlobalStats.stats_timestamp;
  
  	/*
  	 * We found an existing collector stats file.  Read it and look for a
--- 4291,4297 ----
  	}
  
  	/* By default, we're going to return the timestamp of the global file. */
! 	*ts = global_stat_timestamp;
  
  	/*
  	 * We found an existing collector stats file.  Read it and look for a
***************
*** 4812,4820 **** pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
  {
  	if (msg->m_resettarget == RESET_BGWRITER)
  	{
! 		/* Reset the global background writer statistics for the cluster. */
! 		memset(&globalStats, 0, sizeof(globalStats));
! 		globalStats.stat_reset_timestamp = GetCurrentTimestamp();
  	}
  	else if (msg->m_resettarget == RESET_ARCHIVER)
  	{
--- 4813,4821 ----
  {
  	if (msg->m_resettarget == RESET_BGWRITER)
  	{
! 		/* Reset the background writer statistics for the cluster. */
! 		memset(&bgwriterStats, 0, sizeof(bgwriterStats));
! 		bgwriterStats.stat_reset_timestamp = GetCurrentTimestamp();
  	}
  	else if (msg->m_resettarget == RESET_ARCHIVER)
  	{
***************
*** 4987,5002 **** pgstat_recv_archiver(PgStat_MsgArchiver *msg, int len)
  static void
  pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len)
  {
! 	globalStats.timed_checkpoints += msg->m_timed_checkpoints;
! 	globalStats.requested_checkpoints += msg->m_requested_checkpoints;
! 	globalStats.checkpoint_write_time += msg->m_checkpoint_write_time;
! 	globalStats.checkpoint_sync_time += msg->m_checkpoint_sync_time;
! 	globalStats.buf_written_checkpoints += msg->m_buf_written_checkpoints;
! 	globalStats.buf_written_clean += msg->m_buf_written_clean;
! 	globalStats.maxwritten_clean += msg->m_maxwritten_clean;
! 	globalStats.buf_written_backend += msg->m_buf_written_backend;
! 	globalStats.buf_fsync_backend += msg->m_buf_fsync_backend;
! 	globalStats.buf_alloc += msg->m_buf_alloc;
  }
  
  /* ----------
--- 4988,5003 ----
  static void
  pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len)
  {
! 	bgwriterStats.timed_checkpoints += msg->m_timed_checkpoints;
! 	bgwriterStats.requested_checkpoints += msg->m_requested_checkpoints;
! 	bgwriterStats.checkpoint_write_time += msg->m_checkpoint_write_time;
! 	bgwriterStats.checkpoint_sync_time += msg->m_checkpoint_sync_time;
! 	bgwriterStats.buf_written_checkpoints += msg->m_buf_written_checkpoints;
! 	bgwriterStats.buf_written_clean += msg->m_buf_written_clean;
! 	bgwriterStats.maxwritten_clean += msg->m_maxwritten_clean;
! 	bgwriterStats.buf_written_backend += msg->m_buf_written_backend;
! 	bgwriterStats.buf_fsync_backend += msg->m_buf_fsync_backend;
! 	bgwriterStats.buf_alloc += msg->m_buf_alloc;
  }
  
  /* ----------
*** a/src/backend/utils/adt/pgstatfuncs.c
--- b/src/backend/utils/adt/pgstatfuncs.c
***************
*** 1412,1480 **** pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
  Datum
  pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->buf_written_clean);
  }
  
  Datum
  pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_clean);
  }
  
  Datum
  pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
  {
  	/* 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)
  {
  	/* time is already in msec, just convert to double for presentation */
! 	PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
  }
  
  Datum
  pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_TIMESTAMPTZ(pgstat_fetch_global()->stat_reset_timestamp);
  }
  
  Datum
  pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->buf_written_backend);
  }
  
  Datum
  pg_stat_get_buf_fsync_backend(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->buf_fsync_backend);
  }
  
  Datum
  pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
  }
  
  Datum
--- 1412,1480 ----
  Datum
  pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->timed_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->requested_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_checkpoints);
  }
  
  Datum
  pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_clean);
  }
  
  Datum
  pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->maxwritten_clean);
  }
  
  Datum
  pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
  {
  	/* time is already in msec, just convert to double for presentation */
! 	PG_RETURN_FLOAT8((double) pgstat_fetch_stat_bgwriter()->checkpoint_write_time);
  }
  
  Datum
  pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
  {
  	/* time is already in msec, just convert to double for presentation */
! 	PG_RETURN_FLOAT8((double) pgstat_fetch_stat_bgwriter()->checkpoint_sync_time);
  }
  
  Datum
  pg_stat_get_bgwriter_stat_reset_time(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_TIMESTAMPTZ(pgstat_fetch_stat_bgwriter()->stat_reset_timestamp);
  }
  
  Datum
  pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_written_backend);
  }
  
  Datum
  pg_stat_get_buf_fsync_backend(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_fsync_backend);
  }
  
  Datum
  pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
  {
! 	PG_RETURN_INT64(pgstat_fetch_stat_bgwriter()->buf_alloc);
  }
  
  Datum
*** a/src/include/pgstat.h
--- b/src/include/pgstat.h
***************
*** 642,652 **** typedef struct PgStat_ArchiverStats
  } PgStat_ArchiverStats;
  
  /*
!  * Global statistics kept in the stats collector
   */
! typedef struct PgStat_GlobalStats
  {
- 	TimestampTz stats_timestamp;	/* time of stats file update */
  	PgStat_Counter timed_checkpoints;
  	PgStat_Counter requested_checkpoints;
  	PgStat_Counter checkpoint_write_time;		/* times in milliseconds */
--- 642,651 ----
  } PgStat_ArchiverStats;
  
  /*
!  * BgWriter statistics kept in the stats collector
   */
! typedef struct PgStat_BgWriterStats
  {
  	PgStat_Counter timed_checkpoints;
  	PgStat_Counter requested_checkpoints;
  	PgStat_Counter checkpoint_write_time;		/* times in milliseconds */
***************
*** 658,664 **** typedef struct PgStat_GlobalStats
  	PgStat_Counter buf_fsync_backend;
  	PgStat_Counter buf_alloc;
  	TimestampTz stat_reset_timestamp;
! } PgStat_GlobalStats;
  
  
  /* ----------
--- 657,663 ----
  	PgStat_Counter buf_fsync_backend;
  	PgStat_Counter buf_alloc;
  	TimestampTz stat_reset_timestamp;
! } PgStat_BgWriterStats;
  
  
  /* ----------
***************
*** 907,912 **** extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
  extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
  extern int	pgstat_fetch_stat_numbackends(void);
  extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
! extern PgStat_GlobalStats *pgstat_fetch_global(void);
  
  #endif   /* PGSTAT_H */
--- 906,911 ----
  extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
  extern int	pgstat_fetch_stat_numbackends(void);
  extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
! extern PgStat_BgWriterStats *pgstat_fetch_stat_bgwriter(void);
  
  #endif   /* PGSTAT_H */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to