Freeze into an immutable [`BlockProfile`]. Block ids are assigned by sorting addresses, so the result is deterministic regardless of insertion order.
(self)
| 408 | struct Accum { |
| 409 | heartbeats: u64, |
| 410 | serialized_size: u32, |
| 411 | const_count: u32, |
| 412 | ops: OpCounts, |
| 413 | producers: FxHashSet<Address>, |
| 414 | } |
| 415 | |
| 416 | impl ProfileBuilder { |
| 417 | pub fn new() -> Self { |
| 418 | Self::default() |
| 419 | } |
| 420 | |
| 421 | /// Record (or accumulate into) a block's statistics. Heartbeats, |
| 422 | /// const_count, and the op counters accumulate additively; serialized_size |
| 423 | /// is set (idempotent for a fixed block). |
| 424 | pub fn block( |
| 425 | &mut self, |
| 426 | addr: Address, |
| 427 | heartbeats: u64, |
| 428 | serialized_size: u32, |
| 429 | const_count: u32, |
| 430 | ops: OpCounts, |
| 431 | ) { |
| 432 | let e = self.blocks.entry(addr).or_default(); |
| 433 | e.heartbeats = e.heartbeats.saturating_add(heartbeats); |
| 434 | e.serialized_size = serialized_size; |
| 435 | e.const_count = e.const_count.saturating_add(const_count); |
| 436 | e.ops.add(&ops); |
| 437 | } |
| 438 | |
| 439 | /// Record that `consumer` delta-unfolds the body of `producer`. Self-edges |
| 440 | /// are ignored. Ensures both endpoints exist as blocks (with zeroed stats if |
| 441 | /// not yet seen) so the graph is well-formed even if a producer is only ever |