PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_rusage.h File Reference
#include <sys/time.h>
#include "rusagestub.h"
Include dependency graph for pg_rusage.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PGRUsage
 

Typedefs

typedef struct PGRUsage PGRUsage
 

Functions

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

Typedef Documentation

Function Documentation

void pg_rusage_init ( PGRUsage ru0)

Definition at line 27 of file pg_rusage.c.

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

Referenced by copy_heap_data(), do_analyze_rel(), lazy_cleanup_index(), lazy_scan_heap(), lazy_truncate_heap(), lazy_vacuum_heap(), lazy_vacuum_index(), lazy_vacuum_rel(), pg_rusage_show(), reindex_index(), and tuplesort_begin_common().

28 {
29  getrusage(RUSAGE_SELF, &ru0->ru);
30  gettimeofday(&ru0->tv, NULL);
31 }
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
int getrusage(int who, struct rusage *rusage)
Definition: getrusage.c:31
struct timeval tv
Definition: pg_rusage.h:29
struct rusage ru
Definition: pg_rusage.h:30
#define RUSAGE_SELF
Definition: rusagestub.h:23
#define NULL
Definition: c.h:229
const char* pg_rusage_show ( const PGRUsage ru0)

Definition at line 40 of file pg_rusage.c.

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

Referenced by copy_heap_data(), do_analyze_rel(), dumpbatch(), dumptuples(), inittapes(), lazy_cleanup_index(), lazy_scan_heap(), lazy_truncate_heap(), lazy_vacuum_heap(), lazy_vacuum_index(), lazy_vacuum_rel(), mergeonerun(), puttuple_common(), reindex_index(), tuplesort_end(), and tuplesort_performsort().

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 }
return result
Definition: formatting.c:1618
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
struct timeval ru_stime
Definition: rusagestub.h:29
void pg_rusage_init(PGRUsage *ru0)
Definition: pg_rusage.c:27
struct timeval tv
Definition: pg_rusage.h:29
struct rusage ru
Definition: pg_rusage.h:30
struct timeval ru_utime
Definition: rusagestub.h:28