Skip to content

Commit

Permalink
port Trace definition to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Dec 15, 2023
1 parent 4816b40 commit 617c6cb
Show file tree
Hide file tree
Showing 7 changed files with 799 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/**
**/.DS_Store
.DS_Store
performance.db.ndjson
performance.ndjson
performance.ndjson
target/
223 changes: 223 additions & 0 deletions crates/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions crates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[workspace]
members = ["replay_gen"]
resolver = "2"

[profile.release]
# Optimize all the things!
opt-level = 3
lto = "fat"
overflow-checks = true
# Some debug info for profiling.
debug = 1

[profile.test]
# Speed-up test execution and avoid stack overflow with deeply-nested ASTs.
opt-level = 2
lto = "thin"
9 changes: 9 additions & 0 deletions crates/replay_gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "replay_gen"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tempfile = "3.2.0"
1 change: 1 addition & 0 deletions crates/replay_gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod trace;
29 changes: 29 additions & 0 deletions crates/replay_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

use replay_gen::trace;

fn main() -> io::Result<()> {
// FIXME: use clap to parse args. currently just panics.
let args: Vec<String> = env::args().collect();
let newline = &args[1];
let path = Path::new(newline);
let file = File::open(&path)?;
let reader = io::BufReader::new(file);

let mut lines = reader.lines().peekable();

while let Some(line) = lines.next() {
let line = line?;
let event = line.parse::<trace::WasmEvent>()?;
// hack to print the last event without a newline that matches the current behavior.
if lines.peek().is_some() {
println!("{:?}", event);
} else {
print!("{:?}", event);
}
}
Ok(())
}
Loading

0 comments on commit 617c6cb

Please sign in to comment.