Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
62f4df9
Add span recording to tracing implementation
mattrutherford Apr 27, 2020
e5aa529
Add tracing proxy
mattrutherford Apr 28, 2020
e71eb09
switch to rustc_hash::FxHashMap
mattrutherford Apr 29, 2020
db69268
Replace lazy_static and hashmap with thread_local and vec.
mattrutherford Apr 29, 2020
b43015f
fix marking valid span as invalid while removing invalid spans
mattrutherford Apr 29, 2020
dba7d55
refactor, add wasm_tracing module in `support`
mattrutherford May 6, 2020
5e86ef6
update registered spans
mattrutherford May 6, 2020
35706ca
tidy up
mattrutherford May 6, 2020
1388002
typos
mattrutherford May 6, 2020
41964e7
refactor
mattrutherford May 6, 2020
ad81d3b
update flag name to signal lost trace - `is_valid_trace`
mattrutherford May 6, 2020
2cb66bf
update flag name to signal lost trace - `is_valid_trace`
mattrutherford May 6, 2020
03b7b6e
update docs
mattrutherford May 6, 2020
16b018c
update docs
mattrutherford May 6, 2020
d2af83d
Use tracing Field recording to store the actual `name` and `target`
mattrutherford May 7, 2020
9f8baf2
fix debug log in subscriber + small refactor
mattrutherford May 7, 2020
1199f36
add tests
mattrutherford May 11, 2020
0c61f79
handle misuse in case trying to exit span not held
mattrutherford May 11, 2020
8061da5
Implement filter for wasm traces, simplify field recording for primit…
mattrutherford May 11, 2020
2097aca
remove superfluous warning
mattrutherford May 11, 2020
1ef18e6
update docs
mattrutherford May 11, 2020
60e0b60
Merge branch 'master' into mr-sp-tracing
mattrutherford May 11, 2020
cd8bed8
Merge branch 'master' into mr-sp-tracing
mattrutherford May 12, 2020
460d24d
Update primitives/tracing/src/proxy.rs
mattrutherford May 13, 2020
85bdbe0
Apply suggestions from code review
mattrutherford May 13, 2020
b9d1fdf
update docs, apply suggestions
mattrutherford May 14, 2020
b66bb33
move Proxy from thread_local to `Extension`, rename macro
mattrutherford May 14, 2020
afa511d
fix test
mattrutherford May 15, 2020
93a03a8
unify native & wasm span macro calls
mattrutherford May 15, 2020
2126d8e
implement wasm tracing control facility in primitives and frame
mattrutherford May 15, 2020
0d48517
add cli flag `--wasm-tracing`
mattrutherford May 15, 2020
e01ae89
fix
mattrutherford May 15, 2020
2db5f89
switch to `Option<u4>` (possible performance degradation), switch
mattrutherford May 15, 2020
c9c7e9c
performance improvement using u64 vs Option<u64>
mattrutherford May 15, 2020
e3bdb79
performance improvement moving concat to client
mattrutherford May 15, 2020
10a07a6
update docs
mattrutherford May 18, 2020
2b73ed7
Update client/cli/src/params/import_params.rs
mattrutherford May 18, 2020
cff0aa2
performance improvement
mattrutherford May 18, 2020
27c8a8f
Merge remote-tracking branch 'origin/mr-sp-tracing' into mr-sp-tracing
mattrutherford May 18, 2020
70e6315
Revert "performance improvement"
mattrutherford May 18, 2020
dc335e9
small refactor
mattrutherford May 18, 2020
955fa15
formatting
mattrutherford May 18, 2020
cd563c3
bump impl_version
mattrutherford May 18, 2020
1bc601f
Update client/cli/src/config.rs
mattrutherford May 19, 2020
691129d
Merge branch 'master' into mr-sp-tracing
mattrutherford May 19, 2020
e78dd7e
Merge branch 'master' into mr-sp-tracing
mattrutherford May 20, 2020
22bb40f
Merge branch 'master' into mr-sp-tracing
mattrutherford May 21, 2020
a63e6d5
update docs
mattrutherford May 21, 2020
88d3da1
Merge branch 'master' into mr-sp-tracing
mattrutherford May 28, 2020
7228358
small fixes, remove pub static
mattrutherford May 28, 2020
d735529
nit
mattrutherford May 29, 2020
de94f07
add integration tests and refactor Subscriber
mattrutherford Jun 1, 2020
8901340
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 1, 2020
179a515
tests
mattrutherford Jun 1, 2020
a2fbef3
revert formatting
mattrutherford Jun 1, 2020
74ec338
try fix test that works locally but not in CI
mattrutherford Jun 1, 2020
749657b
try fix test that works locally but not in CI
mattrutherford Jun 1, 2020
248f767
debug test that works locally but not in CI
mattrutherford Jun 1, 2020
19cf0f9
fix test that works locally but not in CI
mattrutherford Jun 1, 2020
ffe508a
remove pub visibility from bool in runtime
mattrutherford Jun 3, 2020
d5ba777
make TracingSpanGuard #[cfg(not(feature = "std"))], update docs, comm…
mattrutherford Jun 4, 2020
25e24c4
make TracingProxy drop implementation conditional on !empty state
mattrutherford Jun 4, 2020
da72fbd
add docs for TraceHandler
mattrutherford Jun 4, 2020
f7adde5
remove blank line
mattrutherford Jun 4, 2020
bed5bcb
update expect message
mattrutherford Jun 4, 2020
6f3602e
update tests
mattrutherford Jun 4, 2020
31b4cc1
merge master
mattrutherford Jun 4, 2020
1f016b9
rename cli option to tracing_enable_wasm
mattrutherford Jun 4, 2020
2a48d0a
rename cli option to tracing_enable_wasm
mattrutherford Jun 4, 2020
01693e0
fix
mattrutherford Jun 4, 2020
19d832c
merge master
mattrutherford Jun 9, 2020
a17775c
ensure wasm-tracing features are wasm only
mattrutherford Jun 9, 2020
2aa7c72
bump impl_version
mattrutherford Jun 9, 2020
3b7044d
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 9, 2020
bc9ec21
bump impl_version
mattrutherford Jun 9, 2020
32b8e36
add `"pallet-scheduler/std"` to `[features]` `std` in node/runtime
mattrutherford Jun 9, 2020
9835a01
refactor service to remove sp_tracing dependency
mattrutherford Jun 10, 2020
50e4c9c
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 10, 2020
8b16881
refactor: line width, trait bounds
mattrutherford Jun 10, 2020
068fd94
improve LogTraceHandler output
mattrutherford Jun 10, 2020
14a90ae
fix test
mattrutherford Jun 10, 2020
95b8832
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 10, 2020
b822794
improve tracing log output
mattrutherford Jun 11, 2020
157a639
Apply suggestions from code review
bkchr Jun 11, 2020
88c3d71
Apply suggestions from code review
mattrutherford Jun 15, 2020
4150780
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 15, 2020
07a0c56
Merge branch 'mr-sp-tracing' of github.com:paritytech/substrate into …
mattrutherford Jun 15, 2020
c36fc2a
swap wasm indication from trace name to a separate value
mattrutherford Jun 15, 2020
ca77a6a
Merge branch 'master' into mr-sp-tracing
mattrutherford Jun 15, 2020
d9ebb3b
Update client/tracing/src/lib.rs
bkchr Jun 15, 2020
1811e05
add docs
mattrutherford Jun 16, 2020
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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ targets = ["x86_64-unknown-linux-gnu"]
erased-serde = "0.3.9"
log = { version = "0.4.8" }
parking_lot = "0.10.0"
rustc-hash = "1.1.0"
serde = "1.0.101"
serde_json = "1.0.41"
slog = { version = "2.5.2", features = ["nested-values"] }
tracing-core = "0.1.7"

