PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_rusage.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "utils/pg_rusage.h"
Include dependency graph for pg_rusage.c:

Go to the source code of this file.

Functions

void pg_rusage_init (PGRUsage *ru0)
 
const char * pg_rusage_show (const PGRUsage *ru0)
 

Function Documentation

◆ pg_rusage_init()

void pg_rusage_init ( PGRUsage ru0)

Definition at line 27 of file pg_rusage.c.

28{
29 getrusage(RUSAGE_SELF, &ru0->ru);
30 gettimeofday(&ru0->tv, NULL);
31}
int getrusage(int who, struct rusage *rusage)
#define RUSAGE_SELF
Definition: resource.h:9
struct rusage ru
Definition: pg_rusage.h:25
struct timeval tv
Definition: pg_rusage.h:24
int gettimeofday(struct timeval *tp, void *tzp)

References getrusage(), gettimeofday(), PGRUsage::ru, RUSAGE_SELF, and PGRUsage::tv.

Referenced by copy_table_data(), do_analyze_rel(), heap_vacuum_rel(), PerformWalRecovery(), pg_rusage_show(), reindex_index(), ReindexRelationConcurrently(), and tuplesort_begin_common().

◆ pg_rusage_show()

const char * pg_rusage_show ( const PGRUsage ru0)

Definition at line 40 of file pg_rusage.c.

41{
42 static char result[100];
43 PGRUsage ru1;
44
45 pg_rusage_init(&ru1);
46
47 if (ru1.tv.tv_usec < ru0->tv.tv_usec)
48 {
49 ru1.tv.tv_sec--;
50 ru1.tv.tv_usec += 1000000;
51 }
52 if (ru1.ru.ru_stime.tv_usec < ru0->ru.ru_stime.tv_usec)
53 {
54 ru1.ru.ru_stime.tv_sec--;
55 ru1.ru.ru_stime.tv_usec += 1000000;
56 }
57 if (ru1.ru.ru_utime.tv_usec < ru0->ru.ru_utime.tv_usec)
58 {
59 ru1.ru.ru_utime.tv_sec--;
60 ru1.ru.ru_utime.tv_usec += 1000000;
61 }
62
63 snprintf(result, sizeof(result),
64 _("CPU: user: %d.%02d s, system: %d.%02d s, elapsed: %d.%02d s"),
65 (int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
66 (int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
67 (int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
68 (int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
69 (int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
70 (int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);
71
72 return result;
73}
#define _(x)
Definition: elog.c:90
void pg_rusage_init(PGRUsage *ru0)
Definition: pg_rusage.c:27
#define snprintf
Definition: port.h:238
struct timeval ru_utime
Definition: resource.h:14
struct timeval ru_stime
Definition: resource.h:15

References _, pg_rusage_init(), PGRUsage::ru, rusage::ru_stime, rusage::ru_utime, snprintf, and PGRUsage::tv.

Referenced by copy_table_data(), do_analyze_rel(), dumptuples(), heap_vacuum_rel(), inittapes(), mergeruns(), PerformWalRecovery(), reindex_index(), ReindexRelationConcurrently(), tuplesort_free(), tuplesort_performsort(), and tuplesort_puttuple_common().