@@ -79,7 +79,7 @@ impl Sampler {
79
79
clippy:: cast_possible_truncation,
80
80
clippy:: cast_possible_wrap
81
81
) ]
82
- pub ( crate ) async fn poll ( & mut self ) -> Result < ( ) , Error > {
82
+ pub ( crate ) async fn poll ( & mut self , include_smaps : bool ) -> Result < ( ) , Error > {
83
83
// A tally of the total RSS and PSS consumed by the parent process and
84
84
// its children.
85
85
let mut aggr = memory:: smaps_rollup:: Aggregator :: default ( ) ;
@@ -121,7 +121,7 @@ impl Sampler {
121
121
self . process_info . retain ( |pid, _| pids. contains ( pid) ) ;
122
122
123
123
let pid = process. pid ( ) ;
124
- if let Err ( e) = self . handle_process ( process, & mut aggr) . await {
124
+ if let Err ( e) = self . handle_process ( process, & mut aggr, include_smaps ) . await {
125
125
warn ! ( "Encountered uncaught error when handling `/proc/{pid}/`: {e}" ) ;
126
126
}
127
127
}
@@ -143,6 +143,7 @@ impl Sampler {
143
143
& mut self ,
144
144
process : Process ,
145
145
aggr : & mut memory:: smaps_rollup:: Aggregator ,
146
+ include_smaps : bool ,
146
147
) -> Result < ( ) , Error > {
147
148
let pid = process. pid ( ) ;
148
149
@@ -238,72 +239,73 @@ impl Sampler {
238
239
return Ok ( ( ) ) ;
239
240
}
240
241
241
- // `/proc/{pid}/smaps`
242
- match memory:: smaps:: Regions :: from_pid ( pid) {
243
- Ok ( memory_regions) => {
244
- for ( pathname, measures) in memory_regions. aggregate_by_pathname ( ) {
245
- let labels: [ ( & ' static str , String ) ; 5 ] = [
246
- ( "pid" , pinfo. pid_s . clone ( ) ) ,
247
- ( "exe" , pinfo. exe . clone ( ) ) ,
248
- ( "cmdline" , pinfo. cmdline . clone ( ) ) ,
249
- ( "comm" , pinfo. comm . clone ( ) ) ,
250
- ( "pathname" , pathname) ,
251
- ] ;
252
- gauge ! ( "smaps.rss.by_pathname" , & labels) . set ( measures. rss as f64 ) ;
253
- gauge ! ( "smaps.pss.by_pathname" , & labels) . set ( measures. pss as f64 ) ;
254
- gauge ! ( "smaps.swap.by_pathname" , & labels) . set ( measures. swap as f64 ) ;
255
- gauge ! ( "smaps.size.by_pathname" , & labels) . set ( measures. size as f64 ) ;
242
+ if include_smaps {
243
+ // `/proc/{pid}/smaps`
244
+ match memory:: smaps:: Regions :: from_pid ( pid) {
245
+ Ok ( memory_regions) => {
246
+ for ( pathname, measures) in memory_regions. aggregate_by_pathname ( ) {
247
+ let labels: [ ( & ' static str , String ) ; 5 ] = [
248
+ ( "pid" , pinfo. pid_s . clone ( ) ) ,
249
+ ( "exe" , pinfo. exe . clone ( ) ) ,
250
+ ( "cmdline" , pinfo. cmdline . clone ( ) ) ,
251
+ ( "comm" , pinfo. comm . clone ( ) ) ,
252
+ ( "pathname" , pathname) ,
253
+ ] ;
254
+ gauge ! ( "smaps.rss.by_pathname" , & labels) . set ( measures. rss as f64 ) ;
255
+ gauge ! ( "smaps.pss.by_pathname" , & labels) . set ( measures. pss as f64 ) ;
256
+ gauge ! ( "smaps.swap.by_pathname" , & labels) . set ( measures. swap as f64 ) ;
257
+ gauge ! ( "smaps.size.by_pathname" , & labels) . set ( measures. size as f64 ) ;
256
258
257
- if let Some ( m) = measures. private_clean {
258
- gauge ! ( "smaps.private_clean.by_pathname" , & labels) . set ( m as f64 ) ;
259
- }
260
- if let Some ( m) = measures. private_dirty {
261
- gauge ! ( "smaps.private_dirty.by_pathname" , & labels) . set ( m as f64 ) ;
262
- }
263
- if let Some ( m) = measures. shared_clean {
264
- gauge ! ( "smaps.shared_clean.by_pathname" , & labels) . set ( m as f64 ) ;
265
- }
266
- if let Some ( m) = measures. shared_dirty {
267
- gauge ! ( "smaps.shared_dirty.by_pathname" , & labels) . set ( m as f64 ) ;
268
- }
269
- if let Some ( m) = measures. referenced {
270
- gauge ! ( "smaps.referenced.by_pathname" , & labels) . set ( m as f64 ) ;
271
- }
272
- if let Some ( m) = measures. anonymous {
273
- gauge ! ( "smaps.anonymous.by_pathname" , & labels) . set ( m as f64 ) ;
274
- }
275
- if let Some ( m) = measures. lazy_free {
276
- gauge ! ( "smaps.lazy_free.by_pathname" , & labels) . set ( m as f64 ) ;
277
- }
278
- if let Some ( m) = measures. anon_huge_pages {
279
- gauge ! ( "smaps.anon_huge_pages.by_pathname" , & labels) . set ( m as f64 ) ;
280
- }
281
- if let Some ( m) = measures. shmem_pmd_mapped {
282
- gauge ! ( "smaps.shmem_pmd_mapped.by_pathname" , & labels) . set ( m as f64 ) ;
283
- }
284
- if let Some ( m) = measures. shared_hugetlb {
285
- gauge ! ( "smaps.shared_hugetlb.by_pathname" , & labels) . set ( m as f64 ) ;
286
- }
287
- if let Some ( m) = measures. private_hugetlb {
288
- gauge ! ( "smaps.private_hugetlb.by_pathname" , & labels) . set ( m as f64 ) ;
289
- }
290
- if let Some ( m) = measures. file_pmd_mapped {
291
- gauge ! ( "smaps.file_pmd_mapped.by_pathname" , & labels) . set ( m as f64 ) ;
292
- }
293
- if let Some ( m) = measures. locked {
294
- gauge ! ( "smaps.locked.by_pathname" , & labels) . set ( m as f64 ) ;
295
- }
296
- if let Some ( m) = measures. swap_pss {
297
- gauge ! ( "smaps.swap_pss.by_pathname" , & labels) . set ( m as f64 ) ;
259
+ if let Some ( m) = measures. private_clean {
260
+ gauge ! ( "smaps.private_clean.by_pathname" , & labels) . set ( m as f64 ) ;
261
+ }
262
+ if let Some ( m) = measures. private_dirty {
263
+ gauge ! ( "smaps.private_dirty.by_pathname" , & labels) . set ( m as f64 ) ;
264
+ }
265
+ if let Some ( m) = measures. shared_clean {
266
+ gauge ! ( "smaps.shared_clean.by_pathname" , & labels) . set ( m as f64 ) ;
267
+ }
268
+ if let Some ( m) = measures. shared_dirty {
269
+ gauge ! ( "smaps.shared_dirty.by_pathname" , & labels) . set ( m as f64 ) ;
270
+ }
271
+ if let Some ( m) = measures. referenced {
272
+ gauge ! ( "smaps.referenced.by_pathname" , & labels) . set ( m as f64 ) ;
273
+ }
274
+ if let Some ( m) = measures. anonymous {
275
+ gauge ! ( "smaps.anonymous.by_pathname" , & labels) . set ( m as f64 ) ;
276
+ }
277
+ if let Some ( m) = measures. lazy_free {
278
+ gauge ! ( "smaps.lazy_free.by_pathname" , & labels) . set ( m as f64 ) ;
279
+ }
280
+ if let Some ( m) = measures. anon_huge_pages {
281
+ gauge ! ( "smaps.anon_huge_pages.by_pathname" , & labels) . set ( m as f64 ) ;
282
+ }
283
+ if let Some ( m) = measures. shmem_pmd_mapped {
284
+ gauge ! ( "smaps.shmem_pmd_mapped.by_pathname" , & labels) . set ( m as f64 ) ;
285
+ }
286
+ if let Some ( m) = measures. shared_hugetlb {
287
+ gauge ! ( "smaps.shared_hugetlb.by_pathname" , & labels) . set ( m as f64 ) ;
288
+ }
289
+ if let Some ( m) = measures. private_hugetlb {
290
+ gauge ! ( "smaps.private_hugetlb.by_pathname" , & labels) . set ( m as f64 ) ;
291
+ }
292
+ if let Some ( m) = measures. file_pmd_mapped {
293
+ gauge ! ( "smaps.file_pmd_mapped.by_pathname" , & labels) . set ( m as f64 ) ;
294
+ }
295
+ if let Some ( m) = measures. locked {
296
+ gauge ! ( "smaps.locked.by_pathname" , & labels) . set ( m as f64 ) ;
297
+ }
298
+ if let Some ( m) = measures. swap_pss {
299
+ gauge ! ( "smaps.swap_pss.by_pathname" , & labels) . set ( m as f64 ) ;
300
+ }
298
301
}
299
302
}
300
- }
301
- Err ( err) => {
302
- // We don't want to bail out entirely if we can't read stats
303
- // which will happen if we don't have permissions or, more
304
- // likely, the process has exited.
305
- warn ! ( "Couldn't process `/proc/{pid}/smaps`: {err}" ) ;
306
- return Ok ( ( ) ) ;
303
+ Err ( err) => {
304
+ // We don't want to bail out entirely if we can't read stats
305
+ // which will happen if we don't have permissions or, more
306
+ // likely, the process has exited.
307
+ warn ! ( "Couldn't process `/proc/{pid}/smaps`: {err}" ) ;
308
+ }
307
309
}
308
310
}
309
311
0 commit comments