rustc-hash = "1.1.0"

sc-telemetry = { version = "2.0.0-dev", path = "../telemetry" }
sp-tracing = { version = "2.0.0-dev", path = "../../primitives/tracing" }

[dev-dependencies]
tracing = "0.1.10"
29 changes: 20 additions & 9 deletions client/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use tracing_core::{

use sc_telemetry::{telemetry, SUBSTRATE_INFO};

use sp_tracing::proxy::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER};

/// Used to configure how to receive the metrics
#[derive(Debug, Clone)]
pub enum TracingReceiver {
Expand All @@ -61,8 +63,8 @@ impl Default for TracingReceiver {
#[derive(Debug)]
struct SpanDatum {
id: u64,
name: &'static str,
target: &'static str,
name: String,
target: String,
level: Level,
line: u32,
start_time: Instant,
Expand All @@ -71,7 +73,7 @@ struct SpanDatum {
}

#[derive(Clone, Debug)]
struct Visitor(Vec<(String, String)>);
struct Visitor(FxHashMap<String, String>);

impl Visit for Visitor {
fn record_i64(&mut self, field: &Field, value: i64) {
Expand All @@ -87,7 +89,7 @@ impl Visit for Visitor {
}

fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
self.0.push((field.name().to_string(), format!("{:?}",value)));
self.0.insert(field.name().to_string(), format!("{:?}",value));
}
}

Expand Down Expand Up @@ -186,12 +188,12 @@ impl Subscriber for ProfilingSubscriber {

fn new_span(&self, attrs: &Attributes<'_>) -> Id {
let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let mut values = Visitor(Vec::new());
let mut values = Visitor(FxHashMap::default());
attrs.record(&mut values);
let span_datum = SpanDatum {
id,
name: attrs.metadata().name(),
target: attrs.metadata().target(),
name: attrs.metadata().name().to_owned(),
target: attrs.metadata().target().to_owned(),
level: attrs.metadata().level().clone(),
line: attrs.metadata().line().unwrap_or(0),
start_time: Instant::now(),
Expand Down Expand Up @@ -235,8 +237,17 @@ impl Subscriber for ProfilingSubscriber {

fn try_close(&self, span: Id) -> bool {
let mut span_data = self.span_data.lock();
if let Some(data) = span_data.remove(&span.into_u64()) {
self.send_span(data);
if let Some(mut span_datum) = span_data.remove(&span.into_u64()) {
drop(span_data);
if span_datum.name == WASM_TRACE_IDENTIFIER {
if let Some(n) = span_datum.values.0.remove(WASM_NAME_KEY) {
span_datum.name = n;
}
if let Some(t) = span_datum.values.0.remove(WASM_TARGET_KEY) {
span_datum.target = t;
}
}
self.send_span(span_datum);
};
true
}
Expand Down
3 changes: 1 addition & 2 deletions frame/support/src/wasm_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl Drop for TracingSpanGuard {
/// # Example
///
/// ```
/// # use frame_support::wasm_tracing;
/// wasm_tracing_span!("target", "fn_name");
/// frame_support::wasm_tracing_span!("target", "fn_name");
/// ```
#[macro_export]
macro_rules! wasm_tracing_span {
Expand Down
11 changes: 9 additions & 2 deletions primitives/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
//!
//! To trace functions or invidual code in Substrate, this crate provides [`tracing_span`]
//! and [`enter_span`]. See the individual docs for how to use these macros.
//!
//! Note that to allow traces from wasm execution environment there are
//! 2 reserved identifiers for tracing `Field` recording, stored in the consts:
//! `WASM_TARGET_KEY` and `WASM_NAME_KEY` - if you choose to record fields, you
//! must ensure that your identifiers do not clash with either of these.
//!
//! Additionally, we have a const: `WASM_TRACE_IDENTIFIER`, which holds a span name used
//! to signal that the 'actual' span name and target should be retrieved instead from
//! the associated Fields mentioned above.
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand All @@ -30,8 +39,6 @@ pub use tracing;

#[cfg(feature = "std")]
pub mod proxy;
#[cfg(feature = "std")]
mod span_dispatch;

/// Runs given code within a tracing span, measuring it's execution time.
///
Expand Down
46 changes: 21 additions & 25 deletions primitives/tracing/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

use std::cell::RefCell;
use rental;
use tracing::info_span;

use crate::span_dispatch;
/// Used to identify a proxied WASM trace
pub const WASM_TRACE_IDENTIFIER: &'static str = "WASM_TRACE";
/// Used to extract the real `target` from the associated values of the span
pub const WASM_TARGET_KEY: &'static str = "proxied_wasm_target";
/// Used to extract the real `name` from the associated values of the span
pub const WASM_NAME_KEY: &'static str = "proxied_wasm_name";

const MAX_SPANS_LEN: usize = 1000;

Expand All @@ -28,7 +34,7 @@ thread_local! {
/// Create and enter a `tracing` Span, returning the span id,
/// which should be passed to `exit_span(id)` to signal that the span should exit.
pub fn create_registered_span(target: &str, name: &str) -> u64 {
PROXY.with(|proxy| proxy.borrow_mut().create_registered_span(target, name))
PROXY.with(|proxy| proxy.borrow_mut().create_span(target, name))
}

/// Exit a span by dropping it along with it's associated guard.
Expand Down Expand Up @@ -65,33 +71,24 @@ impl TracingProxy {
pub fn new() -> TracingProxy {
let spans: Vec<(u64, rent_span::SpanAndGuard)> = Vec::new();
TracingProxy {
// Span ids start from 1 - we will use 0 as special case for unregistered spans
next_id: 1,
next_id: 0,
spans,
}
}
}

/// For spans to be recorded they must be registered in `span_dispatch`.
impl TracingProxy {
fn create_registered_span(&mut self, target: &str, name: &str) -> u64 {
let create_span: Result<tracing::Span, String> = span_dispatch::create_registered_span(target, name);
let id;
match create_span {
Ok(span) => {
self.next_id += 1;
id = self.next_id;
let sg = rent_span::SpanAndGuard::new(
Box::new(span),
|span| span.enter(),
);
self.spans.push((id, sg));
}
Err(e) => {
id = 0;
log::info!("{}", e);
}
}
// The identifiers `wasm_target` and `wasm_name` must match their associated const,
// WASM_TARGET_KEY and WASM_NAME_KEY.
fn create_span(&mut self, proxied_wasm_target: &str, proxied_wasm_name: &str) -> u64 {
let span = info_span!(WASM_TRACE_IDENTIFIER, is_valid_trace = true, proxied_wasm_target, proxied_wasm_name);
self.next_id += 1;
let sg = rent_span::SpanAndGuard::new(
Box::new(span),
|span| span.enter(),
);
self.spans.push((self.next_id, sg));
let spans_len = self.spans.len();
if spans_len > MAX_SPANS_LEN {
// This is to prevent unbounded growth of Vec and could mean one of the following:
Expand All @@ -102,11 +99,10 @@ impl TracingProxy {
let mut sg = self.spans.remove(0).1;
sg.rent_all_mut(|s| { s.span.record("is_valid_trace", &false); });
}
id
self.next_id
}

fn exit_span(&mut self, id: u64) {
if id == 0 { return; }
match self.spans.pop() {
Some(v) => {
let mut last_span_id = v.0;
Expand All @@ -122,7 +118,7 @@ impl TracingProxy {
return;
}
}
},
}
None => {
log::warn!("Span id: {} not found", id);
return;
Expand Down
65 changes: 0 additions & 65 deletions primitives/tracing/src/span_dispatch.rs

This file was deleted.