Skip to content

Commit

Permalink
The upgrades to 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Apr 30, 2022
1 parent c204b60 commit 69e4497
Show file tree
Hide file tree
Showing 21 changed files with 1,210 additions and 621 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tracy-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable, 1.40.0]
rust_toolchain: [nightly, stable, 1.53.0]
os: [ubuntu-latest, windows-latest, macOS-latest]
flags: ["", "--release", "--no-default-features", "--all-features"]
timeout-minutes: 20
Expand Down
10 changes: 5 additions & 5 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ The following table lists the version correspondence between the libraries.
| 0.7.4 | 0.11.0 | 0.10.0 | 0.4.0 |
| 0.7.5 | 0.12.0 | 0.11.0 | 0.5.0 |
| 0.7.6 | 0.13.0, 0.14.0 | 0.12.* | 0.6.* |
| v0.7.7 | 0.15.0 | 0.12.* | 0.6.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.6.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.7.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.8.* |
| v0.8.1 | 0.17.0 | 0.12.* | 0.7.* |
| v0.7.7 | 0.15.0 | 0.12.* | 0.6.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.6.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.7.* |
| v0.7.8 | 0.16.0 | 0.12.* | 0.8.* |
| v0.8.1 | 0.17.0 | 0.13.* | 0.9.* |
<!-- AUTO-UPDATE -->
12 changes: 7 additions & 5 deletions make_sys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ fi
TAG="${LAST_RELEASE[0]}"
TARBALL="${LAST_RELEASE[1]}"
DESTINATION=/tmp/tracy-$TAG # could use mktemp, but unnecessary complexity.
DEFINES=("-DTRACY_ENABLE" "-DTRACY_MANUAL_LIFETIME" "-DTRACY_FIBERS")

echo "::set-output name=tracy-tag::$TAG"
mkdir -p "$DESTINATION"

curl -sL "$TARBALL" -o - | tar -f - -zxC "$DESTINATION"

