1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::buf::{BufferFormat, BufferMarker};
use crate::prelude::*;
use yoke::trait_hack::YokeTraitHack;
#[derive(Debug, Copy, Clone, yoke::Yokeable, Default)]
#[non_exhaustive]
pub struct HeapStats {
pub total_bytes_allocated: u64,
pub net_bytes_allocated: usize,
}
#[allow(clippy::exhaustive_structs)]
pub struct HeapStatsMarker;
impl DataMarker for HeapStatsMarker {
type Yokeable = HeapStats;
}
impl DataPayload<BufferMarker> {
#[allow(clippy::expect_used)]
pub fn attempt_zero_copy_heap_size<M>(self) -> HeapStats
where
M: DataMarker,
for<'a> &'a <M::Yokeable as yoke::Yokeable<'a>>::Output: serde::Serialize,
for<'de> YokeTraitHack<<M::Yokeable as yoke::Yokeable<'de>>::Output>:
serde::Deserialize<'de>,
{
let stats_before = dhat::HeapStats::get();
let _reified_data: DataPayload<M> = self
.into_deserialized(BufferFormat::Postcard1)
.expect("Failed to deserialize BufferMarker as postcard-0.7");
let stats_after = dhat::HeapStats::get();
HeapStats {
total_bytes_allocated: stats_after.total_bytes - stats_before.total_bytes,
net_bytes_allocated: stats_after.curr_bytes - stats_before.curr_bytes,
}
}
}