diff options
| author | Tom Lane | 2006-06-20 22:52:00 +0000 |
|---|---|---|
| committer | Tom Lane | 2006-06-20 22:52:00 +0000 |
| commit | 27c3e3de0939d93ae8adb50ab7e00c4a5ff2fa0d (patch) | |
| tree | 49a0c81851952447af7bcace3f37e1d7b77c4854 /src/backend/postmaster | |
| parent | 47a37aeebdbeb5c242141830586e065256a0aaf6 (diff) | |
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/postmaster')
| -rw-r--r-- | src/backend/postmaster/pgstat.c | 12 | ||||
| -rw-r--r-- | src/backend/postmaster/postmaster.c | 14 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index f6949f14377..a340a91fed2 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.129 2006/06/19 01:51:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.130 2006/06/20 22:52:00 tgl Exp $ * ---------- */ #include "postgres.h" @@ -1368,8 +1368,14 @@ pgstat_bestart(void) /* * To minimize the time spent modifying the entry, fetch all the * needed data first. + * + * If we have a MyProcPort, use its session start time (for consistency, + * and to save a kernel call). */ - proc_start_timestamp = GetCurrentTimestamp(); + if (MyProcPort) + proc_start_timestamp = MyProcPort->SessionStartTime; + else + proc_start_timestamp = GetCurrentTimestamp(); userid = GetSessionUserId(); /* @@ -1464,7 +1470,7 @@ pgstat_report_activity(const char *cmd_str) * To minimize the time spent modifying the entry, fetch all the * needed data first. */ - start_timestamp = GetCurrentTimestamp(); + start_timestamp = GetCurrentStatementStartTimestamp(); len = strlen(cmd_str); len = pg_mbcliplen(cmd_str, len, PGBE_ACTIVITY_SIZE - 1); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index aac116b466a..8164d7e5b03 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.487 2006/06/19 01:51:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.488 2006/06/20 22:52:00 tgl Exp $ * * NOTES * @@ -99,7 +99,6 @@ #include "commands/async.h" #include "lib/dllist.h" #include "libpq/auth.h" -#include "libpq/crypt.h" #include "libpq/libpq.h" #include "libpq/pqcomm.h" #include "libpq/pqsignal.h" @@ -2609,8 +2608,9 @@ BackendInitialize(Port *port) ClientAuthInProgress = true; /* limit visibility of log messages */ - /* save start time for end of session reporting */ - gettimeofday(&(port->session_start), NULL); + /* save process start time */ + port->SessionStartTime = GetCurrentTimestamp(); + port->session_start = timestamptz_to_time_t(port->SessionStartTime); /* set these to empty in case they are needed before we set them up */ port->remote_host = ""; @@ -2749,6 +2749,8 @@ BackendRun(Port *port) char **av; int maxac; int ac; + long secs; + int usecs; char protobuf[32]; int i; @@ -2758,7 +2760,9 @@ BackendRun(Port *port) * a new random sequence in the random() library function. */ random_seed = 0; - srandom((unsigned int) (MyProcPid ^ port->session_start.tv_usec)); + /* slightly hacky way to get integer microseconds part of timestamptz */ + TimestampDifference(0, port->SessionStartTime, &secs, &usecs); + srandom((unsigned int) (MyProcPid ^ usecs)); /* ---------------- * Now, build the argv vector that will be given to PostgresMain. |
