Skip to content

Commit 10ba891

Browse files
committed
making a start
1 parent 5885e1b commit 10ba891

File tree

4 files changed

+148
-22
lines changed

4 files changed

+148
-22
lines changed

Cargo.lock

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

boa/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ regex = "1.3.6"
2424
# Optional Dependencies
2525
wasm-bindgen = { version = "0.2.59", optional = true }
2626
serde = { version = "1.0.105", features = ["derive"], optional = true }
27+
measureme = { version = "0.7.1" }
2728

2829
[dev-dependencies]
2930
criterion = "0.3.1"

boa/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
clippy::missing_errors_doc,
2626
clippy::as_conversions
2727
)]
28+
#![feature(thread_id_value)]
2829

2930
pub mod builtins;
3031
pub mod environment;
3132
pub mod exec;
33+
pub mod profiler;
3234
pub mod realm;
3335
pub mod syntax;
3436
#[cfg(feature = "wasm-bindgen")]
@@ -39,6 +41,7 @@ pub use crate::wasm::*;
3941
use crate::{
4042
builtins::value::ResultValue,
4143
exec::{Executor, Interpreter},
44+
profiler::MyProfiler,
4245
realm::Realm,
4346
syntax::{ast::node::Node, lexer::Lexer, parser::Parser},
4447
};
@@ -78,6 +81,10 @@ pub fn forward(engine: &mut Interpreter, src: &str) -> String {
7881
/// If the interpreter fails parsing an error value is returned instead (error object)
7982
pub fn forward_val(engine: &mut Interpreter, src: &str) -> ResultValue {
8083
// Setup executor
84+
let profiler = MyProfiler::new();
85+
profiler.start_event("Parser");
86+
let res = parser_expr(src).unwrap();
87+
8188
match parser_expr(src) {
8289
Ok(expr) => engine.run(&expr),
8390
Err(e) => {

boa/src/profiler.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![allow(missing_copy_implementations, missing_debug_implementations)]
2+
3+
use measureme::{EventId, Profiler, TimingGuard};
4+
use std::path::Path;
5+
6+
/// MmapSerializatioSink is faster on macOS and Linux
7+
/// but FileSerializationSink is faster on Windows
8+
#[cfg(not(windows))]
9+
type SerializationSink = measureme::MmapSerializationSink;
10+
#[cfg(windows)]
11+
type SerializationSink = measureme::FileSerializationSink;
12+
13+
pub struct MyProfiler {
14+
profiler: Profiler<SerializationSink>,
15+
}
16+
17+
impl MyProfiler {
18+
pub fn start_event(&self, label: &str) -> TimingGuard<'_, SerializationSink> {
19+
let kind = self.profiler.alloc_string("Generic");
20+
let lab = EventId::from_label(self.profiler.alloc_string(label));
21+
let thread_id = std::thread::current().id().as_u64() as u32;
22+
self.profiler
23+
.start_recording_interval_event(kind, lab, thread_id)
24+
}
25+
26+
pub fn new() -> MyProfiler {
27+
let profiler = Profiler::new(Path::new("./my_trace")).unwrap();
28+
MyProfiler { profiler }
29+
}
30+
}

0 commit comments

Comments
 (0)