Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): add minitrace to RisingLight #550

Merged
merged 6 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "0.1.0"
default = ["jemalloc"]
simd = []
jemalloc = ["tikv-jemallocator"]
enable_tracing = []

[dependencies]
anyhow = "1"
Expand Down Expand Up @@ -56,6 +57,7 @@ tokio = { version = "1", features = ["full"] }
tokio-util = "0.7"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "parking_lot"] }
minitrace = "0.4.0"

[dev-dependencies]
criterion = { version = "0.3", features = ["async_tokio"] }
Expand Down
26 changes: 20 additions & 6 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::sync::Arc;

use futures::TryStreamExt;
use minitrace::prelude::*;
use risinglight_proto::rowset::block_statistics::BlockStatisticsType;
use tracing::debug;

Expand Down Expand Up @@ -193,12 +194,21 @@ impl Database {
let optimized_plan = optimizer.optimize(logical_plan);
debug!("{:#?}", optimized_plan);

let executor_builder = ExecutorBuilder::new(context.clone(), self.storage.clone());
let executor = executor_builder.clone().build(optimized_plan);
let output: Vec<DataChunk> = executor.try_collect().await.map_err(|e| {
debug!("error: {}", e);
e
})?;
let mut executor_builder = ExecutorBuilder::new(context.clone(), self.storage.clone());
let executor = executor_builder.build(optimized_plan);

let (root, _collector) = Span::root("root");
let output: Vec<DataChunk> = if cfg!(feature = "enable_tracing") {
executor.try_collect().in_span(root).await.map_err(|e| {
debug!("error: {}", e);
e
})?
} else {
executor.try_collect().await.map_err(|e| {
debug!("error: {}", e);
e
})?
};
for chunk in &output {
debug!("output:\n{}", chunk);
}
Expand All @@ -207,6 +217,10 @@ impl Database {
chunk.set_header(column_names);
}
outputs.push(chunk);
#[cfg(feature = "enable_tracing")]
let records: Vec<SpanRecord> = _collector.collect().await;
#[cfg(feature = "enable_tracing")]
println!("{records:#?}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it an optional feature? Either using https://doc.rust-lang.org/cargo/reference/features.html and #[cfg(feature = enable_tracing)], or use cli arg to specify whether to enable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha

}
Ok(outputs)
}
Expand Down
Loading