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
use ;
use crateStat;
use cratederef_offset;
/// Inherited task statistics.
///
/// Can be enabled by [`ExtraRecord::read`][crate::config::ExtraRecord::read].
///
/// This allows a per-task stat on an inherited process hierarchy.
///
/// # Examples
///
/// ```rust
/// use perf_event_open::config::{Cpu, Inherit, Opts, Proc};
/// use perf_event_open::count::Counter;
/// use perf_event_open::event::sw::Software;
///
/// let event = Software::TaskClock;
/// let target = (Proc::CURRENT, Cpu(0));
///
/// let mut opts = Opts::default();
/// opts.inherit = Some(Inherit::NewChild);
/// opts.extra_record.read = true;
///
/// let counter = Counter::new(event, target, opts).unwrap();
/// let sampler = counter.sampler(5).unwrap();
///
/// counter.enable().unwrap();
///
/// unsafe {
/// let child = libc::fork();
/// if child > 0 {
/// let mut code = 0;
/// libc::waitpid(child, &mut code as _, 0);
/// assert_eq!(code, 0);
/// } else {
/// // schedule child processes on CPU 0
/// let mut set = unsafe { std::mem::zeroed() };
/// libc::CPU_SET(0, &mut set);
/// let tid = libc::gettid();
/// let set_size = size_of_val(&set);
/// assert_eq!(libc::sched_setaffinity(tid, set_size, &set as _), 0);
///
/// // make some noise in the child process to kill time
/// for i in 0..100 {
/// std::hint::black_box(&i);
/// }
/// return;
/// }
/// }
///
/// let mut count = 0;
/// for it in sampler.iter() {
/// count += 1;
/// println!("{:-?}", it);
/// }
/// assert_eq!(count, 1);
/// ```
///
/// A kernel bug introduced in Linux 5.13 caused this feature to be unavailable;
/// this bug has been fixed in Linux 6.19. Therefore, you may not receive this
/// record if your Linux kernel does not include the fix, see [patch](https://github.com/torvalds/linux/commit/c418d8b4d7a43a86b82ee39cb52ece3034383530).
from!;
debug!;