@@ -83,6 +83,8 @@ impl Sampler {
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 ( ) ;
86
+ let mut processes_found: i32 = 0 ;
87
+ let mut pids_skipped: FxHashSet < i32 > = FxHashSet :: default ( ) ;
86
88
87
89
// Every sample run we collect all the child processes rooted at the
88
90
// parent. As noted by the procfs documentation is this done by
@@ -115,25 +117,43 @@ impl Sampler {
115
117
pids. insert ( pid) ;
116
118
}
117
119
}
118
- }
120
+ }
119
121
}
120
122
}
121
123
124
+ processes_found += 1 ;
122
125
let pid = process. pid ( ) ;
123
- if let Err ( e) = self . handle_process ( process, & mut aggr, include_smaps) . await {
124
- warn ! ( "Encountered uncaught error when handling `/proc/{pid}/`: {e}" ) ;
125
- }
126
+ match self . handle_process ( process, & mut aggr, include_smaps) . await {
127
+ Ok ( true ) => { /* Handled successfully */ }
128
+ Ok ( false ) => {
129
+ pids_skipped. insert ( pid) ;
130
+ }
131
+ Err ( e) => {
132
+ warn ! ( "Encountered uncaught error when handling `/proc/{pid}/`: {e}" ) ;
133
+ }
126
134
}
127
135
128
136
// Update the process_info map to only hold processes seen by the current poll call.
129
137
self . process_info . retain ( |pid, _| pids. contains ( pid) ) ;
130
138
131
139
gauge ! ( "total_rss_bytes" ) . set ( aggr. rss as f64 ) ;
132
140
gauge ! ( "total_pss_bytes" ) . set ( aggr. pss as f64 ) ;
141
+ gauge ! ( "processes_found" ) . set ( processes_found as f64 ) ;
142
+
143
+ // If we skipped any processes, log a warning.
144
+ if !pids_skipped. is_empty ( ) {
145
+ warn ! (
146
+ "Skipped {} processes: {:?}" ,
147
+ pids_skipped. len( ) ,
148
+ pids_skipped
149
+ ) ;
150
+ }
133
151
134
- Ok ( ( ) )
152
+ ( )
135
153
}
136
154
155
+ /// Handle a process. Returns true if the process was handled successfully,
156
+ /// false if it was skipped for any reason.
137
157
#[ allow(
138
158
clippy:: similar_names,
139
159
clippy:: too_many_lines,
@@ -146,7 +166,7 @@ impl Sampler {
146
166
process : Process ,
147
167
aggr : & mut memory:: smaps_rollup:: Aggregator ,
148
168
include_smaps : bool ,
149
- ) -> Result < ( ) , Error > {
169
+ ) -> Result < bool , Error > {
150
170
let pid = process. pid ( ) ;
151
171
152
172
// `/proc/{pid}/status`
@@ -156,12 +176,12 @@ impl Sampler {
156
176
warn ! ( "Couldn't read status: {:?}" , e) ;
157
177
// The pid may have exited since we scanned it or we may not
158
178
// have sufficient permission.
159
- return Ok ( ( ) ) ;
179
+ return Ok ( false ) ;
160
180
}
161
181
} ;
162
182
if status. tgid != pid {
163
183
// This is a thread, not a process and we do not wish to scan it.
164
- return Ok ( ( ) ) ;
184
+ return Ok ( false ) ;
165
185
}
166
186
167
187
// If we haven't seen this process before, initialize its ProcessInfo.
@@ -174,7 +194,7 @@ impl Sampler {
174
194
warn ! ( "Couldn't read exe for pid {}: {:?}" , pid, e) ;
175
195
// The pid may have exited since we scanned it or we may not
176
196
// have sufficient permission.
177
- return Ok ( ( ) ) ;
197
+ return Ok ( false ) ;
178
198
}
179
199
} ;
180
200
let comm = match proc_comm ( pid) . await {
@@ -183,7 +203,7 @@ impl Sampler {
183
203
warn ! ( "Couldn't read comm for pid {}: {:?}" , pid, e) ;
184
204
// The pid may have exited since we scanned it or we may not
185
205
// have sufficient permission.
186
- return Ok ( ( ) ) ;
206
+ return Ok ( false ) ;
187
207
}
188
208
} ;
189
209
let cmdline = match proc_cmdline ( pid) . await {
@@ -192,7 +212,7 @@ impl Sampler {
192
212
warn ! ( "Couldn't read cmdline for pid {}: {:?}" , pid, e) ;
193
213
// The pid may have exited since we scanned it or we may not
194
214
// have sufficient permission.
195
- return Ok ( ( ) ) ;
215
+ return Ok ( false ) ;
196
216
}
197
217
} ;
198
218
let pid_s = format ! ( "{pid}" ) ;
@@ -238,7 +258,7 @@ impl Sampler {
238
258
// which will happen if we don't have permissions or, more
239
259
// likely, the process has exited.
240
260
warn ! ( "Couldn't process `/proc/{pid}/stat`: {e}" ) ;
241
- return Ok ( ( ) ) ;
261
+ return Ok ( false ) ;
242
262
}
243
263
244
264
if include_smaps {
@@ -317,10 +337,10 @@ impl Sampler {
317
337
// which will happen if we don't have permissions or, more
318
338
// likely, the process has exited.
319
339
warn ! ( "Couldn't process `/proc/{pid}/smaps_rollup`: {err}" ) ;
320
- return Ok ( ( ) ) ;
340
+ return Ok ( false ) ;
321
341
}
322
342
323
- Ok ( ( ) )
343
+ Ok ( true )
324
344
}
325
345
}
326
346
0 commit comments