diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-06-20 22:52:00 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-06-20 22:52:00 +0000 |
commit | 27c3e3de0939d93ae8adb50ab7e00c4a5ff2fa0d (patch) | |
tree | 49a0c81851952447af7bcace3f37e1d7b77c4854 /src/backend/utils | |
parent | 47a37aeebdbeb5c242141830586e065256a0aaf6 (diff) | |
download | postgresql-27c3e3de0939d93ae8adb50ab7e00c4a5ff2fa0d.tar.gz postgresql-27c3e3de0939d93ae8adb50ab7e00c4a5ff2fa0d.zip |
Remove redundant gettimeofday() calls to the extent practical without
changing semantics too much. statement_timestamp is now set immediately
upon receipt of a client command message, and the various places that used
to do their own gettimeofday() calls to mark command startup are referenced
to that instead. I have also made stats_command_string use that same
value for pg_stat_activity.query_start for both the command itself and
its eventual replacement by <IDLE> or <idle in transaction>. There was
some debate about that, but no argument that seemed convincing enough to
justify an extra gettimeofday() call.
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 56 | ||||
-rw-r--r-- | src/backend/utils/error/elog.c | 9 | ||||
-rw-r--r-- | src/backend/utils/mmgr/portalmem.c | 4 |
3 files changed, 61 insertions, 8 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index fd40c1ebfdd..f4f23c9dd31 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.163 2006/04/25 00:25:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.164 2006/06/20 22:52:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -963,6 +963,39 @@ GetCurrentTimestamp(void) return result; } +/* + * TimestampDifference -- convert the difference between two timestamps + * into integer seconds and microseconds + * + * Both inputs must be ordinary finite timestamps (in current usage, + * they'll be results from GetCurrentTimestamp()). + * + * We expect start_time <= stop_time. If not, we return zeroes; for current + * callers there is no need to be tense about which way division rounds on + * negative inputs. + */ +void +TimestampDifference(TimestampTz start_time, TimestampTz stop_time, + long *secs, int *microsecs) +{ + TimestampTz diff = stop_time - start_time; + + if (diff <= 0) + { + *secs = 0; + *microsecs = 0; + } + else + { +#ifdef HAVE_INT64_TIMESTAMP + *secs = (long) (diff / USECS_PER_SEC); + *microsecs = (int) (diff % USECS_PER_SEC); +#else + *secs = (long) diff; + *microsecs = (int) ((diff - *secs) * 1000000.0); +#endif + } +} /* * Convert a time_t to TimestampTz. @@ -985,6 +1018,27 @@ time_t_to_timestamptz(time_t tm) return result; } +/* + * Convert a TimestampTz to time_t. + * + * This too is just marginally useful, but some places need it. + */ +time_t +timestamptz_to_time_t(TimestampTz t) +{ + time_t result; + +#ifdef HAVE_INT64_TIMESTAMP + result = (time_t) (t / USECS_PER_SEC + + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); +#else + result = (time_t) (t + + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); +#endif + + return result; +} + void dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index e0f3c9d8868..54db791f613 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -42,7 +42,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.169 2006/03/05 15:58:46 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.170 2006/06/20 22:52:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1408,7 +1408,7 @@ log_line_prefix(StringInfo buf) if (MyProcPort) { appendStringInfo(buf, "%lx.%x", - (long) (MyProcPort->session_start.tv_sec), + (long) (MyProcPort->session_start), MyProcPid); } break; @@ -1440,7 +1440,7 @@ log_line_prefix(StringInfo buf) strftime(strfbuf, sizeof(strfbuf), /* leave room for milliseconds... */ - /* Win32 timezone names are too long so don't print them. */ + /* Win32 timezone names are too long so don't print them */ #ifndef WIN32 "%Y-%m-%d %H:%M:%S %Z", #else @@ -1474,12 +1474,11 @@ log_line_prefix(StringInfo buf) case 's': if (MyProcPort) { - time_t stamp_time = MyProcPort->session_start.tv_sec; char strfbuf[128]; strftime(strfbuf, sizeof(strfbuf), "%Y-%m-%d %H:%M:%S %Z", - localtime(&stamp_time)); + localtime(&MyProcPort->session_start)); appendStringInfoString(buf, strfbuf); } break; diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 9af7a5f0d86..a32cad08d30 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.87 2006/04/25 14:11:58 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.88 2006/06/20 22:52:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -202,7 +202,7 @@ CreatePortal(const char *name, bool allowDup, bool dupSilent) portal->atStart = true; portal->atEnd = true; /* disallow fetches until query is set */ portal->visible = true; - portal->creation_time = GetCurrentTimestamp(); + portal->creation_time = GetCurrentStatementStartTimestamp(); /* put portal in table (sets portal->name) */ PortalHashTableInsert(portal, name); |