Skip to content

Commit

Permalink
[fxfs] Make profile recording generic for files and blobs.
Browse files Browse the repository at this point in the history
Bug: b/337321099

Change-Id: Ib4e351bec81c68bca1e02186b64b34c3b00f5e55
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/ /1049613
Reviewed-by: Chris Drouillard <[email protected]>
Commit-Queue: Martin Lindsay <[email protected]>
  • Loading branch information
Martin Lindsay authored and CQ Bot committed May 29, 2024
1 parent 450bf9c commit 9e4a3af
Show file tree
Hide file tree
Showing 4 changed files with 776 additions and 238 deletions.
2 changes: 1 addition & 1 deletion src/storage/fxfs/platform/src/fuchsia/fxblob/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ impl BlobDirectory {
{
let mut guard = self.volume().pager().recorder();
if let Some(recorder) = &mut (*guard) {
let _ = recorder.record_open(&hash);
let _ = recorder.record_open(blob.0.clone());
}
}
let vmo = blob.create_child_vmo()?;
Expand Down
19 changes: 8 additions & 11 deletions src/storage/fxfs/platform/src/fuchsia/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,6 @@ use {
crate::fuchsia::{
epochs::{Epochs, RefGuard},
errors::map_to_status,
fxblob::blob::FxBlob,
node::FxNode,
profile::Recorder,
},
Expand Down Expand Up @@ -166,7 165,7 @@ pub struct Pager {
// need to wait for page requests for the specific file being flushed, but we should see if we
// need to for performance reasons first.
epochs: Arc<Epochs>,
recorder: Mutex<Option<Recorder>>,
recorder: Mutex<Option<Box<dyn Recorder>>>,
}

// FileHolder is used to retain either a strong or a weak reference to a file. If there are any
Expand Down Expand Up @@ -202,25 201,23 @@ impl Pager {
}

/// Set the current profile recorder, or set to None to not record.
pub fn set_recorder(&self, recorder: Option<Recorder>) {
pub fn set_recorder(&self, recorder: Option<Box<dyn Recorder>>) {
// Drop the old one outside of the lock.
let _ = std::mem::replace(&mut (*self.recorder.lock().unwrap()), recorder);
}

/// Borrow the profile recorder. Used to record file opens.
pub fn recorder(&self) -> MutexGuard<'_, Option<Recorder>> {
pub fn recorder(&self) -> MutexGuard<'_, Option<Box<dyn Recorder>>> {
self.recorder.lock().unwrap()
}

/// Record a range into a profile if one is being recorded.
pub fn record_page_in<P: PagerBacked>(&self, node: Arc<P>, range: Range<u64>) {
if let Ok(blob) = node.into_any().downcast::<FxBlob>() {
let mut recorder_holder = self.recorder.lock().unwrap();
if let Some(recorder) = &mut (*recorder_holder) {
// If the message fails to send, so will all the rest.
if let Err(_) = recorder.record(&blob.root(), range.start) {
*recorder_holder = None;
}
let mut recorder_holder = self.recorder.lock().unwrap();
if let Some(recorder) = &mut (*recorder_holder) {
// If the message fails to send, so will all the rest.
if let Err(_) = recorder.record(node, range.start) {
*recorder_holder = None;
}
}
}
Expand Down
Loading

0 comments on commit 9e4a3af

Please sign in to comment.