Move the subscriber into a different crate

This commit is contained in:
Dzmitry Malyshau 2020-08-12 14:52:21 -04:00
parent a0711cf9b2
commit d07d8503a0
13 changed files with 75 additions and 121 deletions

91
Cargo.lock generated
View File

@ -97,23 +97,6 @@ dependencies = [
"byteorder",
]
[[package]]
name = "battery"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36a698e449024a5d18994a815998bf5e2e4bc1883e35a7d7ba95b6b69ee45907"
dependencies = [
"cfg-if",
"core-foundation 0.6.4",
"lazycell",
"libc",
"mach",
"nix 0.15.0",
"num-traits",
"uom",
"winapi 0.3.8",
]
[[package]]
name = "bitflags"
version = "1.2.1"
@ -146,7 +129,7 @@ checksum = "7aa2097be53a00de9e8fc349fea6d76221f398f5c4fa550d420669906962d160"
dependencies = [
"mio",
"mio-extras",
"nix 0.14.1",
"nix",
]
[[package]]
@ -217,16 +200,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
[[package]]
name = "core-foundation"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d"
dependencies = [
"core-foundation-sys 0.6.2",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.7.0"
@ -247,12 +220,6 @@ dependencies = [
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b"
[[package]]
name = "core-foundation-sys"
version = "0.7.0"
@ -712,15 +679,6 @@ dependencies = [
"scoped-tls",
]
[[package]]
name = "mach"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1"
dependencies = [
"libc",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -886,19 +844,6 @@ dependencies = [
"void",
]
[[package]]
name = "nix"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"libc",
"void",
]
[[package]]
name = "num-integer"
version = "0.1.43"
@ -1022,6 +967,7 @@ dependencies = [
"ron",
"serde",
"wgpu-core",
"wgpu-subscriber",
"wgpu-types",
"winit",
]
@ -1292,7 +1238,7 @@ dependencies = [
"dlib",
"lazy_static",
"memmap",
"nix 0.14.1",
"nix",
"wayland-client",
"wayland-protocols",
]
@ -1475,12 +1421,6 @@ dependencies = [
"tracing-serde",
]
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "unicode-xid"
version = "0.1.0"
@ -1493,16 +1433,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "uom"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cec796ec5f7ac557631709079168286056205c51c60aac33f51764bdc7b8dc4"
dependencies = [
"num-traits",
"typenum",
]
[[package]]
name = "void"
version = "1.0.2"
@ -1585,7 +1515,7 @@ dependencies = [
"downcast-rs",
"libc",
"mio",
"nix 0.14.1",
"nix",
"wayland-commons",
"wayland-scanner",
"wayland-sys",
@ -1597,7 +1527,7 @@ version = "0.23.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb66b0d1a27c39bbce712b6372131c6e25149f03ffb0cd017cf8f7de8d66dbdb"
dependencies = [
"nix 0.14.1",
"nix",
"wayland-sys",
]
@ -1639,7 +1569,6 @@ name = "wgpu-core"
version = "0.5.0"
dependencies = [
"arrayvec",
"battery",
"bitflags",
"copyless",
"fxhash",
@ -1659,11 +1588,19 @@ dependencies = [
"serde",
"smallvec",
"thiserror",
"tracing",
"wgpu-types",
]
[[package]]
name = "wgpu-subscriber"
version = "0.5.0"
dependencies = [
"parking_lot",
"thread-id",
"tracing",
"tracing-log",
"tracing-subscriber",
"wgpu-types",
]
[[package]]

View File

@ -1,7 +1,8 @@
[workspace]
members = [
"dummy",
"player",
"wgpu-core",
"dummy",
"player",
"wgpu-core",
"wgpu-subscriber",
"wgpu-types",
]

View File

@ -13,6 +13,7 @@ The implementation consists of the following parts:
- [![Crates.io](https://img.shields.io/crates/v/wgpu-core.svg?label=wgpu-core)](https://crates.io/crates/wgpu-core) [![docs.rs](https://docs.rs/wgpu-core/badge.svg)](https://docs.rs/wgpu-core/) - internal Rust API for WebGPU implementations to use
- [![Crates.io](https://img.shields.io/crates/v/wgpu-types.svg?label=wgpu-types)](https://crates.io/crates/wgpu-types) [![docs.rs](https://docs.rs/wgpu-types/badge.svg)](https://docs.rs/wgpu-types/) - Rust types shared between `wgpu-core`, `wgpu-native`, and `wgpu-rs`
- [![Crates.io](https://img.shields.io/crates/v/wgpu-subscriber.svg?label=wgpu-subsciber)](https://crates.io/crates/wgpu-subscriber) [![docs.rs](https://docs.rs/wgpu-subscriber/badge.svg)](https://docs.rs/wgpu-subscriber/) - tracing subscribers to use with `wgpu`
- `player` - standalone application for replaying the API traces, uses `winit`
This repository contains the core of `wgpu`, and is not usable directly by applications.

View File

@ -13,4 +13,4 @@ publish = false
path = "../wgpu-core"
package = "wgpu-core"
version = "0.5"
features = ["battery", "serial-pass", "subscriber", "trace"]
features = ["serial-pass", "trace"]

View File

@ -32,7 +32,11 @@ features = ["replay"]
path = "../wgpu-core"
package = "wgpu-core"
version = "0.5"
features = ["replay", "raw-window-handle", "subscriber"]
features = ["replay", "raw-window-handle"]
[dependencies.wgpu-subscriber]
path = "../wgpu-subscriber"
version = "0.5"
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5", features = ["x11"] }

View File

@ -17,7 +17,7 @@ fn main() {
#[cfg(feature = "winit")]
use winit::{event_loop::EventLoop, window::WindowBuilder};
wgc::logging::subscriber::initialize_default_subscriber(
wgpu_subscriber::initialize_default_subscriber(
std::env::var("WGPU_CHROME_TRACE")
.as_ref()
.map(Path::new)

View File

@ -19,8 +19,6 @@ trace = ["ron", "serde", "wgt/trace"]
replay = ["serde", "wgt/replay"]
# Enable serializable compute/render passes, and bundle encoders.
serial-pass = ["serde", "wgt/serde", "arrayvec/serde"]
# Enable chrome-tracing backend and default tracing subscriber
subscriber = ["thread-id", "tracing-log", "tracing-subscriber"]
[dependencies]
arrayvec = "0.5"
@ -34,10 +32,7 @@ raw-window-handle = { version = "0.3", optional = true }
ron = { version = "0.5", optional = true }
serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "1"
thread-id = { version = "3", optional = true }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-log = { version = "0.1", optional = true }
tracing-subscriber = { version = "0.2", optional = true }
thiserror = "1"
[dependencies.naga]
@ -70,8 +65,5 @@ gfx-backend-dx12 = { version = "0.5.8" }
gfx-backend-dx11 = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5.11" }
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
battery = { version = "0.7", optional = true }
[dev-dependencies]
loom = "0.3"

View File

@ -35,7 +35,6 @@ pub mod device;
pub mod hub;
pub mod id;
pub mod instance;
pub mod logging;
pub mod pipeline;
pub mod resource;
pub mod swap_chain;
@ -220,6 +219,18 @@ macro_rules! gfx_select {
};
}
#[macro_export]
macro_rules! span {
($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => {
let span = tracing::span!(tracing::Level::$level, $name, $($fields)*);
let $guard_name = span.enter();
};
($guard_name:tt, $level:ident, $name:expr) => {
let span = tracing::span!(tracing::Level::$level, $name);
let $guard_name = span.enter();
};
}
/// Fast hash map used internally.
type FastHashMap<K, V> =
std::collections::HashMap<K, V, std::hash::BuildHasherDefault<fxhash::FxHasher>>;

View File

@ -1,14 +0,0 @@
#[cfg(feature = "subscriber")]
pub mod subscriber;
#[macro_export]
macro_rules! span {
($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => {
let span = tracing::span!(tracing::Level::$level, $name, $($fields)*);
let $guard_name = span.enter();
};
($guard_name:tt, $level:ident, $name:expr) => {
let span = tracing::span!(tracing::Level::$level, $name);
let $guard_name = span.enter();
};
}

View File

@ -0,0 +1,21 @@
[package]
name = "wgpu-subscriber"
version = "0.5.0"
authors = ["wgpu developers"]
edition = "2018"
description = "WebGPU tracing subscriber"
homepage = "https://github.com/gfx-rs/wgpu"
repository = "https://github.com/gfx-rs/wgpu"
keywords = ["graphics"]
license = "MPL-2.0"
[lib]
[features]
[dependencies]
parking_lot = "0.10"
thread-id = "3"
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-log = "0.1"
tracing-subscriber = "0.2"

View File

@ -1,4 +1,4 @@
use crate::logging::subscriber::CURRENT_THREAD_ID;
use crate::CURRENT_THREAD_ID;
use parking_lot::Mutex;
use std::{
borrow::Cow,
@ -8,8 +8,10 @@ use std::{
sync::Arc,
time::Instant,
};
use tracing::field::{Field, Visit};
use tracing::{span, Event, Metadata, Subscriber};
use tracing::{
field::{Field, Visit},
span, Event, Metadata, Subscriber,
};
use tracing_subscriber::{layer::Context, registry::LookupSpan, Layer};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]

View File

@ -1,11 +1,8 @@
use smallvec::SmallVec;
use std::{
fmt,
io::{self, Stderr, Stdout},
time::Instant,
use std::{fmt, io, time::Instant};
use tracing::{
field::{Field, Visit},
Event, Level, Subscriber,
};
use tracing::field::{Field, Visit};
use tracing::{Event, Level, Subscriber};
use tracing_subscriber::{layer::Context, registry::LookupSpan, Layer};
#[derive(Debug, Default)]
@ -23,8 +20,8 @@ impl Visit for FmtEventVisitor {
}
enum StandardOutput {
Out(Stdout),
Err(Stderr),
Out(io::Stdout),
Err(io::Stderr),
}
impl StandardOutput {
@ -66,11 +63,13 @@ where
let mut visitor = FmtEventVisitor::default();
event.record(&mut visitor);
let mut spans: SmallVec<[&str; 8]> = SmallVec::new();
let mut span_string = String::new();
for span in ctx.scope() {
spans.push(span.name());
if !span_string.is_empty() {
span_string.push_str(" | ");
}
span_string.push_str(span.name());
}
let span_string = spans.join(" | ");
let metadata = event.metadata();
let level = match *metadata.level() {