PostgreSQL Source Code  git master
xlogstats.c File Reference
#include "postgres.h"
#include "access/xlogreader.h"
#include "access/xlogstats.h"
Include dependency graph for xlogstats.c:

Go to the source code of this file.

Functions

void XLogRecGetLen (XLogReaderState *record, uint32 *rec_len, uint32 *fpi_len)
 
void XLogRecStoreStats (XLogStats *stats, XLogReaderState *record)
 

Function Documentation

◆ XLogRecGetLen()

void XLogRecGetLen ( XLogReaderState record,
uint32 rec_len,
uint32 fpi_len 
)

Definition at line 22 of file xlogstats.c.

24 {
25  int block_id;
26 
27  /*
28  * Calculate the amount of FPI data in the record.
29  *
30  * XXX: We peek into xlogreader's private decoded backup blocks for the
31  * bimg_len indicating the length of FPI data.
32  */
33  *fpi_len = 0;
34  for (block_id = 0; block_id <= XLogRecMaxBlockId(record); block_id++)
35  {
36  if (!XLogRecHasBlockRef(record, block_id))
37  continue;
38 
39  if (XLogRecHasBlockImage(record, block_id))
40  *fpi_len += XLogRecGetBlock(record, block_id)->bimg_len;
41  }
42 
43  /*
44  * Calculate the length of the record as the total length - the length of
45  * all the block images.
46  */
47  *rec_len = XLogRecGetTotalLen(record) - *fpi_len;
48 }
#define XLogRecGetTotalLen(decoder)
Definition: xlogreader.h:406
#define XLogRecGetBlock(decoder, i)
Definition: xlogreader.h:417
#define XLogRecMaxBlockId(decoder)
Definition: xlogreader.h:416
#define XLogRecHasBlockImage(decoder, block_id)
Definition: xlogreader.h:421
#define XLogRecHasBlockRef(decoder, block_id)
Definition: xlogreader.h:418

References XLogRecGetBlock, XLogRecGetTotalLen, XLogRecHasBlockImage, XLogRecHasBlockRef, and XLogRecMaxBlockId.

Referenced by XLogDumpDisplayRecord(), and XLogRecStoreStats().

◆ XLogRecStoreStats()

void XLogRecStoreStats ( XLogStats stats,
XLogReaderState record 
)

Definition at line 54 of file xlogstats.c.

55 {
56  RmgrId rmid;
57  uint8 recid;
58  uint32 rec_len;
59  uint32 fpi_len;
60 
61  Assert(stats != NULL && record != NULL);
62 
63  stats->count++;
64 
65  rmid = XLogRecGetRmid(record);
66 
67  XLogRecGetLen(record, &rec_len, &fpi_len);
68 
69  /* Update per-rmgr statistics */
70 
71  stats->rmgr_stats[rmid].count++;
72  stats->rmgr_stats[rmid].rec_len += rec_len;
73  stats->rmgr_stats[rmid].fpi_len += fpi_len;
74 
75  /*
76  * Update per-record statistics, where the record is identified by a
77  * combination of the RmgrId and the four bits of the xl_info field that
78  * are the rmgr's domain (resulting in sixteen possible entries per
79  * RmgrId).
80  */
81 
82  recid = XLogRecGetInfo(record) >> 4;
83 
84  /*
85  * XACT records need to be handled differently. Those records use the
86  * first bit of those four bits for an optional flag variable and the
87  * following three bits for the opcode. We filter opcode out of xl_info
88  * and use it as the identifier of the record.
89  */
90  if (rmid == RM_XACT_ID)
91  recid &= 0x07;
92 
93  stats->record_stats[rmid][recid].count++;
94  stats->record_stats[rmid][recid].rec_len += rec_len;
95  stats->record_stats[rmid][recid].fpi_len += fpi_len;
96 }
unsigned int uint32
Definition: c.h:441
unsigned char uint8
Definition: c.h:439
Assert(fmt[strlen(fmt) - 1] !='\n')
uint8 RmgrId
Definition: rmgr.h:11
uint64 count
Definition: xlogstats.h:23
uint64 fpi_len
Definition: xlogstats.h:25
uint64 rec_len
Definition: xlogstats.h:24
XLogRecStats record_stats[RM_MAX_ID+1][MAX_XLINFO_TYPES]
Definition: xlogstats.h:36
uint64 count
Definition: xlogstats.h:30
XLogRecStats rmgr_stats[RM_MAX_ID+1]
Definition: xlogstats.h:35
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:408
#define XLogRecGetRmid(decoder)
Definition: xlogreader.h:409
void XLogRecGetLen(XLogReaderState *record, uint32 *rec_len, uint32 *fpi_len)
Definition: xlogstats.c:22

References Assert(), XLogRecStats::count, XLogStats::count, XLogRecStats::fpi_len, XLogRecStats::rec_len, XLogStats::record_stats, XLogStats::rmgr_stats, XLogRecGetInfo, XLogRecGetLen(), and XLogRecGetRmid.

Referenced by GetWalStats(), and main().