BASEDIR=("$DESTINATION"/*)
REQUIRED=($(gcc --dependencies -DTRACY_ENABLE "$BASEDIR/TracyClient.cpp" | grep -o "$BASEDIR/[^ \\]*"))
REQUIRED=($(gcc --dependencies ${DEFINES[@]} "$BASEDIR/TracyClient.cpp" | grep -o "$BASEDIR/[^ \\]*"))

mkdir -p "tracy-client-sys/tracy"

Expand All @@ -31,7 +33,7 @@ bindgen "$BASEDIR/TracyC.h" \
--size_t-is-usize \
--disable-header-comment \
-- \
-DTRACY_ENABLE
${DEFINES[@]}
sed -i 's/pub type/type/g' 'tracy-client-sys/src/generated.rs'

for REQUIRED_FILE in ${REQUIRED[@]}
Expand Down Expand Up @@ -60,20 +62,20 @@ NEXT_SYS_VERSION="0.$(echo "$CURRENT_SYS_VERSION" \
NEXTNEXT_SYS_VERSION="0.$(echo "$CURRENT_SYS_VERSION" \
| sed -nr 's,[0-9]+\.([0-9]+)\.[0-9]+,\1,p' \
| awk '{print $0+2}').0"
NEXT_CLIENT_VERSION="0.12.$(echo "$CURRENT_CLIENT_VERSION" \
NEXT_CLIENT_VERSION="0.13.$(echo "$CURRENT_CLIENT_VERSION" \
| sed -nr 's,[0-9]+\.[0-9]+\.([0-9]+),\1,p' \
| awk '{print $0+1}')"

# Adjust the table in the README file…
sed -i "/^<!-- AUTO-UPDATE -->$/i $(printf "| $TAG | $NEXT_SYS_VERSION | 0.12.* | 0.7.* |")" \
sed -i "/^<!-- AUTO-UPDATE -->$/i $(printf "| $TAG | $NEXT_SYS_VERSION | 0.13.* | 0.9.* |")" \
README.mkd
# …the version in tracy-client-sys…
sed -i "s/^\(version =\) \".*\" \(# AUTO-BUMP\)$/\1 \"$NEXT_SYS_VERSION\" \2/" \
tracy-client-sys/Cargo.toml
# …and the versions in tracy-client.
sed -i "s/^\(version =\) \".*\" \(# AUTO-BUMP\)$/\1 \"$NEXT_CLIENT_VERSION\" \2/" \
tracy-client/Cargo.toml
sed -i "s/^\(version =\) \".*\" \(# AUTO-UPDATE\)$/\1 \">=0.14.0, <$NEXTNEXT_SYS_VERSION\" \2/" \
sed -i "s/^\(version =\) \".*\" \(# AUTO-UPDATE\)$/\1 \">=0.17.0, <$NEXTNEXT_SYS_VERSION\" \2/" \
tracy-client/Cargo.toml

# Make a commit that we'll PR
Expand Down
26 changes: 17 additions & 9 deletions tracing-tracy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-tracy"
version = "0.8.0"
version = "0.9.0"
authors = ["Simonas Kazlauskas <tracing-tracy@kazlauskas.me>"]
license = "MIT/Apache-2.0"
edition = "2018"
Expand All @@ -18,19 +18,27 @@ harness = false
[dependencies]
tracing-core = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "registry"] }
tracy-client = { path = "../tracy-client", version = "0.12.1", default-features = false }
client = { package = "tracy-client", path = "../tracy-client", version = "0.13.0", default-features = false, features = ["fibers"] }

[dev-dependencies]
tracing = { version = "0.1", default-features = false, features = ["std"] }
tokio = { version = "0.2", features = ["full"] }
tokio = { version = "1", features = ["full"] }
tracing-attributes = { version = "0.1"}
tracing-futures = { version = "0.2" }
futures = "0.3"

[features]
default = [ "enable" ]
enable = [ "tracy-client/enable" ]
delayed-init = [ "tracy-client/delayed-init" ]
lowres-timer = [ "tracy-client/lowres-timer" ]
noexit = [ "tracy-client/noexit" ]
ondemand = [ "tracy-client/ondemand" ]
# Refer to `tracy-client-sys` for documentation on features.
default = [ "enable", "system-tracing", "context-switch-tracing", "sampling", "code-transfer",
"broadcast" ]
broadcast = ["client/broadcast"]
code-transfer = ["client/code-transfer"]
context-switch-tracing = ["client/context-switch-tracing"]
enable = ["client/enable"]
fibers = ["client/fibers"]
timer-fallback = ["client/timer-fallback"]
ondemand = ["client/ondemand"]
only-ipv4 = ["client/only-ipv4"]
only-localhost = ["client/only-localhost"]
sampling = ["client/sampling"]
system-tracing = ["client/system-tracing"]
33 changes: 20 additions & 13 deletions tracing-tracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@
//!
//! # Important note
//!
//! Unlike with many other subscriber implementations, simply depending on this crate is sufficient
//! for tracy to be enabled at program startup, even if [`TracyLayer`](TracyLayer) is not
//! registered as a subscriber. While not registering a `TracyLayer` will avoid Tracy from
//! collecting spans, it still broadcasts discovery packets to the local network and exposes the
//! data it collects in the background to that same network. Traces collected by Tracy may include
//! source and assembly code as well.
//! Depending on the configuration Tracy may broadcast discovery packets to the local network and
//! expose the data it collects in the background to that same network. Traces collected by Tracy
//! may include source and assembly code as well.
//!
//! As thus, you may want make sure to only enable the `tracing-tracy` crate conditionally, via the
//! `enable` feature flag provided by this crate.
//!
//! [Tracy]: https://github.com/wolfpld/tracy
//!
//! # Features
//!
//! Refer to the [`client::sys`] crate for documentation on crate features. This crate re-exports
//! all the features from [`client`].
use std::{borrow::Cow, cell::RefCell, collections::VecDeque, fmt::Write};
use tracing_core::{
Expand All @@ -58,7 +60,9 @@ use tracing_subscriber::{
registry,
};

use tracy_client::{color_message, finish_continuous_frame, message, Span};
use client::{Client, Span};

pub use client;

thread_local! {
/// A stack of spans currently active on the current thread.
Expand All @@ -71,6 +75,7 @@ thread_local! {
pub struct TracyLayer<F = DefaultFields> {
fmt: F,
stack_depth: u16,
client: Client,
}

impl TracyLayer<DefaultFields> {
Expand All @@ -81,6 +86,7 @@ impl TracyLayer<DefaultFields> {
Self {
fmt: DefaultFields::default(),
stack_depth: 64,
client: Client::enable(),
}
}
}
Expand All @@ -99,6 +105,7 @@ impl<F> TracyLayer<F> {
TracyLayer {
fmt,
stack_depth: self.stack_depth,
client: self.client,
}
}

Expand All @@ -116,7 +123,7 @@ impl<F> TracyLayer<F> {
while !data.is_char_boundary(max_len) {
max_len -= 1;
}
color_message(error_msg, 0xFF000000, self.stack_depth);
self.client.color_message(error_msg, 0xFF000000, self.stack_depth);
&data[..max_len]
} else {
data
Expand Down Expand Up @@ -178,7 +185,7 @@ where
};
TRACY_SPAN_STACK.with(|s| {
s.borrow_mut().push_back((
Span::new(
self.client.span_alloc(
self.truncate_to_length(
&name,
file,
Expand All @@ -200,7 +207,7 @@ where
TRACY_SPAN_STACK.with(|s| {
if let Some((span, span_id)) = s.borrow_mut().pop_back() {
if id.into_u64() != span_id {
color_message(
self.client.color_message(
"Tracing spans exited out of order! \
Trace may not be accurate for this span stack.",
0xFF000000,
Expand All @@ -209,7 +216,7 @@ where
}
drop(span);
} else {
color_message(
self.client.color_message(
"Exiting a tracing span, but got nothing on the tracy span stack!",
0xFF000000,
self.stack_depth,
Expand All @@ -226,7 +233,7 @@ where
};
event.record(&mut visitor);
if !visitor.first {
message(
self.client.message(
self.truncate_to_length(
&visitor.dest,
"",
Expand All @@ -237,7 +244,7 @@ where
);
}
if visitor.frame_mark {
finish_continuous_frame!();
self.client.frame_mark();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tracing-tracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ async fn parent_task(subtasks: usize) {
#[instrument]
async fn subtask(number: usize) -> usize {
info!("sleeping in subtask {}...", number);
tokio::time::delay_for(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
info!("sleeping in subtask {}...", number);
tokio::time::delay_for(std::time::Duration::from_millis(number as _)).await;
tokio::time::sleep(std::time::Duration::from_millis(number as _)).await;
info!("sleeping in subtask {}...", number);
tokio::time::delay_for(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
number
}

Expand Down Expand Up @@ -111,7 +111,7 @@ pub(crate) fn main() {
message_too_long();
long_span_data();
span_with_fields();
let mut runtime = tokio::runtime::Builder::new()
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio runtime");
Expand Down
47 changes: 38 additions & 9 deletions tracy-client-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,52 @@ description = """
Low level bindings to the client libraries for the Tracy profiler
"""

[[test]]
name = "tests"
path = "tests.rs"
harness = false
required-features = ["fibers"]

[dependencies]

[build-dependencies]
cc = { version = "1", default-features = false }

[features]
default = [ "enable" ]
# Enable Tracy. Once this is activated, tracy will be initialized at program startup.
default = [ "enable", "system-tracing", "context-switch-tracing", "sampling", "code-transfer",
"broadcast" ]
# Enable Tracy. Corresponds to the `TRACY_ENABLE` define.
enable = []
# Enable delayed init support. Tracy will initialize on first use, rather than during
# life-before-main.
delayed-init = []
# Enable support for tracing coroutines, fibers and similar such asynchrony primitives. Corresponds
# to the `TRACY_FIBERS` define.
fibers = []

# Enable tracing of the system-level details. This is only active if permissions are sufficient
# when the application is run. The `TRACY_NO_SYSTEM_TRACING` define is set if this feature is
# disabled.
system-tracing = []
# Enable capture of the context switch data. The `TRACY_NO_CONTEXT_SWITCH` define is set if this
# feature is disabled.
context-switch-tracing = []
# Enable external sampling of the call stacks. The `TRACY_NO_SAMPLING` define is set if this
# feature is disabled.
sampling = []
# Enable transfer of the machine code to the profiler. The `TRACY_NO_CODE_TRANSFER` define is set
# if this feature is disabled.
code-transfer = []

# Allow the client to announce its presence to the profilers on the local network. The
# `TRACY_NO_BROADCAST` define is set if this feature is disabled.
broadcast = []
# Listen for profilers on the localhost interface only. Corresponds to the `TRACY_ONLY_LOCALHOST`
# define. Can also be activated by setting an environment variable of the same name.
only-localhost = []
# Listen on IPv4 interfaces only. Corresponds to the `TRACY_ONLY_IPV4` define. Can also be
# activated by setting an environment variable of the same name.
only-ipv4 = []

# Enable support for running with low resolution timers.
lowres-timer = []
# Do not exit when program finishes execution or crashes. Can also be activated by an environment
# variable: `TRACY_NO_EXIT`.
noexit = []
timer-fallback = []
# Enable on-demand mode. Traces are only collected when a server connects to the client.
# Also makes it possible to repeatedly re-connect to a client.
ondemand = []
42 changes: 31 additions & 11 deletions tracy-client-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,46 @@ fn set_feature_defines(mut c: cc::Build) -> cc::Build {
if std::env::var_os("CARGO_FEATURE_ENABLE").is_some() {
c.define("TRACY_ENABLE", None);
}
if std::env::var_os("CARGO_FEATURE_DELAYED_INIT").is_some() {
c.define("TRACY_DELAYED_INIT", None);
}
if std::env::var_os("CARGO_FEATURE_LOWRES_TIMER").is_some() {
c.define("TRACY_TIMER_QPC", None);
}
if std::env::var_os("CARGO_FEATURE_NOEXIT").is_some() {
c.define("TRACY_NO_EXIT", None);
if std::env::var_os("CARGO_FEATURE_TIMER_FALLBACK").is_some() {
c.define("TRACY_TIMER_FALLBACK", None);
}
if std::env::var_os("CARGO_FEATURE_ONDEMAND").is_some() {
c.define("TRACY_ON_DEMAND", None);
}
if std::env::var_os("CARGO_FEATURE_ONLY_LOCALHOST").is_some() {
c.define("TRACY_ONLY_LOCALHOST", None);
}
if std::env::var_os("CARGO_FEATURE_ONLY_IPV4").is_some() {
c.define("TRACY_ONLY_IPV4", None);
}
if std::env::var_os("CARGO_FEATURE_FIBERS").is_some() {
c.define("TRACY_FIBERS", None);
}

if !std::env::var_os("CARGO_FEATURE_SYSTEM_TRACING").is_some() {
c.define("TRACY_NO_SYSTEM_TRACING", None);
}
if !std::env::var_os("CARGO_FEATURE_CONTEXT_SWITCH_TRACING").is_some() {
c.define("TRACY_NO_CONTEXT_SWITCH", None);
}
if !std::env::var_os("CARGO_FEATURE_SAMPLING").is_some() {
c.define("TRACY_NO_SAMPLING", None);
}
if !std::env::var_os("CARGO_FEATURE_CODE_TRANSFER").is_some() {
c.define("TRACY_NO_CODE_TRANSFER", None);
}
if !std::env::var_os("CARGO_FEATURE_BROADCAST").is_some() {
c.define("TRACY_NO_BROADCAST", None);
}
c
}


fn main() {
if std::env::var_os("CARGO_FEATURE_ENABLE").is_some() {
set_feature_defines(cc::Build::new())
.file("tracy/TracyClient.cpp")
.define("TRACY_MANUAL_LIFETIME", None)
.define("TRACY_DELAYED_INIT", None)
.warnings(false)
.cpp(true)
.flag_if_supported("-std=c++11")
Expand All @@ -44,8 +64,8 @@ fn main() {
link_libraries(&target_os);
}
Err(e) => {
writeln!(::std::io::stderr(),
"Unable to get target_os=`{}`!", e).expect("could not report the error");
writeln!(::std::io::stderr(), "Unable to get target_os=`{}`!", e)
.expect("could not report the error");
::std::process::exit(0xfd);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tracy-client-sys/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ fn bindgen_test_layout____tracy_gpu_context_name_data() {
);
}
type TracyCZoneCtx = ___tracy_c_zone_context;
extern "C" {
pub fn ___tracy_startup_profiler();
}
extern "C" {
pub fn ___tracy_shutdown_profiler();
}
extern "C" {
pub fn ___tracy_alloc_srcloc(
line: u32,
Expand Down
Loading

0 comments on commit 69e4497

Please sign in to comment.