perf_event_data/records/
lost.rs

1use crate::prelude::*;
2
3/// Lost records indicate when events are dropped by the kernel.
4///
5/// This will happen when the sampler ring buffer fills up and there is no
6/// space left for events to be inserted.
7#[derive(Copy, Clone, Debug)]
8pub struct Lost {
9    /// The unique event ID for the samples that were lost.
10    pub id: u64,
11
12    /// The number of events that were lost.
13    pub lost: u64,
14}
15
16impl<'p> Parse<'p> for Lost {
17    fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
18    where
19        E: Endian,
20        B: ParseBuf<'p>,
21    {
22        Ok(Self {
23            id: p.parse()?,
24            lost: p.parse()?,
25        })
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use crate::endian::Little;
32
33    use super::*;
34
35    #[test]
36    fn test_parse() {
37        #[rustfmt::skip]
38        let bytes: &[u8] = &[
39            0x10, 0x00, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00,
40            0x00, 0xAF, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x00
41        ];
42
43        let mut parser: Parser<_, Little> = Parser::new(bytes, ParseConfig::default());
44        let lost: Lost = parser.parse().unwrap();
45
46        assert_eq!(lost.id, 0x990010);
47        assert_eq!(lost.lost, 0x7B000000AF00);
48    }
49}