| 397 | } |
| 398 | |
| 399 | HeapSimulator::Result HeapSimulator::Finish() { |
| 400 | Result result = algorithm_->Finish(); |
| 401 | |
| 402 | // Post-process the result to add chunks for shared buffers. An empty chunk |
| 403 | // map means that either no buffers were allocated, or the heap was only |
| 404 | // collecting statistics, e.g. NoFragmentationStatsHeap. |
| 405 | size_t total_chunk_count = 0; |
| 406 | absl::c_for_each(result.heap_results, [&](const HeapResult& hr) { |
| 407 | total_chunk_count += hr.chunk_map.size(); |
| 408 | }); |
| 409 | if (total_chunk_count != 0) { |
| 410 | // If we were told to assign specific buffers, make sure we've assigned |
| 411 | // exactly that many buffers. |
| 412 | if (options_.buffers_to_assign != nullptr) { |
| 413 | CHECK_EQ(options_.buffers_to_assign->size(), total_chunk_count); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // Fragmentation is the difference between the actual and ideal sizes. |
| 418 | const Result no_frag_result = no_fragmentation_stats_->Finish(); |
| 419 | result.fragmentation_size = result.heap_size - no_frag_result.heap_size; |
| 420 | |
| 421 | // Copy the debug trace we collected to the final result. |
| 422 | result.debug_trace.Swap(&debug_trace_); |
| 423 | |
| 424 | return result; |
| 425 | } |
| 426 | |
| 427 | void HeapSimulator::FillDebugTrace(HeapSimulatorTrace::Event::Kind kind, |
| 428 | const HloValue* buffer, |
no test coverage detected