Skip to content

Commit 7b5cc1f

Browse files
committed
feat: 添加新api: detach_apps
1 parent f6b32f2 commit 7b5cc1f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Diff for: frame-analyzer/src/lib.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,36 @@ impl Analyzer {
227227
}
228228

229229
self.map.remove(&pid).ok_or(AnalyzerError::AppNotFound)?;
230-
self.map.remove(&pid);
231230
self.register_poll()?;
232231

233232
Ok(())
234233
}
235234

235+
/// Detach the Analyzer from all attached apps
236+
///
237+
/// # Examples
238+
///
239+
/// ```
240+
/// # use frame_analyzer::Analyzer;
241+
/// #
242+
/// #
243+
/// # fn main() {
244+
/// # let _ = try_main();
245+
/// # }
246+
/// #
247+
/// # fn try_main() -> anyhow::Result<()> {
248+
/// let mut analyzer = Analyzer::new()?;
249+
/// # let app_pid = 2;
250+
/// analyzer.attach_app(app_pid);
251+
/// // Do some useful work for awhile
252+
/// analyzer.detach_apps(); // if you don't detach here, analyzer will auto detach it when itself go dropped
253+
/// # Ok(())
254+
/// # }
255+
/// ```
256+
pub fn detach_apps(&mut self) {
257+
self.map.clear();
258+
}
259+
236260
/// Attempts to wait for a frametime value on this analyzer
237261
/// `Analyzer::recv` will always block the current thread if there is no data available
238262
///

0 commit comments

Comments
 (0)