Skip to content

Commit ef716ad

Browse files
committed
Add runtime argument
1 parent 951198f commit ef716ad

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/vm/examples/heap_profiling.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Run with
22
// cargo run --features dhat-heap --example heap_profiling --release
33

4-
use std::time::SystemTime;
4+
use std::time::{Duration, SystemTime};
55
use tempfile::TempDir;
66
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
77

@@ -12,12 +12,13 @@ use cosmwasm_vm::{
1212
Size,
1313
};
1414

15+
use clap::{Arg, Command};
16+
1517
#[cfg(feature = "dhat-heap")]
1618
#[global_allocator]
1719
static ALLOC: dhat::Alloc = dhat::Alloc;
1820

1921
/// Number of seconds after which the test stops
20-
const END_AFTER: u64 = 2 * 60; // seconds
2122
const ROUNDS: usize = 1024;
2223
const ROUND_LEN: usize = 16;
2324

@@ -100,7 +101,7 @@ fn contracts() -> Vec<Contract> {
100101
}
101102

102103
#[allow(clippy::collapsible_else_if)]
103-
fn app() {
104+
fn app(runtime: u64) {
104105
let start_time = SystemTime::now();
105106

106107
let options = CacheOptions::new(
@@ -129,11 +130,7 @@ fn app() {
129130
let cache: Cache<MockApi, MockStorage, MockQuerier> = unsafe { Cache::new(options).unwrap() };
130131
for round in 0..ROUNDS {
131132
for _ in 0..ROUND_LEN {
132-
if SystemTime::now()
133-
.duration_since(start_time)
134-
.unwrap()
135-
.as_secs()
136-
> END_AFTER
133+
if SystemTime::now().duration_since(start_time).unwrap() > Duration::from_secs(runtime)
137134
{
138135
eprintln!("Round {round}. End time reached. Ending the process");
139136

@@ -191,8 +188,22 @@ fn now_rfc3339() -> String {
191188
}
192189

193190
pub fn main() {
191+
let matches = Command::new("Heap profiling")
192+
.version("0.0.0")
193+
.arg(
194+
Arg::new("runtime")
195+
.long("runtime")
196+
.help("Time in seconds how long the tests should be running")
197+
.value_parser(clap::value_parser!(u64).range(1..3600))
198+
.default_value("60"),
199+
)
200+
.get_matches();
201+
let runtime = matches
202+
.get_one::<u64>("runtime")
203+
.expect("Error parsing time argument");
204+
194205
#[cfg(feature = "dhat-heap")]
195206
let _profiler = dhat::Profiler::new_heap();
196207

197-
app();
208+
app(*runtime);
198209
}

0 commit comments

Comments
 (0)