aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/nabstime.c22
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c46
2 files changed, 60 insertions, 8 deletions
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index 408b1ee14dd..8a75bdffbee 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.104 2003/02/22 05:57:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.105 2003/03/20 03:34:56 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -82,10 +82,13 @@ static int istinterval(char *i_string,
AbsoluteTime *i_end);
-/* GetCurrentAbsoluteTime()
- * Get the current system time.
+/*
+ * GetCurrentAbsoluteTime()
+ *
+ * Get the current system time. Set timezone parameters if not specified
+ * elsewhere. Define HasCTZSet to allow clients to specify the default
+ * timezone.
*
- * Returns the number of seconds since epoch (January 1 1970 GMT).
*/
AbsoluteTime
GetCurrentAbsoluteTime(void)
@@ -127,9 +130,14 @@ GetCurrentDateTime(struct tm * tm)
abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL);
}
-/* GetCurrentTimeUsec()
- * Get the transaction start time ("now()") broken down as a struct tm,
- * plus fractional-second and timezone info.
+/*
+ * GetCurrentAbsoluteTimeUsec()
+ *
+ * Get the current system time. Set timezone parameters if not specified
+ * elsewhere. Define HasCTZSet to allow clients to specify the default
+ * timezone.
+ *
+ * Returns the number of seconds since epoch (January 1 1970 GMT)
*/
void
GetCurrentTimeUsec(struct tm * tm, fsec_t *fsec, int *tzp)
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 42b63b8739f..455da1c2aa9 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -25,6 +25,7 @@ extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS);
@@ -221,7 +222,6 @@ pg_backend_pid(PG_FUNCTION_ARGS)
/*
* Built-in function for resetting the counters
- *
*/
Datum
pg_stat_reset(PG_FUNCTION_ARGS)
@@ -302,6 +302,50 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
Datum
+pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
+{
+ PgStat_StatBeEntry *beentry;
+ int32 beid;
+ AbsoluteTime sec;
+ int usec;
+ Timestamp result;
+
+ beid = PG_GETARG_INT32(0);
+
+ if (!superuser())
+ PG_RETURN_NULL();
+
+ if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+ PG_RETURN_NULL();
+
+ sec = beentry->activity_start_sec;
+ usec = beentry->activity_start_usec;
+
+ /*
+ * No time recorded for start of current query -- this is the case
+ * if the user hasn't enabled query-level stats collection.
+ */
+ if (sec == 0 && usec == 0)
+ PG_RETURN_NULL();
+
+ /*
+ * This method of converting "Unix time" (sec/usec since epoch) to a
+ * PostgreSQL timestamp is an ugly hack -- if you fix it, be sure to
+ * fix the similar hackery in timestamp.c
+ */
+#ifdef HAVE_INT64_TIMESTAMP
+ result = (((sec - ((date2j(2000, 1, 1) - date2j(1970, 1, 1)) * 86400))
+ * INT64CONST(1000000)) + usec);
+#else
+ result = (sec + (usec * 1.0e-6) - ((date2j(2000, 1, 1) -
+ date2j(1970, 1, 1)) * 86400));
+#endif
+
+ PG_RETURN_TIMESTAMP(result);
+}
+
+
+Datum
pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
{
PgStat_StatDBEntry *dbentry;