|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* pg_rusage.c
|
|
|
|
|
* Resource usage measurement support routines.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
|
|
|
|
* src/backend/utils/misc/pg_rusage.c
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "utils/pg_rusage.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize usage snapshot.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pg_rusage_init(PGRUsage *ru0)
|
|
|
|
|
{
|
|
|
|
|
getrusage(RUSAGE_SELF, &ru0->ru);
|
|
|
|
|
gettimeofday(&ru0->tv, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Compute elapsed time since ru0 usage snapshot, and format into
|
|
|
|
|
* a displayable string. Result is in a static string, which is
|
|
|
|
|
* tacky, but no one ever claimed that the Postgres backend is
|
|
|
|
|
* threadable...
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
pg_rusage_show(const PGRUsage *ru0)
|
|
|
|
|
{
|
|
|
|
|
static char result[100];
|
|
|
|
|
PGRUsage ru1;
|
|
|
|
|
|
|
|
|
|
pg_rusage_init(&ru1);
|
|
|
|
|
|
|
|
|
|
if (ru1.tv.tv_usec < ru0->tv.tv_usec)
|
|
|
|
|
{
|
|
|
|
|
ru1.tv.tv_sec--;
|
|
|
|
|
ru1.tv.tv_usec += 1000000;
|
|
|
|
|
}
|
|
|
|
|
if (ru1.ru.ru_stime.tv_usec < ru0->ru.ru_stime.tv_usec)
|
|
|
|
|
{
|
|
|
|
|
ru1.ru.ru_stime.tv_sec--;
|
|
|
|
|
ru1.ru.ru_stime.tv_usec += 1000000;
|
|
|
|
|
}
|
|
|
|
|
if (ru1.ru.ru_utime.tv_usec < ru0->ru.ru_utime.tv_usec)
|
|
|
|
|
{
|
|
|
|
|
ru1.ru.ru_utime.tv_sec--;
|
|
|
|
|
ru1.ru.ru_utime.tv_usec += 1000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snprintf(result, sizeof(result),
|
|
|
|
|
_("CPU: user: %d.%02d s, system: %d.%02d s, elapsed: %d.%02d s"),
|
|
|
|
|
(int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
9 years ago
|
|
|
(int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
|
|
|
|
|
(int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
9 years ago
|
|
|
(int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
|
|
|
|
|
(int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
|
|
|
|
|
(int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|