mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 22:25:40 +00:00
Update call_trace middleware to include a counter.
This commit is contained in:
parent
8ee4b7f7b0
commit
2e1fb7abca
@ -2,8 +2,19 @@ use wasmer_runtime_core::{
|
||||
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
|
||||
module::ModuleInfo,
|
||||
};
|
||||
use std::sync::{Arc, atomic::{Ordering, AtomicU32}};
|
||||
|
||||
pub struct CallTrace;
|
||||
pub struct CallTrace {
|
||||
counter: Arc<AtomicU32>,
|
||||
}
|
||||
|
||||
impl CallTrace {
|
||||
pub fn new() -> CallTrace {
|
||||
CallTrace {
|
||||
counter: Arc::new(AtomicU32::new(0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FunctionMiddleware for CallTrace {
|
||||
type Error = String;
|
||||
@ -13,10 +24,13 @@ impl FunctionMiddleware for CallTrace {
|
||||
_module_info: &ModuleInfo,
|
||||
sink: &mut EventSink<'a, 'b>,
|
||||
) -> Result<(), Self::Error> {
|
||||
let counter = self.counter.clone();
|
||||
|
||||
match op {
|
||||
Event::Internal(InternalEvent::FunctionBegin(id)) => sink.push(Event::Internal(
|
||||
InternalEvent::Breakpoint(Box::new(move |_| {
|
||||
eprintln!("func ({})", id);
|
||||
let idx = counter.fetch_add(1, Ordering::SeqCst);
|
||||
eprintln!("[{}] func ({})", idx, id);
|
||||
Ok(())
|
||||
})),
|
||||
)),
|
||||
|
Loading…
Reference in New Issue
Block a user