C/C++ API Reference
Loading...
Searching...
No Matches
pw_bloat

Oveview

Utilities for generating binary size reports. Main docs: https://pigweed.dev/pw_bloat.

Macros

#define PW_BLOAT_COND(cond, mask)
 
#define PW_BLOAT_EXPR(expr, mask)
 

Variables

constexpr uint32_t pw::bloat::kDefaultMask = ~0u
 

Macro Definition Documentation

◆ PW_BLOAT_COND

#define PW_BLOAT_COND (   cond,
  mask 
)
Value:
do { \
if ((mask & 1) != 0 && (cond)) { \
mask = (mask >> 1) | 0x8000000; \
} else { \
mask >>= 1; \
} \
} while (0)

Possibly evaluates a conditional statement as part of a size report.

The mask parameter is treated as a bitmap. If the least significant bit is set, the condition is evaluated and, if true, the bit is recycled to the most significant position. Otherwise, the bit is discarded.

A clever compiler should be kept from optimizing away the conditional statements by initializing the mask parameter with a volatile variable:

volatile uint32_t mask = pw::bloat::kDefaultMask;
MyObject my_obj;
PW_BLOAT_COND(my_obj.is_in_some_state(), mask);
constexpr uint32_t kDefaultMask
Definition: bloat_this_binary.h:32
#define PW_BLOAT_COND(cond, mask)
Definition: bloat_this_binary.h:51

If a method returns void and is called for its side effects, use PW_BLOAT_EXPR instead.

◆ PW_BLOAT_EXPR

#define PW_BLOAT_EXPR (   expr,
  mask 
)
Value:
do { \
if ((mask & 1) != 0) { \
(expr); \
mask = (mask >> 1) | 0x8000000; \
} else { \
mask >>= 1; \
} \
} while (0)

Possibly evaluates an expression as part of a size report.

The mask parameter is treated as a bitmap. If the least significant bit is set, the expression is evaluated and the bit is recycled to the most significant position. Otherwise, the bit is discarded.

A clever compiler should be kept from optimizing away the expression by initializing the mask parameter with a volatile variable, provided the method has some side effect:

volatile uint32_t mask = pw::bloat::kDefaultMask;
MyObject my_obj;
PW_BLOAT_EXPR(my_obj.some_method(), mask);
#define PW_BLOAT_EXPR(expr, mask)
Definition: bloat_this_binary.h:78

If a method is const or has no effect beyond its return value, use PW_BLOAT_COND instead.

Variable Documentation

◆ kDefaultMask

constexpr uint32_t pw::bloat::kDefaultMask = ~0u
constexpr

A value that can cause all conditions passed to PW_BLOAT_COND and expressions passed to PW_BLOAT_EXPR to be executed. Assign a volatile variable to this value and pass it those macros to prevent unwanted compiler optimizations from removing code to be measured.