Skip to main content

percpu_writer_bindings/
buffer_types.rs

1// Copyright 2026 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7//! Rust bindings and methods for `percpu_writer` dropped-record tracking structures.
8
9#![no_std]
10
11use zx_types::zx_instant_boot_ticks_t;
12
13mod sys {
14    include!(rustenv_path::envpath!("PERCPU_WRITER_BINDINGS_RS"));
15}
16
17pub use sys::{
18    percpu_writer_DroppedRecordDurationEvent as DroppedRecordDurationEvent,
19    percpu_writer_DroppedRecordStats as DroppedRecordStats,
20};
21
22impl Default for DroppedRecordStats {
23    #[inline]
24    fn default() -> Self {
25        Self::new()
26    }
27}
28
29impl DroppedRecordStats {
30    /// Creates a zero-initialized `DroppedRecordStats`.
31    #[inline]
32    pub const fn new() -> Self {
33        Self {
34            first_dropped: 0,
35            last_dropped: 0,
36            num_dropped: 0,
37            bytes_dropped: 0,
38            has_dropped: false,
39            __bindgen_padding_0: [0; 7],
40        }
41    }
42
43    /// Resets the dropped record statistics to their initial values.
44    #[inline]
45    pub fn reset(&mut self) {
46        self.first_dropped = 0;
47        self.last_dropped = 0;
48        self.num_dropped = 0;
49        self.bytes_dropped = 0;
50        self.has_dropped = false;
51    }
52
53    /// Records a dropped trace record of `size` bytes at timestamp `now`.
54    #[inline]
55    pub fn track(&mut self, now: zx_instant_boot_ticks_t, size: u32) {
56        if !self.has_dropped {
57            self.first_dropped = now;
58            self.has_dropped = true;
59        }
60        self.last_dropped = now;
61        self.num_dropped = self.num_dropped.wrapping_add(1);
62        self.bytes_dropped = self.bytes_dropped.wrapping_add(size);
63    }
64
65    /// Returns true if any records have been dropped since the last reset.
66    #[inline]
67    pub const fn has_dropped(&self) -> bool {
68        self.has_dropped
69    }
70}