mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Fix some places that were unportably assuming struct timeval's tv_sec
field is signed. Clean up casting.
This commit is contained in:
parent
c3086c8f53
commit
bd19e8f604
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2001, PostgreSQL Global Development Group
|
* 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"
|
#include "postgres.h"
|
||||||
@ -1247,19 +1247,27 @@ pgstat_main(void)
|
|||||||
*/
|
*/
|
||||||
if (need_statwrite)
|
if (need_statwrite)
|
||||||
{
|
{
|
||||||
gettimeofday(&timeout, NULL);
|
struct timeval now;
|
||||||
timeout.tv_usec = next_statwrite.tv_usec - timeout.tv_usec;
|
|
||||||
timeout.tv_sec = next_statwrite.tv_sec - timeout.tv_sec;
|
gettimeofday(&now, NULL);
|
||||||
if (timeout.tv_usec < 0)
|
/* avoid assuming that tv_sec is signed */
|
||||||
{
|
if (now.tv_sec > next_statwrite.tv_sec ||
|
||||||
timeout.tv_sec -= 1;
|
(now.tv_sec == next_statwrite.tv_sec &&
|
||||||
timeout.tv_usec += 1000000;
|
now.tv_usec >= next_statwrite.tv_usec))
|
||||||
}
|
|
||||||
if (timeout.tv_sec < 0)
|
|
||||||
{
|
{
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_usec = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
@ -559,7 +559,6 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
|
|||||||
MemoryContext oldcontext;
|
MemoryContext oldcontext;
|
||||||
List *parsetree_list,
|
List *parsetree_list,
|
||||||
*parsetree_item;
|
*parsetree_item;
|
||||||
struct timezone tz;
|
|
||||||
struct timeval start_t,
|
struct timeval start_t,
|
||||||
stop_t;
|
stop_t;
|
||||||
bool save_Log_duration = Log_duration;
|
bool save_Log_duration = Log_duration;
|
||||||
@ -571,7 +570,7 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
|
|||||||
* report incorrect time because gettimeofday() wasn't called.
|
* report incorrect time because gettimeofday() wasn't called.
|
||||||
*/
|
*/
|
||||||
if (save_Log_duration)
|
if (save_Log_duration)
|
||||||
gettimeofday(&start_t, &tz);
|
gettimeofday(&start_t, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start up a transaction command. All queries generated by the
|
* Start up a transaction command. All queries generated by the
|
||||||
@ -943,15 +942,15 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
|
|||||||
|
|
||||||
if (save_Log_duration)
|
if (save_Log_duration)
|
||||||
{
|
{
|
||||||
gettimeofday(&stop_t, &tz);
|
gettimeofday(&stop_t, NULL);
|
||||||
if (stop_t.tv_usec < start_t.tv_usec)
|
if (stop_t.tv_usec < start_t.tv_usec)
|
||||||
{
|
{
|
||||||
stop_t.tv_sec--;
|
stop_t.tv_sec--;
|
||||||
stop_t.tv_usec += 1000000;
|
stop_t.tv_usec += 1000000;
|
||||||
}
|
}
|
||||||
elog(LOG, "duration: %ld.%06ld sec",
|
elog(LOG, "duration: %ld.%06ld sec",
|
||||||
(long int) stop_t.tv_sec - start_t.tv_sec,
|
(long) (stop_t.tv_sec - start_t.tv_sec),
|
||||||
(long int) stop_t.tv_usec - start_t.tv_usec);
|
(long) (stop_t.tv_usec - start_t.tv_usec));
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_query_string = NULL;
|
debug_query_string = NULL;
|
||||||
@ -1783,7 +1782,7 @@ PostgresMain(int argc, char *argv[], const char *username)
|
|||||||
if (!IsUnderPostmaster)
|
if (!IsUnderPostmaster)
|
||||||
{
|
{
|
||||||
puts("\nPOSTGRES backend interactive interface ");
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2081,12 +2080,10 @@ struct timeval Save_t;
|
|||||||
void
|
void
|
||||||
ResetUsage(void)
|
ResetUsage(void)
|
||||||
{
|
{
|
||||||
struct timezone tz;
|
|
||||||
|
|
||||||
getrusage(RUSAGE_SELF, &Save_r);
|
getrusage(RUSAGE_SELF, &Save_r);
|
||||||
gettimeofday(&Save_t, &tz);
|
gettimeofday(&Save_t, NULL);
|
||||||
ResetBufferUsage();
|
ResetBufferUsage();
|
||||||
/* ResetTupleCount(); */
|
/* ResetTupleCount(); */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -2096,12 +2093,11 @@ ShowUsage(const char *title)
|
|||||||
struct timeval user,
|
struct timeval user,
|
||||||
sys;
|
sys;
|
||||||
struct timeval elapse_t;
|
struct timeval elapse_t;
|
||||||
struct timezone tz;
|
|
||||||
struct rusage r;
|
struct rusage r;
|
||||||
char *bufusage;
|
char *bufusage;
|
||||||
|
|
||||||
getrusage(RUSAGE_SELF, &r);
|
getrusage(RUSAGE_SELF, &r);
|
||||||
gettimeofday(&elapse_t, &tz);
|
gettimeofday(&elapse_t, NULL);
|
||||||
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
|
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
|
||||||
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
|
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
|
||||||
if (elapse_t.tv_usec < Save_t.tv_usec)
|
if (elapse_t.tv_usec < Save_t.tv_usec)
|
||||||
@ -2133,18 +2129,18 @@ ShowUsage(const char *title)
|
|||||||
appendStringInfo(&str, "! system usage stats:\n");
|
appendStringInfo(&str, "! system usage stats:\n");
|
||||||
appendStringInfo(&str,
|
appendStringInfo(&str,
|
||||||
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
|
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
|
||||||
(long int) elapse_t.tv_sec - Save_t.tv_sec,
|
(long) (elapse_t.tv_sec - Save_t.tv_sec),
|
||||||
(long int) elapse_t.tv_usec - Save_t.tv_usec,
|
(long) (elapse_t.tv_usec - Save_t.tv_usec),
|
||||||
(long int) r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec,
|
(long) (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) (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) (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) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec));
|
||||||
appendStringInfo(&str,
|
appendStringInfo(&str,
|
||||||
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
|
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
|
||||||
(long int) user.tv_sec,
|
(long) user.tv_sec,
|
||||||
(long int) user.tv_usec,
|
(long) user.tv_usec,
|
||||||
(long int) sys.tv_sec,
|
(long) sys.tv_sec,
|
||||||
(long int) sys.tv_usec);
|
(long) sys.tv_usec);
|
||||||
/* BeOS has rusage but only has some fields, and not these... */
|
/* BeOS has rusage but only has some fields, and not these... */
|
||||||
#if defined(HAVE_GETRUSAGE)
|
#if defined(HAVE_GETRUSAGE)
|
||||||
appendStringInfo(&str,
|
appendStringInfo(&str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user