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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use ;
use cratederef_offset;
// PERF_RECORD_LOST counts all lost records:
// Count lost when paused:
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/ring_buffer.c#L178
// Count lost when no space:
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/ring_buffer.c#L203
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/ring_buffer.c#L263
// Generate PERF_RECORD_LOST:
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/ring_buffer.c#L189
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/ring_buffer.c#L247
// The same applies to `perf_read`:
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/core.c#L5764
// https://github.com/torvalds/linux/blob/v6.13/kernel/events/core.c#L7373
/// Some records have been lost.
///
/// # Examples
///
/// ```rust
/// # #[cfg(not(feature = "linux-6.0"))]
/// # return;
/// #
/// # tokio_test::block_on(async {
/// use std::thread;
/// use std::time::Duration;
///
/// use perf_event_open::config::{Cpu, Opts, Proc, SampleOn, WakeUpOn};
/// use perf_event_open::count::Counter;
/// use perf_event_open::event::sw::Software;
/// use perf_event_open::sample::record::Record;
///
/// let event = Software::TaskClock;
/// let target = (Proc::ALL, Cpu(0));
///
/// let mut opts = Opts::default();
/// opts.stat_format.lost_records = true;
/// opts.wake_up.on = WakeUpOn::Samples(1);
/// opts.sample_on = SampleOn::Count(1_000_000); // 1ms
///
/// let counter = Counter::new(event, target, opts).unwrap();
/// let sampler = counter.sampler(5).unwrap();
///
/// counter.enable().unwrap();
/// // Pause the ring-buffer output, discarded samples are considered lost.
/// sampler.pause().unwrap();
/// thread::sleep(Duration::from_millis(10));
/// sampler.resume().unwrap();
///
/// let mut iter = sampler.iter().into_async().unwrap();
/// while let Some((_, r)) = iter.next().await {
/// if let Record::LostRecords(l) = r {
/// println!("{:-?}", l);
/// # assert!(l.lost_records > 0);
/// break;
/// }
/// }
/// # });
/// ```
from!;
debug!;
/// Some samples have been lost.
///
/// This counts only hardware generated corrupt samples
/// that are discarded by the kernel.
///
/// Since `linux-4.2`: <https://github.com/torvalds/linux/commit/f38b0dbb491a6987e198aa6b428db8692a6480f8>
from!;
debug!;