Skip to content

Commit

Permalink
feat(storage): add latency metrics, minor debug message change and mi… (
Browse files Browse the repository at this point in the history
#2112)

feat(storage): add latency metrics, minor debug message change and minor fix
  • Loading branch information
DvirYo-starkware authored Jun 17, 2024
1 parent b9c9593 commit dd3b492
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions crates/papyrus_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ pub struct StorageTxn<'env, Mode: TransactionKind> {

impl<'env> StorageTxn<'env, RW> {
/// Commits the changes made in the transaction to the storage.
#[latency_histogram("storage_commit_latency_seconds", false)]
pub fn commit(self) -> StorageResult<()> {
self.file_handlers.flush();
Ok(self.txn.commit()?)
Expand Down Expand Up @@ -701,11 +702,15 @@ impl FileHandlers<RW> {
}

// TODO(dan): Consider 1. flushing only the relevant files, 2. flushing concurrently.
#[latency_histogram("storage_file_handler_flush_latency_seconds", false)]
fn flush(&self) {
debug!("Flushing the mmap files.");
self.thin_state_diff.flush();
self.contract_class.flush();
self.casm.flush();
self.deprecated_contract_class.flush();
self.transaction_output.flush();
self.transaction.flush();
}

// Appends a thin transaction output to the corresponding file and returns its location.
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/mmap_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<V: ValueSerde> MMapFile<V> {

/// Flushes the mmap to the file.
fn flush(&mut self) {
debug!("Flushing mmap to file");
trace!("Flushing mmap to file");
self.mmap.flush().expect("Failed to flush the mmap");
self.should_flush = false;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<V: ValueSerde + Debug> Writer<V> for FileHandler<V, RW> {
{
let mut mmap_file = self.mmap_file.lock().expect("Lock should not be poisoned");
offset = mmap_file.offset;
debug!("Inserting object at offset: {}", offset);
trace!("Inserting object at offset: {}", offset);
let mmap_slice = &mut mmap_file.mmap[offset..];
mmap_slice[..len].copy_from_slice(&serialized);
mmap_file
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_storage/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ fn write_replaced_classes<'env>(
Ok(())
}

#[latency_histogram("storage_write_storage_diffs_latency_seconds", true)]
#[latency_histogram("storage_write_storage_diffs_latency_seconds", false)]
fn write_storage_diffs<'env>(
storage_diffs: &IndexMap<ContractAddress, IndexMap<StorageKey, Felt>>,
txn: &DbTransaction<'env, RW>,
Expand Down

0 comments on commit dd3b492

Please sign in to comment.