Skip to content

Commit 43c93f4

Browse files
authored
Merge pull request #2039 from CosmWasm/cleanup-heap-profiling
Cleanup heap profiling
2 parents b7cdcb2 + e3633fc commit 43c93f4

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vm/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ staking = ["cosmwasm-std/staking"]
2020
stargate = ["cosmwasm-std/stargate"]
2121
# Use cranelift backend instead of singlepass. This is required for development on Windows.
2222
cranelift = ["wasmer/cranelift"]
23-
# For heap profiling. Only used in "memory" example.
23+
# For heap profiling. Only used in the "heap_profiling" example.
2424
dhat-heap = ["dep:dhat"]
2525

2626
[lib]
@@ -45,9 +45,9 @@ thiserror = "1.0.26"
4545
wasmer = { version = "=4.2.5", default-features = false, features = ["cranelift", "singlepass"] }
4646
wasmer-middlewares = "=4.2.5"
4747
strum = { version = "0.25.0", default-features = false, features = ["derive"] }
48-
# For heap profiling. Only used in "memory" example. This has to be a non-dev dependency
48+
# For heap profiling. Only used in the "heap_profiling" example. This has to be a non-dev dependency
4949
# because cargo currently does not support optional dev-dependencies.
50-
dhat = { version = "0.3.2", optional = true }
50+
dhat = { version = "0.3.3", optional = true }
5151

5252
# Dependencies that we do not use ourself. We add those entries
5353
# to bump the min version of them.
@@ -77,8 +77,8 @@ name = "main"
7777
harness = false
7878

7979
[[example]]
80-
name = "memory"
81-
path = "examples/memory.rs"
80+
name = "heap_profiling"
81+
path = "examples/heap_profiling.rs"
8282

8383
[profile.release]
8484
debug = 1

packages/vm/examples/memory.rs renamed to packages/vm/examples/heap_profiling.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Run with
2-
// cargo run --features dhat-heap --example memory --release
2+
// 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,12 +101,12 @@ 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(
107108
TempDir::new().unwrap().into_path(),
108-
capabilities_from_csv("iterator,staking,stargate"),
109+
capabilities_from_csv("iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0"),
109110
MEMORY_CACHE_SIZE,
110111
DEFAULT_MEMORY_LIMIT,
111112
);
@@ -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..10_000))
198+
.default_value("30"),
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)