*
* Copyright (c) 2001, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.30 2002/10/21 19:59:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.31 2002/10/24 23:19:13 tgl Exp $
* ----------
*/
#include "postgres.h"
*/
if (need_statwrite)
{
- gettimeofday(&timeout, NULL);
- timeout.tv_usec = next_statwrite.tv_usec - timeout.tv_usec;
- timeout.tv_sec = next_statwrite.tv_sec - timeout.tv_sec;
- if (timeout.tv_usec < 0)
- {
- timeout.tv_sec -= 1;
- timeout.tv_usec += 1000000;
- }
- if (timeout.tv_sec < 0)
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ /* avoid assuming that tv_sec is signed */
+ if (now.tv_sec > next_statwrite.tv_sec ||
+ (now.tv_sec == next_statwrite.tv_sec &&
+ now.tv_usec >= next_statwrite.tv_usec))
{
timeout.tv_sec = 0;
timeout.tv_usec = 0;
}
+ else
+ {
+ timeout.tv_sec = next_statwrite.tv_sec - now.tv_sec;
+ timeout.tv_usec = next_statwrite.tv_usec - now.tv_usec;
+ if (timeout.tv_usec < 0)
+ {
+ timeout.tv_sec--;
+ timeout.tv_usec += 1000000;
+ }
+ }
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.305 2002/10/19 20:15:09 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.306 2002/10/24 23:19:13 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
MemoryContext oldcontext;
List *parsetree_list,
*parsetree_item;
- struct timezone tz;
struct timeval start_t,
stop_t;
bool save_Log_duration = Log_duration;
* report incorrect time because gettimeofday() wasn't called.
*/
if (save_Log_duration)
- gettimeofday(&start_t, &tz);
+ gettimeofday(&start_t, NULL);
/*
* Start up a transaction command. All queries generated by the
if (save_Log_duration)
{
- gettimeofday(&stop_t, &tz);
+ gettimeofday(&stop_t, NULL);
if (stop_t.tv_usec < start_t.tv_usec)
{
stop_t.tv_sec--;
stop_t.tv_usec += 1000000;
}
elog(LOG, "duration: %ld.%06ld sec",
- (long int) stop_t.tv_sec - start_t.tv_sec,
- (long int) stop_t.tv_usec - start_t.tv_usec);
+ (long) (stop_t.tv_sec - start_t.tv_sec),
+ (long) (stop_t.tv_usec - start_t.tv_usec));
}
debug_query_string = NULL;
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.305 $ $Date: 2002/10/19 20:15:09 $\n");
+ puts("$Revision: 1.306 $ $Date: 2002/10/24 23:19:13 $\n");
}
/*
void
ResetUsage(void)
{
- struct timezone tz;
-
getrusage(RUSAGE_SELF, &Save_r);
- gettimeofday(&Save_t, &tz);
+ gettimeofday(&Save_t, NULL);
ResetBufferUsage();
-/* ResetTupleCount(); */
+ /* ResetTupleCount(); */
}
void
struct timeval user,
sys;
struct timeval elapse_t;
- struct timezone tz;
struct rusage r;
char *bufusage;
getrusage(RUSAGE_SELF, &r);
- gettimeofday(&elapse_t, &tz);
+ gettimeofday(&elapse_t, NULL);
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
if (elapse_t.tv_usec < Save_t.tv_usec)
appendStringInfo(&str, "! system usage stats:\n");
appendStringInfo(&str,
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
- (long int) elapse_t.tv_sec - Save_t.tv_sec,
- (long int) elapse_t.tv_usec - Save_t.tv_usec,
- (long int) r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec,
- (long int) r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec,
- (long int) r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec,
- (long int) r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec);
+ (long) (elapse_t.tv_sec - Save_t.tv_sec),
+ (long) (elapse_t.tv_usec - Save_t.tv_usec),
+ (long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
+ (long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
+ (long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
+ (long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec));
appendStringInfo(&str,
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
- (long int) user.tv_sec,
- (long int) user.tv_usec,
- (long int) sys.tv_sec,
- (long int) sys.tv_usec);
+ (long) user.tv_sec,
+ (long) user.tv_usec,
+ (long) sys.tv_sec,
+ (long) sys.tv_usec);
/* BeOS has rusage but only has some fields, and not these... */
#if defined(HAVE_GETRUSAGE)
appendStringInfo(&str,