-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep derive_default_enum feature and add rusty-fork
- Loading branch information
Showing
4 changed files
with
96 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tracing-chrometrace" | ||
version = "0.1.16" | ||
version = "0.1.17" | ||
edition = "2018" | ||
|
||
authors = ["Youseok Yang <[email protected]>"] | ||
|
@@ -21,8 +21,6 @@ serde = { version = "1.0", features = ["derive"] } | |
serde_json = "1.0" | ||
strum = { version = "0.22", features = ["derive"] } | ||
strum_macros = "0.22" | ||
temp-file = "0.1.7" | ||
tempfile = "3.3.0" | ||
|
||
tracing = "0.1.34" | ||
tracing-subscriber = { version = "0.3.11", features = ["fmt", "std", "env-filter"] } | ||
|
@@ -32,6 +30,8 @@ criterion = { version = "0.3", features = ["html_reports"] } | |
crossbeam-queue = "0.3.5" | ||
tracing-appender = "0.2.2" | ||
tracing-chrome = "0.5.0" | ||
temp-file = "0.1.7" | ||
rusty-fork = "0.3.0" | ||
|
||
[[bench]] | ||
name = "benchmark" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,79 @@ | ||
use itertools::Itertools; | ||
use std::{ | ||
fs::{self, File}, | ||
thread, | ||
time::Duration, | ||
}; | ||
use tempfile; | ||
use rusty_fork::rusty_fork_test; | ||
|
||
use tracing_appender::non_blocking::NonBlocking; | ||
use tracing_chrometrace::{ChromeEvent, ChromeLayer}; | ||
use tracing_subscriber::prelude::*; | ||
|
||
#[test] | ||
fn test_init() { | ||
let (writer, _guard) = ChromeLayer::with_writer(std::io::stdout); | ||
|
||
tracing_subscriber::registry().with(writer).init(); | ||
rusty_fork_test! { | ||
#[test] | ||
fn test_init() { | ||
let (writer, _guard) = ChromeLayer::with_writer(std::io::stdout); | ||
|
||
tracing::info!(target = "chrome_layer", message = "hello"); | ||
} | ||
|
||
#[test] | ||
fn test_concurrent_write() { | ||
let file = temp_file::empty(); | ||
let (writer, worker) = NonBlocking::new(File::create(file.path()).unwrap()); | ||
let (writer, guard) = ChromeLayer::with_writer(writer); | ||
|
||
let iterations = 1000; | ||
|
||
tracing_subscriber::registry().with(writer).init(); | ||
|
||
let handle = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 0, index = i); | ||
} | ||
}); | ||
|
||
let handle2 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 1, index = i); | ||
} | ||
}); | ||
tracing_subscriber::registry().with(writer).init(); | ||
|
||
let handle3 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 2, index = i); | ||
} | ||
}); | ||
tracing::info!(target = "chrome_layer", message = "hello"); | ||
} | ||
|
||
let handle4 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 3, index = i); | ||
#[test] | ||
fn test_concurrent_write() { | ||
let file = temp_file::empty(); | ||
let (writer, worker) = NonBlocking::new(File::create(file.path()).unwrap()); | ||
let (writer, guard) = ChromeLayer::with_writer(writer); | ||
|
||
let iterations = 1000; | ||
|
||
tracing_subscriber::registry().with(writer).init(); | ||
|
||
let handle = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 0, index = i); | ||
} | ||
}); | ||
|
||
let handle2 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 1, index = i); | ||
} | ||
}); | ||
|
||
let handle3 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 2, index = i); | ||
} | ||
}); | ||
|
||
let handle4 = thread::spawn(move || { | ||
for i in 0..iterations { | ||
tracing::info!(thread = 3, index = i); | ||
} | ||
}); | ||
|
||
handle.join().unwrap(); | ||
handle2.join().unwrap(); | ||
handle3.join().unwrap(); | ||
handle4.join().unwrap(); | ||
|
||
drop(guard); | ||
drop(worker); | ||
|
||
let events = fs::read_to_string(file.path()).unwrap(); | ||
let events: Vec<ChromeEvent> = serde_json::from_str::<Vec<ChromeEvent>>(&events).unwrap(); | ||
|
||
let expected: Vec<i32> = (0..iterations).collect(); | ||
|
||
for i in 0..4 { | ||
let found: Vec<i32> = events | ||
.iter() | ||
.filter(|e| e.args["thread"] == i.to_string()) | ||
.map(|e| e.args["index"].parse().unwrap()) | ||
.collect(); | ||
|
||
assert_eq!(expected, found) | ||
} | ||
}); | ||
|
||
handle.join(); | ||
handle2.join(); | ||
handle3.join(); | ||
handle4.join(); | ||
|
||
drop(guard); | ||
drop(worker); | ||
|
||
let events = fs::read_to_string(file.path()).unwrap(); | ||
let events: Vec<ChromeEvent> = serde_json::from_str::<Vec<ChromeEvent>>(&events).unwrap(); | ||
|
||
let expected: Vec<i32> = (0..iterations).collect(); | ||
|
||
for i in 0..4 { | ||
let found: Vec<i32> = events | ||
.iter() | ||
.filter(|e| e.args["thread"] == i.to_string()) | ||
.map(|e| e.args["index"].parse().unwrap()) | ||
.collect(); | ||
|
||
assert_eq!(expected, found) | ||
} | ||
} |