@@ -58,13 +58,14 @@ use crate::{check_errno_syscall, sys, Counter, SampleFlag};
58
58
/// [`enable`]: Counter::enable
59
59
/// [`Group`]: crate::Group
60
60
/// [`Group::add`]: crate::Group::add
61
+ #[ derive( Clone , Debug ) ]
61
62
pub struct Builder < ' a > {
62
63
attrs : perf_event_attr ,
63
64
who : EventPid < ' a > ,
64
65
cpu : Option < usize > ,
65
66
}
66
67
67
- #[ derive( Debug ) ]
68
+ #[ derive( Clone , Debug ) ]
68
69
enum EventPid < ' a > {
69
70
/// Monitor the calling process.
70
71
ThisProcess ,
@@ -119,19 +120,19 @@ impl<'a> Builder<'a> {
119
120
}
120
121
121
122
/// Include kernel code.
122
- pub fn include_kernel ( mut self ) -> Self {
123
+ pub fn include_kernel ( & mut self ) -> & mut Self {
123
124
self . attrs . set_exclude_kernel ( 0 ) ;
124
125
self
125
126
}
126
127
127
128
/// Include hypervisor code.
128
- pub fn include_hv ( mut self ) -> Self {
129
+ pub fn include_hv ( & mut self ) -> & mut Self {
129
130
self . attrs . set_exclude_hv ( 0 ) ;
130
131
self
131
132
}
132
133
133
134
/// Observe the calling process. (This is the default.)
134
- pub fn observe_self ( mut self ) -> Self {
135
+ pub fn observe_self ( & mut self ) -> & mut Self {
135
136
self . who = EventPid :: ThisProcess ;
136
137
self
137
138
}
@@ -140,7 +141,7 @@ impl<'a> Builder<'a> {
140
141
/// [`CAP_SYS_PTRACE`][man-capabilities] capabilities.
141
142
///
142
143
/// [man-capabilities]: http://man7.org/linux/man-pages/man7/capabilities.7.html
143
- pub fn observe_pid ( mut self , pid : pid_t ) -> Self {
144
+ pub fn observe_pid ( & mut self , pid : pid_t ) -> & mut Self {
144
145
self . who = EventPid :: Other ( pid) ;
145
146
self
146
147
}
@@ -160,7 +161,7 @@ impl<'a> Builder<'a> {
160
161
/// [`build`]: Builder::build
161
162
/// [`one_cpu`]: Builder::one_cpu
162
163
/// [cap]: http://man7.org/linux/man-pages/man7/capabilities.7.html
163
- pub fn any_pid ( mut self ) -> Self {
164
+ pub fn any_pid ( & mut self ) -> & mut Self {
164
165
self . who = EventPid :: Any ;
165
166
self
166
167
}
@@ -170,13 +171,13 @@ impl<'a> Builder<'a> {
170
171
/// in the cgroupfs filesystem.
171
172
///
172
173
/// [man-cgroups]: http://man7.org/linux/man-pages/man7/cgroups.7.html
173
- pub fn observe_cgroup ( mut self , cgroup : & ' a File ) -> Self {
174
+ pub fn observe_cgroup ( & mut self , cgroup : & ' a File ) -> & mut Self {
174
175
self . who = EventPid :: CGroup ( cgroup) ;
175
176
self
176
177
}
177
178
178
179
/// Observe only code running on the given CPU core.
179
- pub fn one_cpu ( mut self , cpu : usize ) -> Self {
180
+ pub fn one_cpu ( & mut self , cpu : usize ) -> & mut Self {
180
181
self . cpu = Some ( cpu) ;
181
182
self
182
183
}
@@ -193,7 +194,7 @@ impl<'a> Builder<'a> {
193
194
/// [`observe_self`]: Builder::observe_self
194
195
/// [`observe_pid`]: Builder::observe_pid
195
196
/// [`observe_cgroup`]: Builder::observe_cgroup
196
- pub fn any_cpu ( mut self ) -> Self {
197
+ pub fn any_cpu ( & mut self ) -> & mut Self {
197
198
self . cpu = None ;
198
199
self
199
200
}
@@ -209,7 +210,7 @@ impl<'a> Builder<'a> {
209
210
/// This flag cannot be set if the counter belongs to a `Group`. Doing so
210
211
/// will result in an error when the counter is built. This is a kernel
211
212
/// limitation.
212
- pub fn inherit ( mut self , inherit : bool ) -> Self {
213
+ pub fn inherit ( & mut self , inherit : bool ) -> & mut Self {
213
214
let flag = if inherit { 1 } else { 0 } ;
214
215
self . attrs . set_inherit ( flag) ;
215
216
self
@@ -290,7 +291,7 @@ impl<'a> Builder<'a> {
290
291
///
291
292
/// [`SampleFlag`]: crate::SampleFlag
292
293
/// [manpage]: http://man7.org/linux/man-pages/man2/perf_event_open.2.html
293
- pub fn sample ( mut self , sample : SampleFlag ) -> Self {
294
+ pub fn sample ( & mut self , sample : SampleFlag ) -> & mut Self {
294
295
self . attrs . sample_type |= sample. bits ( ) ;
295
296
self
296
297
}
@@ -299,7 +300,7 @@ impl<'a> Builder<'a> {
299
300
///
300
301
/// MMAP records are emitted when the process/thread that is being
301
302
/// observed creates a new executable memory mapping.
302
- pub fn mmap ( mut self , mmap : bool ) -> Self {
303
+ pub fn mmap ( & mut self , mmap : bool ) -> & mut Self {
303
304
self . attrs . set_mmap ( mmap. into ( ) ) ;
304
305
self
305
306
}
@@ -311,7 +312,7 @@ impl<'a> Builder<'a> {
311
312
/// configured.
312
313
///
313
314
/// [`wakeup_events`]: Self::wakeup_events
314
- pub fn wakeup_watermark ( mut self , watermark : usize ) -> Self {
315
+ pub fn wakeup_watermark ( & mut self , watermark : usize ) -> & mut Self {
315
316
self . attrs . set_watermark ( 1 ) ;
316
317
self . attrs . __bindgen_anon_2 . wakeup_watermark = watermark as _ ;
317
318
self
@@ -327,7 +328,7 @@ impl<'a> Builder<'a> {
327
328
///
328
329
/// [manpage]: https://man7.org/linux/man-pages/man2/perf_event_open.2.html
329
330
/// [`wakeup_watermark`]: Self::wakeup_watermark
330
- pub fn wakeup_events ( mut self , events : usize ) -> Self {
331
+ pub fn wakeup_events ( & mut self , events : usize ) -> & mut Self {
331
332
self . attrs . set_watermark ( 0 ) ;
332
333
self . attrs . __bindgen_anon_2 . wakeup_events = events as _ ;
333
334
self
0 commit comments