pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Patch for Postmaster Uptime (from the TODO)
3+ messages / 3 participants
[nested] [flat]

* Patch for Postmaster Uptime (from the TODO)
@ 2005-02-24 22:49  Eric Crampton <escpg@eonomine.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Eric Crampton @ 2005-02-24 22:49 UTC (permalink / raw)
  To: pgsql-patches@postgresql.org

Hello hackers,

I noticed in the TODO that there is an item requesting a function which
returns the uptime of the postmaster. I've wanted that as well. So, I've
added just such a thing: server_start_time(). This function returns the
time when the postmaster was started; a simple now() - server_start_time()
returns the uptime.

The below patches are for four files:

* postmaster.c: Now calls a new function, MarkServerStartTime(), before
calling ServerLoop().

* timestamp.h/timestamp.c: New functions: MarkServerStartTime() (called
from postmaster.c) and server_start_time(), a new SQL function which may
be called.

* pg_proc.h: Added DATA and DESCR to the very end of the list (OID=2557)
for the server_start_time function.

I didn't bother to include the generated fmgroids.h and fmgrtab.c. Since
they are small, I've attached the four unified diffs against the 8.0.1
code. Let me know if there's anything different the code should have done.

--Eric

Attachments:

  [application/octet-stream] pg_proc.h.diff (610B, ../../39796.207.171.180.101.1109285340.spork@webmail.eonomine.com/2-pg_proc.h.diff)
  download | inline diff:
--- postgresql-8.0.1/src/include/catalog/pg_proc.h	Fri Dec 31 14:03:25 2004
+++ patched-postgresql-8.0.1/src/include/catalog/pg_proc.h	Thu Feb 24 08:37:57 2005
@@ -3604,6 +3604,9 @@
 DATA(insert OID = 2556 ( pg_tablespace_databases	PGNSP PGUID 12 f f t t s 1 26 "26" _null_ pg_tablespace_databases - _null_));
 DESCR("returns database oids in a tablespace");
 
+DATA(insert OID = 2557 (  server_start_time		   PGNSP PGUID 12 f f t f s 0 1184 "" _null_  server_start_time - _null_ ));
+DESCR("time when the server started");
+
 
 /*
  * Symbolic values for provolatile column: these indicate whether the result


  [application/octet-stream] postmaster.c.diff (338B, ../../39796.207.171.180.101.1109285340.spork@webmail.eonomine.com/3-postmaster.c.diff)
  download | inline diff:
--- postgresql-8.0.1/src/backend/postmaster/postmaster.c	Wed Jan 12 08:38:17 2005
+++ patched-postgresql-8.0.1/src/backend/postmaster/postmaster.c	Thu Feb 24 08:20:46 2005
@@ -915,6 +915,11 @@
 	 */
 	StartupPID = StartupDataBase();
 
+	/*
+	 * Set the server start time.
+	 */
+	MarkServerStartTime();
+	
 	status = ServerLoop();
 
 	/*


  [application/octet-stream] timestamp.c.diff (1.2K, ../../39796.207.171.180.101.1109285340.spork@webmail.eonomine.com/4-timestamp.c.diff)
  download | inline diff:
--- postgresql-8.0.1/src/backend/utils/adt/timestamp.c	Fri Dec 31 14:01:22 2004
+++ patched-postgresql-8.0.1/src/backend/utils/adt/timestamp.c	Thu Feb 24 14:04:12 2005
@@ -50,6 +50,11 @@
 static void AdjustIntervalForTypmod(Interval *interval, int32 typmod);
 static TimestampTz timestamp2timestamptz(Timestamp timestamp);
 
+/*
+ * Set by MarkServerStartTime().
+ */
+static AbsoluteTime serverStartTime = 0;
+static int serverStartTimeUsec = 0;
 
 /*****************************************************************************
  *	 USER I/O ROUTINES														 *
@@ -941,6 +946,28 @@
 	PG_RETURN_TIMESTAMPTZ(result);
 }
 
+/* MarkServerStartTime()
+ * Marks the time of server startup.
+ */
+void
+MarkServerStartTime(void)
+{
+	serverStartTime = GetCurrentAbsoluteTimeUsec(&(serverStartTimeUsec));
+}
+
+/* server_start_time()
+ * Returns the time when the server was started.
+ */
+Datum
+server_start_time(PG_FUNCTION_ARGS)
+{
+	TimestampTz result;
+
+	result = AbsoluteTimeUsecToTimestampTz(serverStartTime, serverStartTimeUsec);
+
+	PG_RETURN_TIMESTAMPTZ(result);
+}
+
 void
 dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
 {
@@ -4002,3 +4029,4 @@
 
 	PG_RETURN_TIMESTAMP(result);
 }	/* timestamptz_izone() */
+


  [application/octet-stream] timestamp.h.diff (411B, ../../39796.207.171.180.101.1109285340.spork@webmail.eonomine.com/5-timestamp.h.diff)
  download | inline diff:
--- postgresql-8.0.1/src/include/utils/timestamp.h	Fri Dec 31 14:03:46 2004
+++ patched-postgresql-8.0.1/src/include/utils/timestamp.h	Thu Feb 24 08:19:46 2005
@@ -248,6 +248,9 @@
 extern Datum timestamptz_part(PG_FUNCTION_ARGS);
 
 extern Datum now(PG_FUNCTION_ARGS);
+extern void MarkServerStartTime(void);
+extern Datum server_start_time(PG_FUNCTION_ARGS);
+
 
 /* Internal routines (not fmgr-callable) */
 


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Patch for Postmaster Uptime (from the TODO)
@ 2005-02-25 01:38  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Eric Crampton <escpg@eonomine.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2005-02-25 01:38 UTC (permalink / raw)
  To: escpg@eonomine.com; +Cc: pgsql-patches@postgresql.org

"Eric Crampton" <escpg@eonomine.com> writes:
> I noticed in the TODO that there is an item requesting a function which
> returns the uptime of the postmaster. I've wanted that as well. So, I've
> added just such a thing: server_start_time(). This function returns the
> time when the postmaster was started; a simple now() - server_start_time()
> returns the uptime.

Isn't there one of these in the patch queue already?

The patch as given won't work on Windows, because it depends on fork
inheritance of the value.  I think the previous patcher fixed that.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Patch for Postmaster Uptime (from the TODO)
@ 2005-02-25 02:48  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Bruce Momjian @ 2005-02-25 02:48 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: escpg@eonomine.com; pgsql-patches@postgresql.org

Tom Lane wrote:
> "Eric Crampton" <escpg@eonomine.com> writes:
> > I noticed in the TODO that there is an item requesting a function which
> > returns the uptime of the postmaster. I've wanted that as well. So, I've
> > added just such a thing: server_start_time(). This function returns the
> > time when the postmaster was started; a simple now() - server_start_time()
> > returns the uptime.
> 
> Isn't there one of these in the patch queue already?

Yes.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-02-25 02:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-24 22:49 Patch for Postmaster Uptime (from the TODO) Eric Crampton <escpg@eonomine.com>
2005-02-25 01:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-02-25 02:48   ` Bruce Momjian <pgman@candle.pha.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox