Browse Source

Set up tracing subscribers in benchmark example

tags/v0.2.0-candidate
Philipp Oppermann 3 years ago
parent
commit
c9ab38d6bc
Failed to extract signature
5 changed files with 39 additions and 2 deletions
  1. +4
    -0
      Cargo.lock
  2. +2
    -0
      examples/benchmark/node/Cargo.toml
  3. +16
    -2
      examples/benchmark/node/src/main.rs
  4. +2
    -0
      examples/benchmark/sink/Cargo.toml
  5. +15
    -0
      examples/benchmark/sink/src/main.rs

+ 4
- 0
Cargo.lock View File

@@ -281,6 +281,8 @@ dependencies = [
"futures",
"rand",
"tokio",
"tracing",
"tracing-subscriber",
]

[[package]]
@@ -289,6 +291,8 @@ version = "0.1.2"
dependencies = [
"dora-node-api",
"eyre",
"tracing",
"tracing-subscriber",
]

[[package]]


+ 2
- 0
examples/benchmark/node/Cargo.toml View File

@@ -11,3 +11,5 @@ eyre = "0.6.8"
futures = "0.3.21"
rand = "0.8.5"
tokio = { version = "1.20.1", features = ["rt", "macros"] }
tracing = "0.1.36"
tracing-subscriber = "0.3.15"

+ 16
- 2
examples/benchmark/node/src/main.rs View File

@@ -1,9 +1,12 @@
use std::time::Duration;

use dora_node_api::{self, dora_core::config::DataId, DoraNode};
use eyre::Context;
use rand::Rng;
use std::time::Duration;
use tracing_subscriber::Layer;

fn main() -> eyre::Result<()> {
set_up_tracing().wrap_err("failed to set up tracing subscriber")?;

let latency = DataId::from("latency".to_owned());
let throughput = DataId::from("throughput".to_owned());

@@ -56,3 +59,14 @@ fn main() -> eyre::Result<()> {

Ok(())
}

fn set_up_tracing() -> eyre::Result<()> {
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;

let stdout_log = tracing_subscriber::fmt::layer()
.pretty()
.with_filter(tracing::metadata::LevelFilter::DEBUG);
let subscriber = tracing_subscriber::Registry::default().with(stdout_log);
tracing::subscriber::set_global_default(subscriber)
.context("failed to set tracing global subscriber")
}

+ 2
- 0
examples/benchmark/sink/Cargo.toml View File

@@ -8,3 +8,5 @@ edition = "2021"
[dependencies]
dora-node-api = { workspace = true }
eyre = "0.6.8"
tracing = "0.1.36"
tracing-subscriber = "0.3.15"

+ 15
- 0
examples/benchmark/sink/src/main.rs View File

@@ -1,7 +1,11 @@
use dora_node_api::{self, daemon::Event, DoraNode};
use eyre::Context;
use std::time::{Duration, Instant};
use tracing_subscriber::Layer;

fn main() -> eyre::Result<()> {
set_up_tracing().wrap_err("failed to set up tracing subscriber")?;

let (_node, mut events) = DoraNode::init_from_env()?;

// latency is tested first
@@ -74,3 +78,14 @@ fn record_results(
};
println!("{msg}");
}

fn set_up_tracing() -> eyre::Result<()> {
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;

let stdout_log = tracing_subscriber::fmt::layer()
.pretty()
.with_filter(tracing::metadata::LevelFilter::DEBUG);
let subscriber = tracing_subscriber::Registry::default().with(stdout_log);
tracing::subscriber::set_global_default(subscriber)
.context("failed to set tracing global subscriber")
}

Loading…
Cancel
Save