Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

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

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

Definition at line 40 of file pg_rusage.c.

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

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

{
    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 %d.%02ds/%d.%02du sec elapsed %d.%02d sec",
             (int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
          (int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
             (int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
          (int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
             (int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
             (int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);

    return result;
}