Skip to content

Commit 8928b43

Browse files
committed
extract InstanceEnv::console_timer_end
1 parent 551bba2 commit 8928b43

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

crates/core/src/host/instance_env.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::scheduler::{get_schedule_from_row, ScheduleError, Scheduler};
22
use crate::database_logger::{BacktraceProvider, LogLevel, Record};
33
use crate::db::relational_db::{MutTx, RelationalDB};
44
use crate::error::{DBError, DatastoreError, IndexError, NodesError};
5+
use crate::host::wasm_common::TimingSpan;
56
use crate::replica_context::ReplicaContext;
67
use core::mem;
78
use parking_lot::{Mutex, MutexGuard};
@@ -189,6 +190,22 @@ impl InstanceEnv {
189190
);
190191
}
191192

193+
/// End a console timer by logging the span at INFO level.
194+
pub fn console_timer_end(&self, span: &TimingSpan, function: Option<&str>, bt: &dyn BacktraceProvider) -> RtResult<u32> {
195+
let elapsed = span.start.elapsed();
196+
let message = format!("Timing span {:?}: {:?}", &span.name, elapsed);
197+
198+
let record = Record {
199+
ts: chrono::Utc::now(),
200+
target: None,
201+
filename: None,
202+
line_number: None,
203+
function,
204+
message: &message,
205+
};
206+
self.console_log(LogLevel::Info, &record, bt);
207+
}
208+
192209
/// Project `cols` in `row_ref` encoded in BSATN to `buffer`
193210
/// and return the full length of the BSATN.
194211
///

crates/core/src/host/wasmtime/wasm_instance_env.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,23 +1199,11 @@ impl WasmInstanceEnv {
11991199
return Ok(errno::NO_SUCH_CONSOLE_TIMER.get().into());
12001200
};
12011201

1202-
let elapsed = span.start.elapsed();
1203-
let message = format!("Timing span {:?}: {:?}", &span.name, elapsed);
12041202
let function = caller.data().log_record_function();
1205-
1206-
let record = Record {
1207-
ts: chrono::Utc::now(),
1208-
target: None,
1209-
filename: None,
1210-
line_number: None,
1211-
function,
1212-
message: &message,
1213-
};
1214-
caller.data().instance_env.console_log(
1215-
crate::database_logger::LogLevel::Info,
1216-
&record,
1217-
&caller.as_context(),
1218-
);
1203+
caller
1204+
.data()
1205+
.instance_env
1206+
.console_timer_end(&span, function, &caller.as_context());
12191207
Ok(0)
12201208
})
12211209
}

0 commit comments

Comments
 (0)