1
1
// Run with
2
- // cargo run --features dhat-heap --example memory --release
2
+ // cargo run --features dhat-heap --example heap_profiling --release
3
3
4
- use std:: time:: SystemTime ;
4
+ use std:: time:: { Duration , SystemTime } ;
5
5
use tempfile:: TempDir ;
6
6
use time:: { format_description:: well_known:: Rfc3339 , OffsetDateTime } ;
7
7
@@ -12,12 +12,13 @@ use cosmwasm_vm::{
12
12
Size ,
13
13
} ;
14
14
15
+ use clap:: { Arg , Command } ;
16
+
15
17
#[ cfg( feature = "dhat-heap" ) ]
16
18
#[ global_allocator]
17
19
static ALLOC : dhat:: Alloc = dhat:: Alloc ;
18
20
19
21
/// Number of seconds after which the test stops
20
- const END_AFTER : u64 = 2 * 60 ; // seconds
21
22
const ROUNDS : usize = 1024 ;
22
23
const ROUND_LEN : usize = 16 ;
23
24
@@ -100,12 +101,12 @@ fn contracts() -> Vec<Contract> {
100
101
}
101
102
102
103
#[ allow( clippy:: collapsible_else_if) ]
103
- fn app ( ) {
104
+ fn app ( runtime : u64 ) {
104
105
let start_time = SystemTime :: now ( ) ;
105
106
106
107
let options = CacheOptions :: new (
107
108
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 " ) ,
109
110
MEMORY_CACHE_SIZE ,
110
111
DEFAULT_MEMORY_LIMIT ,
111
112
) ;
@@ -129,11 +130,7 @@ fn app() {
129
130
let cache: Cache < MockApi , MockStorage , MockQuerier > = unsafe { Cache :: new ( options) . unwrap ( ) } ;
130
131
for round in 0 ..ROUNDS {
131
132
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)
137
134
{
138
135
eprintln ! ( "Round {round}. End time reached. Ending the process" ) ;
139
136
@@ -191,8 +188,22 @@ fn now_rfc3339() -> String {
191
188
}
192
189
193
190
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
+
194
205
#[ cfg( feature = "dhat-heap" ) ]
195
206
let _profiler = dhat:: Profiler :: new_heap ( ) ;
196
207
197
- app ( ) ;
208
+ app ( * runtime ) ;
198
209
}
0 commit comments