Returns a formatted string with the top memory consumers.
(&self, top: usize)
| 484 | |
| 485 | /// Returns a formatted string with the top memory consumers. |
| 486 | pub fn report_top(&self, top: usize) -> String { |
| 487 | let mut consumers = self |
| 488 | .tracked_consumers |
| 489 | .lock() |
| 490 | .iter() |
| 491 | .map(|(consumer_id, tracked_consumer)| { |
| 492 | ( |
| 493 | ( |
| 494 | *consumer_id, |
| 495 | tracked_consumer.name.to_owned(), |
| 496 | tracked_consumer.can_spill, |
| 497 | tracked_consumer.peak(), |
| 498 | ), |
| 499 | tracked_consumer.reserved(), |
| 500 | ) |
| 501 | }) |
| 502 | .collect::<Vec<_>>(); |
| 503 | consumers.sort_by_key(|consumer| std::cmp::Reverse(consumer.1)); |
| 504 | |
| 505 | consumers[0..std::cmp::min(top, consumers.len())] |
| 506 | .iter() |
| 507 | .map(|((id, name, can_spill, peak), size)| { |
| 508 | format!( |
| 509 | " {name}#{id}(can spill: {can_spill}) consumed {}, peak {}", |
| 510 | human_readable_size(*size), |
| 511 | human_readable_size(*peak), |
| 512 | ) |
| 513 | }) |
| 514 | .collect::<Vec<_>>() |
| 515 | .join(",\n") |
| 516 | + "." |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | impl<I: MemoryPool> MemoryPool for TrackConsumersPool<I> { |