Skip to content

Commit

Permalink
update the way outputfile gets written, always ammending the name and…
Browse files Browse the repository at this point in the history
… timestamp
  • Loading branch information
lanvidr committed Jan 24, 2024
1 parent e4ecab1 commit 1bcc42e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
9 changes: 2 additions & 7 deletions crates/sui-replay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use transaction_provider::{FuzzStartPoint, TransactionSource};
use crate::replay::ExecutionSandboxState;
use crate::replay::LocalExec;
use crate::replay::ProtocolVersionSummary;
use move_vm_config::runtime::get_default_output_filepath;
use std::env;
use std::io::BufRead;
use std::path::PathBuf;
Expand Down Expand Up @@ -376,13 +377,7 @@ pub async fn execute_replay_command(
protocol_version,
profile_output,
} => {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Error getting system time")
.as_nanos();
let mut default_name = std::path::PathBuf::from(".");
default_name.push(format!("gas_profile_{}_{}.json", tx_digest, now));
let output_path = profile_output.or(Some(default_name));
let output_path = profile_output.or(Some(get_default_output_filepath()));

let tx_digest = TransactionDigest::from_str(&tx_digest)?;
info!("Executing tx: {}", tx_digest);
Expand Down
4 changes: 2 additions & 2 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ pub enum SuiClientCommands {
#[arg(long, short)]
tx_digest: String,

/// If specified, overrides the filepath of the output profile, for example -- /temp/my_profile.json
/// If an output filepath is not specified, it will output a file `gas_profile_{tx_digest}_{unix_timestamp}.json`
/// If specified, overrides the filepath of the output profile, for example -- /temp/my_profile_name.json will write output to `/temp/my_profile_name_{tx_digest}_{unix_timestamp}.json`
/// If an output filepath is not specified, it will output a file `gas_profile_{tx_digest}_{unix_timestamp}.json` to the working directory
#[arg(long, short)]
profile_output: Option<PathBuf>,
},
Expand Down
19 changes: 18 additions & 1 deletion external-crates/move/crates/move-vm-config/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Default for VMRuntimeLimitsConfig {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct VMProfilerConfig {
/// User configured full path override
pub full_path: std::path::PathBuf,
Expand All @@ -76,6 +76,17 @@ pub struct VMProfilerConfig {
pub use_long_function_name: bool,
}

#[cfg(debug_assertions)]
impl std::default::Default for VMProfilerConfig {
fn default() -> Self {
Self {
full_path: get_default_output_filepath(),
track_bytecode_instructions: false,
use_long_function_name: false,
}
}
}

#[cfg(feature = "gas-profiler")]
impl VMProfilerConfig {
pub fn get_default_config_if_enabled() -> Option<VMProfilerConfig> {
Expand All @@ -86,3 +97,9 @@ impl VMProfilerConfig {
}
}
}

pub fn get_default_output_filepath() -> std::path::PathBuf {
let mut default_name = std::path::PathBuf::from(".");
default_name.push("gas_profile.json");
default_name
}
23 changes: 22 additions & 1 deletion external-crates/move/crates/move-vm-profiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,28 @@ impl GasProfiler {
return;
}

let p = &config.full_path.clone();
let mut p = config.full_path.clone();
let file_prefix = match p.file_stem() {
Some(fp) => fp.to_str().unwrap_or("gas_profile"),
None => "gas_profile",
};
let file_extension = match p.extension() {
Some(e) => e.to_str().unwrap_or("json"),
None => "json",
};
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Error getting system time")
.as_nanos();
let filename = format!(
"{}_{}_{}.{}",
file_prefix,
self.name.clone(),
now,
file_extension
);
p.set_file_name(filename);

let path_str = p.as_os_str().to_string_lossy().to_string();
let mut file = std::fs::File::create(p).expect("Unable to create file");

Expand Down

0 comments on commit 1bcc42e

Please sign in to comment.