PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
logging.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  eLogType {
  PG_DEBUG, PG_PROGRESS, PG_WARNING, PG_FATAL,
  PG_VERBOSE, PG_STATUS, PG_REPORT, PG_WARNING,
  PG_FATAL
}
 

Functions

void pg_log (eLogType type, const char *fmt,...) pg_attribute_printf(2
 
void void pg_fatal (const char *fmt,...) pg_attribute_printf(1
 
void void pg_attribute_noreturn ()
 
void progress_report (bool force)
 

Variables

uint64 fetch_size
 
uint64 fetch_done
 

Enumeration Type Documentation

enum eLogType
Enumerator
PG_DEBUG 
PG_PROGRESS 
PG_WARNING 
PG_FATAL 
PG_VERBOSE 
PG_STATUS 
PG_REPORT 
PG_WARNING 
PG_FATAL 

Definition at line 22 of file logging.h.

23 {
24  PG_DEBUG,
26  PG_WARNING,
27  PG_FATAL
28 } eLogType;
eLogType
Definition: logging.h:22

Function Documentation

void void pg_attribute_noreturn ( )
void void pg_fatal ( const char *  fmt,
  ... 
)
void pg_log ( eLogType  type,
const char *  fmt,
  ... 
)
void progress_report ( bool  force)

Definition at line 102 of file logging.c.

References fetch_done, fetch_size, INT64_FORMAT, last_progress_report, now(), NULL, pg_log(), PG_PROGRESS, showprogress, and snprintf().

103 {
104  int percent;
105  char fetch_done_str[32];
106  char fetch_size_str[32];
107  pg_time_t now;
108 
109  if (!showprogress)
110  return;
111 
112  now = time(NULL);
113  if (now == last_progress_report && !force)
114  return; /* Max once per second */
115 
117  percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
118 
119  /*
120  * Avoid overflowing past 100% or the full size. This may make the total
121  * size number change as we approach the end of the backup (the estimate
122  * will always be wrong if WAL is included), but that's better than having
123  * the done column be bigger than the total.
124  */
125  if (percent > 100)
126  percent = 100;
127  if (fetch_done > fetch_size)
129 
130  /*
131  * Separate step to keep platform-dependent format code out of
132  * translatable strings. And we only test for INT64_FORMAT availability
133  * in snprintf, not fprintf.
134  */
135  snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
136  fetch_done / 1024);
137  snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
138  fetch_size / 1024);
139 
140  pg_log(PG_PROGRESS, "%*s/%s kB (%d%%) copied",
141  (int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
142  percent);
143  printf("\r");
144 }
int64 pg_time_t
Definition: pgtime.h:23
uint64 fetch_done
Definition: logging.c:22
uint64 fetch_size
Definition: logging.c:21
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void pg_log(eLogType type, const char *fmt,...)
Definition: logging.c:69
static pg_time_t last_progress_report
Definition: logging.c:24
static bool showprogress
Definition: pg_basebackup.c:86
#define NULL
Definition: c.h:226
#define INT64_FORMAT
Definition: c.h:312
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1651

Variable Documentation

uint64 fetch_done

Definition at line 22 of file logging.c.

Referenced by main(), progress_report(), and write_target_range().

uint64 fetch_size