Make profiling API a bit harder to misuse

This commit is contained in:
Johannes Altmanninger
2026-05-03 17:37:43 +08:00
parent 161f31f42b
commit 9370830733
2 changed files with 7 additions and 14 deletions

View File

@@ -518,11 +518,7 @@ fn throwing_main() -> i32 {
// TODO(MSRV>=1.88): feature(let_chains)
if let Some(path) = &opts.profile_startup_output {
if opts.profile_startup_output != opts.profile_output {
parser.emit_profiling(path);
// If we are profiling both, ensure the startup data only
// ends up in the startup file.
parser.clear_profiling();
parser.flush_profiling(path);
}
}
@@ -621,7 +617,7 @@ fn throwing_main() -> i32 {
);
if let Some(profile_output) = opts.profile_output {
parser.emit_profiling(&profile_output);
parser.flush_profiling(&profile_output);
}
history::save_all();

View File

@@ -1119,13 +1119,8 @@ pub fn profile_items_mut(&self) -> RefMut<'_, Vec<ProfileItem>> {
self.profile_items.borrow_mut()
}
/// Remove the profiling items.
pub fn clear_profiling(&self) {
self.profile_items.borrow_mut().clear();
}
/// Output profiling data to the given filename.
pub fn emit_profiling(&self, path: &OsStr) {
/// Flush profiling data to the given filename.
pub fn flush_profiling(&self, path: &OsStr) {
// Save profiling information. OK to not use CLO_EXEC here because this is called while fish is
// exiting (and hence will not fork).
let mut f = match std::fs::File::create(path) {
@@ -1142,7 +1137,9 @@ pub fn emit_profiling(&self, path: &OsStr) {
return;
}
};
print_profile(&self.profile_items.borrow(), &mut f);
let mut profile_items = self.profile_items.borrow_mut();
print_profile(&profile_items, &mut f);
profile_items.clear();
}
pub fn get_backtrace(&self, src: &wstr, errors: &ParseErrorList) -> WString {