GithubHelp home page GithubHelp logo

rust_tracy_client's Introduction

Tracy profiler clients in Rust

This project contains Rust crates for producing Tracy profiler traces. Tracy features nanosecond precision, ability to profile remotely and a full-featured graphical interface for finding hot spots in profiled programs.

While Tracy's support for Rust is not first-class, it is still a very potent tool. If you have an application instrumented with the tracing crate, Tracy can be used with your program in minutes via the tracing-tracy crate. It can work well as both a profiling and, to a lesser extent, an observability tool.

Important note

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, tracy-client and tracy-client-sys crates conditionally, via the enable feature flag provided by the crates.

Version support table

This project, unlike Tracy itself, follows semantic versioning. We will publish a breaking version bump for tracy-client-sys whenever there is a potentially breaking protocol change, even if the Tracy project itself does not. An older version of Tracy being unable to communicate with the client of a more recent version is an example of such a breaking change.

tracy-client, tracing-tracy and other crates also follow semantic versioning, but do not consider protocol breaks a breaking change for their purposes. For that reason each future version of tracy-client may be able to support depending on a large number of incompatible tracy-client-sys versions. Users are expected to select the version of Tracy profiler they target and use precise version bounds in Cargo.toml or Cargo.lock to specify the version of tracy-client-sys that they want to use.

The following table lists the version correspondence between the libraries.

Tracy tracy-client-sys tracy-client tracing-tracy
0.7.1 0.9.0 0.8.0 0.2.0
0.7.3 0.10.0 0.9.0 0.3.0
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.13.* 0.9.*
v0.8.1 0.17.* 0.14.* 0.10.*
v0.8.2 0.18.0 0.14.* 0.10.*
v0.9 0.19.0 0.14.2 0.10.0
v0.9 0.19.0 0.15.0 0.10.1
v0.9.1 0.21.0 0.15.2 0.10.2
v0.9.1 0.21.0 0.16.0 0.10.3
v0.10 0.22.0 0.16.4 0.10.4
v0.10 0.22.0 0.17.0 0.11.0
v0.11.0 0.23.0 0.17.1 0.11.1

rust_tracy_client's People

Contributors

benfrankel avatar cwfitzgerald avatar danipopes avatar enerqi avatar guusw avatar ibab avatar imberflur avatar mockersf avatar nagisa avatar ralith avatar repi avatar supercilex avatar superdump avatar yalter avatar zanshi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust_tracy_client's Issues

I had to use internal for dynamic FrameName

Hi, I'm using tracy-client to profile a Wayland compositor. I'm using non-continuous frames for profiling monitor redrawing. However, with multiple monitors plugged in, every monitor should have its own frame set, as they are disjoint and redraw on their own vsync cycles.

Since monitors can be plugged in and out at runtime, I have to generate FrameNames dynamically, based on the name of the connector. I understand it's not really supported by Tracy at the moment, but it works well enough™ if I leak the name string, so that it's available for the remaining program lifetime. Unfortunately, I can't use the frame_name! macro as it only accepts a literal.

let vblank_frame_name = unsafe {
    tracy_client::internal::create_frame_name(format!("vblank on {output_name}\0").leak())
};

(I do this once when a monitor is connected, not every frame.)

Would it make sense to expose something for this in tracy-client?

License text not in repo nor published crates

The rust crates are licensed under the Apache-2.0 OR MIT licenses, but neither license text is present in this repo, even though both licenses require the license text be present in all source distributions.

Also, the C++ code is licensed under the BSD-3-Clause license, so I think the correct license for tracy-client-sys crate would actually be (Apache-2.0 OR MIT) AND BSD-3-Clause as it is directly building and including C++ under that license, but IANAL so take that with a grain of salt.

Support span colours

The new release of tracy now supports setting colours when allocating srcloc for span. We should too at least in tracy-client.

`tracing-tracy` minor version bumps with major `tracy-client` version bumps

This makes it easier to accidentally have 2 versions of tracy-client in use.

Is this intentional? I know profiling has to do something like this to avoid churn in libraries that use it, but I wasn't previously expecting this from tracing-tracy so accidentally ended up with two versions and had to debug this error:

 tracy/client/TracyProfiler.cpp:1357: tracy::Profiler::Profiler(): Assertion `!s_instance' failed.

If so, this isn't a major issue and I can just make sure to use a particular version of tracing-tracy.

Some linux systems may need CXXFLAGS+=-std=c++0x

Other Linux users may run into this; I am uncertain. I was having trouble using any of the tracy rust crates because it was failing to compile the underlying TracyClient.cpp and friends. Perhaps we can add something to the documentation regarding maybe needing special CXXFLAGS? or perhaps CXXFLAG can conditionally be added when seemingly necessary and running cargo build?

cargo build
// ... lots of output
  error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-DTRACY_ENABLE" "-o" "target/debug/build/tracy-client-sys-6734926446c3849b/out/tracy/TracyClient.o" "-c" "tracy/TracyClient.cpp" with args "c++" did not execute successfully (status code exit status: 1).

When running c++ manually the output is many lines like this:

c++ -O0 -ffunction-sections -fdata-sections -fPIC -g -fno-omit-frame-pointer -m64 -DTRACY_ENABLE -o target/debug/build/tracy-client-sys-67123123b/out/tracy/TracyClient.o -c tracy/TracyClient.cpp

.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.16.0/tracy/client/TracyDxt1.cpp:633:24: error: ‘c’ does not name a type
             const auto c = ProcessRGB( (uint8_t*)buf );
                        ^

It appears as though the "auto" keyword (from C++11?) is not available by default when using g++? (I'm not a C person).

Apparently the issue was I was compiling with g++ (may be diff for others?) and to enable C++11 features it must be passed as a flag. The "standard" value is "c++0x" for c++11. When you add that to CXXFLAGS cargo build compilation can continue.

The complete cargo build command:
CXXFLAGS=-std=c++0x cargo build

How can I trace a external call and show up in the UI?

Is possible to mark a section of the code that calls a external function or a inner loop that show up in the UI, like:

#[tracing::instrument(skip_all)]
pub fn compile_sql(db: &RelationalDB, tx: &MutTxId, sql_text: &str) -> Result<Vec<CrudExpr>, DBError> {
    tracing::info!(sql = sql_text);
    let ast = compile_to_ast(db, tx, sql_text)?;

    let mut results = Vec::with_capacity(ast.len());

    let loops = tracing::info_span!("LOOP compiler");
    for sql in ast {
        tracing::info!(sql = sql_text); <--- WANNA THIS be part of "LOOP compiler"
        results.push(compile_statement(sql).map_err(|error| DBError::Plan {
            sql: sql_text.to_string(),
            error,
        })?);
    }

Tracy hanging when loaded with a DLL on version 0.17. It seems fine with version 0.16 (Windows)

I updated the library from 0.16.5 to 17.0 and got a problem in an application of mine. The Rust portion of the code is a DLL invoked from a C++ application. The C++ application is not the one being profiled, only some threads and some function calls on the Rust side. Things were working fine, and they still are, to an extent.

The Rust app is loaded at runtime, a thread is spun from C++ which will run a loop in the Rust library. There is some message passing from Rust/C++, both ways, so sometimes the C++ thread will get into Rust code and vice versa. The Rust lib has tracy_client, but the C++ portion has no idea tracy exists. I imagined there wouldn't be much trouble with it. However, when the app is shutting down, the Rust portion of the code starts to shutdown, the thread that runs Rust code is joined from C++ side, and the DLL should be unloaded. However, the process never finishes.

I could not replicate this yet on another project, by just using a DLL, though.

Pulling it on the debugger while the problem was happening, I saw some thread was stuck at TracyThread.hpp, line 46, on a WaitForSingleObject call, on the Thread destructor.

I don't know if it is a problem with this library, or the way I'm using. I'll try to replicate this problem but if any of you can help me identify what the problem might be I'd be grateful.

I'm using these features:


[dependencies.tracy-client]
version = "0.17"
default-features = false

[features]
tracy = [
    "tracy-client/enable",
    "tracy-client/system-tracing",
    "tracy-client/context-switch-tracing",
    "tracy-client/sampling",
    "tracy-client/code-transfer",
    "tracy-client/broadcast",
    "tracy-client/callstack-inlines",
]

tracy-client 0.14.1 is not on crates.io

I'm using tracy's newest release version 0.8.2, but tracy-client have only 0.14.0 on crate.io, which cause
"The client you are trying to connect to uses incompatible protocol version.
Make sure you are using the same Tracy version on both client and server."

related issue: aclysma/profiling#38 (comment)

For now, i'm using tracy-client = { git = "https://github.com/nagisa/rust_tracy_client.git", version = "0.14.1"} for a temporary solution.
Moreover, is there a way to specific the tracy-client-sys version of tracy-client crate in Cargo.toml?

TRACY_NO_EXIT doesn't do anything

Not sure if this has anything to do with the rust side of things, but I thought it was supposed to block my binary from exiting. Is there some API I need to call to make this happen when using tokio tracing? Also there should probably be a feature tied to this envvar.

Update to the new version of Tracy

The auto-update PR script broke, at least because installing bindgen split out the CLI into a separate crate. But also, Tracy itself has significant changes, so I don’t really anticipate things "just" working after some version bumps.

Reintroduce #1

#1 was reverted because current release of tracy is no longer compatible with the protocol in master.

Cross-compile on Linux, target i686-pc-windows-gnu fails.

Compiling a program that uses Tracy and works on Linux.
Trying a compile with target cargo build --target i686-pc-windows-gnu. Compile time errors.

Looks like a missing dependency at the C++ level, or wrong version, or something like that.

System doing the compile is 20.04 LTS.

Program being compiled is "Rend3": Location: https://github.com/BVE-Reborn/rend3

The following warnings were emitted during compilation:

warning: In file included from tracy/client/TracyProfiler.hpp:17,
warning:                  from tracy/client/TracyScoped.hpp:11,
warning:                  from tracy/client/TracyProfiler.cpp:71,
warning:                  from tracy/TracyClient.cpp:23:
warning: tracy/client/../common/TracyMutex.hpp:19:25: error: ‘mutex’ in namespace ‘std’ does not name a type
warning:    19 | using TracyMutex = std::mutex;
warning:       |                         ^~~~~
warning: tracy/client/../common/TracyMutex.hpp:16:1: note: ‘std::mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
warning:    15 | #include <mutex>
warning:   +++ |+#include <mutex>
warning:    16 | 
warning: In file included from tracy/client/TracyScoped.hpp:11,
warning:                  from tracy/client/TracyProfiler.cpp:71,
warning:                  from tracy/TracyClient.cpp:23:
warning: tracy/client/TracyProfiler.hpp:795:5: error: ‘TracyMutex’ does not name a type
warning:   795 |     TracyMutex m_serialLock;
warning:       |     ^~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:799:5: error: ‘TracyMutex’ does not name a type
warning:   799 |     TracyMutex m_fiLock;
warning:       |     ^~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static tracy::QueueItem* tracy::Profiler::QueueSerial()’:
warning: tracy/client/TracyProfiler.hpp:170:11: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   170 |         p.m_serialLock.lock();
warning:       |           ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static tracy::QueueItem* tracy::Profiler::QueueSerialCallstack(void*)’:
warning: tracy/client/TracyProfiler.hpp:177:11: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   177 |         p.m_serialLock.lock();
warning:       |           ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::QueueSerialFinish()’:
warning: tracy/client/TracyProfiler.hpp:186:11: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   186 |         p.m_serialLock.unlock();
warning:       |           ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::SendFrameImage(const void*, uint16_t, uint16_t, uint8_t, bool)’:
warning: tracy/client/TracyProfiler.hpp:226:18: error: ‘class tracy::Profiler’ has no member named ‘m_fiLock’; did you mean ‘m_sock’?
warning:   226 |         profiler.m_fiLock.lock();
warning:       |                  ^~~~~~~~
warning:       |                  m_sock
warning: tracy/client/TracyProfiler.hpp:234:18: error: ‘class tracy::Profiler’ has no member named ‘m_fiLock’; did you mean ‘m_sock’?
warning:   234 |         profiler.m_fiLock.unlock();
warning:       |                  ^~~~~~~~
warning:       |                  m_sock
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemAlloc(const void*, size_t, bool)’:
warning: tracy/client/TracyProfiler.hpp:398:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   398 |         GetProfiler().m_serialLock.lock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:400:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   400 |         GetProfiler().m_serialLock.unlock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemFree(const void*, bool)’:
warning: tracy/client/TracyProfiler.hpp:411:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   411 |         GetProfiler().m_serialLock.lock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:413:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   413 |         GetProfiler().m_serialLock.unlock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemAllocCallstack(const void*, size_t, int, bool)’:
warning: tracy/client/TracyProfiler.hpp:429:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   429 |         profiler.m_serialLock.lock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:432:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   432 |         profiler.m_serialLock.unlock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemFreeCallstack(const void*, int, bool)’:
warning: tracy/client/TracyProfiler.hpp:451:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   451 |         profiler.m_serialLock.lock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:454:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   454 |         profiler.m_serialLock.unlock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemAllocNamed(const void*, size_t, bool, const char*)’:
warning: tracy/client/TracyProfiler.hpp:468:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   468 |         GetProfiler().m_serialLock.lock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:471:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   471 |         GetProfiler().m_serialLock.unlock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemFreeNamed(const void*, bool, const char*)’:
warning: tracy/client/TracyProfiler.hpp:482:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   482 |         GetProfiler().m_serialLock.lock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:485:23: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   485 |         GetProfiler().m_serialLock.unlock();
warning:       |                       ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemAllocCallstackNamed(const void*, size_t, int, bool, const char*)’:
warning: tracy/client/TracyProfiler.hpp:501:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   501 |         profiler.m_serialLock.lock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:505:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   505 |         profiler.m_serialLock.unlock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp: In static member function ‘static void tracy::Profiler::MemFreeCallstackNamed(const void*, int, bool, const char*)’:
warning: tracy/client/TracyProfiler.hpp:524:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   524 |         profiler.m_serialLock.lock();
warning:       |                  ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.hpp:528:18: error: ‘class tracy::Profiler’ has no member named ‘m_serialLock’
warning:   528 |         profiler.m_serialLock.unlock();
warning:       |                  ^~~~~~~~~~~~
warning: In file included from tracy/TracyClient.cpp:23:
warning: tracy/client/TracyProfiler.cpp: At global scope:
warning: tracy/client/TracyProfiler.cpp:141:10: error: ‘once_flag’ in namespace ‘std’ does not name a type
warning:   141 |     std::once_flag once_flag;
warning:       |          ^~~~~~~~~
warning: In file included from tracy/TracyClient.cpp:23:
warning: tracy/client/TracyProfiler.cpp:99:1: note: ‘std::once_flag’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
warning:    98 | #  include <lmcons.h>
warning:   +++ |+#include <mutex>
warning:    99 | extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
warning: In file included from tracy/TracyClient.cpp:23:
warning: tracy/client/TracyProfiler.cpp: In constructor ‘tracy::RPMallocInit::RPMallocInit()’:
warning: tracy/client/TracyProfiler.cpp:154:14: error: ‘call_once’ is not a member of ‘std’
warning:   154 |         std::call_once( once_flag, InitOnceCallback );
warning:       |              ^~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:154:25: error: ‘once_flag’ was not declared in this scope
warning:   154 |         std::call_once( once_flag, InitOnceCallback );
warning:       |                         ^~~~~~~~~
warning: In file included from tracy/TracyClient.cpp:23:
warning: tracy/client/TracyProfiler.cpp: In function ‘const char* tracy::GetHostInfo()’:
warning: tracy/client/TracyProfiler.cpp:531:50: error: ‘std::thread’ has not been declared
warning:   531 |     ptr += sprintf( ptr, "CPU cores: %i\n", std::thread::hardware_concurrency() );
warning:       |                                                  ^~~~~~
warning: tracy/client/TracyProfiler.cpp: In function ‘LONG tracy::CrashFilter(PEXCEPTION_POINTERS)’:
warning: tracy/client/TracyProfiler.cpp:702:10: error: ‘std::this_thread’ has not been declared
warning:   702 |     std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
warning:       |          ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:704:58: error: ‘std::this_thread’ has not been declared
warning:   704 |     while( !GetProfiler().HasShutdownFinished() ) { std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); };
warning:       |                                                          ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::SpawnWorkerThreads()’:
warning: tracy/client/TracyProfiler.cpp:1271:14: error: ‘std::this_thread’ has not been declared
warning:  1271 |         std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
warning:       |              ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::Worker()’:
warning: tracy/client/TracyProfiler.cpp:1372:70: error: ‘std::this_thread’ has not been declared
warning:  1372 |     while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                                                                      ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:1492:18: error: ‘std::this_thread’ has not been declared
warning:  1492 |             std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                  ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:1682:26: error: ‘std::this_thread’ has not been declared
warning:  1682 |                     std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                          ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:1815:18: error: ‘std::this_thread’ has not been declared
warning:  1815 |             std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                  ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::CompressWorker()’:
warning: tracy/client/TracyProfiler.cpp:1826:70: error: ‘std::this_thread’ has not been declared
warning:  1826 |     while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                                                                      ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:1834:21: error: ‘m_fiLock’ was not declared in this scope; did you mean ‘m_sock’?
warning:  1834 |             while( !m_fiLock.try_lock() )
warning:       |                     ^~~~~~~~
warning:       |                     m_sock
warning: tracy/client/TracyProfiler.cpp:1845:17: error: ‘m_fiLock’ was not declared in this scope; did you mean ‘m_sock’?
warning:  1845 |                 m_fiLock.unlock();
warning:       |                 ^~~~~~~~
warning:       |                 m_sock
warning: tracy/client/TracyProfiler.cpp:1878:18: error: ‘std::this_thread’ has not been declared
warning:  1878 |             std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
warning:       |                  ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::ClearSerial()’:
warning: tracy/client/TracyProfiler.cpp:1980:13: error: ‘m_serialLock’ was not declared in this scope
warning:  1980 |     while( !m_serialLock.try_lock() )
warning:       |             ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:1992:9: error: ‘m_serialLock’ was not declared in this scope
warning:  1992 |         m_serialLock.unlock();
warning:       |         ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘tracy::Profiler::DequeueStatus tracy::Profiler::DequeueSerial()’:
warning: tracy/client/TracyProfiler.cpp:2283:17: error: ‘m_serialLock’ was not declared in this scope
warning:  2283 |         while( !m_serialLock.try_lock() )
warning:       |                 ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:2294:13: error: ‘m_serialLock’ was not declared in this scope
warning:  2294 |             m_serialLock.unlock();
warning:       |             ^~~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::HandleDisconnect()’:
warning: tracy/client/TracyProfiler.cpp:2808:22: error: ‘std::this_thread’ has not been declared
warning:  2808 |                 std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                      ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp:2837:18: error: ‘std::this_thread’ has not been declared
warning:  2837 |             std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
warning:       |                  ^~~~~~~~~~~
warning: tracy/client/TracyProfiler.cpp: In member function ‘void tracy::Profiler::CalibrateTimer()’:
warning: tracy/client/TracyProfiler.cpp:2849:10: error: ‘std::this_thread’ has not been declared
warning:  2849 |     std::this_thread::sleep_for( std::chrono::milliseconds( 200 ) );
warning:       |          ^~~~~~~~~~~
warning: In file included from tracy/TracyClient.cpp:26:
warning: tracy/client/TracySysTrace.cpp: In function ‘bool tracy::SysTraceStart(int64_t&)’:
warning: tracy/client/TracySysTrace.cpp:396:37: error: ‘TraceSetInformation’ was not declared in this scope; did you mean ‘HeapSetInformation’?
warning:   396 |         const auto intervalStatus = TraceSetInformation( 0, TraceSampledProfileIntervalInfo, &interval, sizeof( interval ) );
warning:       |                                     ^~~~~~~~~~~~~~~~~~~
warning:       |                                     HeapSetInformation
warning: tracy/client/TracySysTrace.cpp:422:35: error: ‘std::thread’ has not been declared
warning:   422 |     s_prop->MinimumBuffers = std::thread::hardware_concurrency() * 4;
warning:       |                                   ^~~~~~
warning: tracy/client/TracySysTrace.cpp:423:35: error: ‘std::thread’ has not been declared
warning:   423 |     s_prop->MaximumBuffers = std::thread::hardware_concurrency() * 6;
warning:       |                                   ^~~~~~
warning: tracy/client/TracySysTrace.cpp:453:34: error: ‘TraceSetInformation’ was not declared in this scope; did you mean ‘HeapSetInformation’?
warning:   453 |         const auto stackStatus = TraceSetInformation( s_traceHandle, TraceStackTracingInfo, &stackId, sizeof( stackId ) );
warning:       |                                  ^~~~~~~~~~~~~~~~~~~
warning:       |                                  HeapSetInformation
warning: tracy/client/TracySysTrace.cpp: In function ‘void tracy::SysTraceSendExternalName(uint64_t)’:
warning: tracy/client/TracySysTrace.cpp:536:26: error: ‘GetProcessIdOfThread’ was not declared in this scope
warning:   536 |         const auto pid = GetProcessIdOfThread( hnd );
warning:       |                          ^~~~~~~~~~~~~~~~~~~~
warning: In file included from tracy/TracyClient.cpp:27:
warning: tracy/common/TracySocket.cpp: In member function ‘int tracy::Socket::Recv(void*, int, int)’:
warning: tracy/common/TracySocket.cpp:342:19: error: aggregate ‘tracy::Socket::Recv(void*, int, int)::pollfd fd’ has incomplete type and cannot be defined
warning:   342 |     struct pollfd fd;
warning:       |                   ^~
warning: tracy/common/TracySocket.cpp:344:17: error: ‘POLLIN’ was not declared in this scope
warning:   344 |     fd.events = POLLIN;
warning:       |                 ^~~~~~
warning: tracy/common/TracySocket.cpp:23:16: error: ‘WSAPoll’ was not declared in this scope
warning:    23 | #  define poll WSAPoll
warning:       |                ^~~~~~~
warning: tracy/common/TracySocket.cpp:346:9: note: in expansion of macro ‘poll’
warning:   346 |     if( poll( &fd, 1, timeout ) > 0 )
warning:       |         ^~~~
warning: tracy/common/TracySocket.cpp: In member function ‘bool tracy::Socket::HasData()’:
warning: tracy/common/TracySocket.cpp:425:19: error: aggregate ‘tracy::Socket::HasData()::pollfd fd’ has incomplete type and cannot be defined
warning:   425 |     struct pollfd fd;
warning:       |                   ^~
warning: tracy/common/TracySocket.cpp:427:17: error: ‘POLLIN’ was not declared in this scope
warning:   427 |     fd.events = POLLIN;
warning:       |                 ^~~~~~
warning: tracy/common/TracySocket.cpp:23:16: error: ‘WSAPoll’ was not declared in this scope
warning:    23 | #  define poll WSAPoll
warning:       |                ^~~~~~~
warning: tracy/common/TracySocket.cpp:429:12: note: in expansion of macro ‘poll’
warning:   429 |     return poll( &fd, 1, 0 ) > 0;
warning:       |            ^~~~
warning: tracy/common/TracySocket.cpp: In member function ‘tracy::Socket* tracy::ListenSocket::Accept()’:
warning: tracy/common/TracySocket.cpp:515:19: error: aggregate ‘tracy::ListenSocket::Accept()::pollfd fd’ has incomplete type and cannot be defined
warning:   515 |     struct pollfd fd;
warning:       |                   ^~
warning: tracy/common/TracySocket.cpp:517:17: error: ‘POLLIN’ was not declared in this scope
warning:   517 |     fd.events = POLLIN;
warning:       |                 ^~~~~~
warning: tracy/common/TracySocket.cpp:23:16: error: ‘WSAPoll’ was not declared in this scope
warning:    23 | #  define poll WSAPoll
warning:       |                ^~~~~~~
warning: tracy/common/TracySocket.cpp:519:9: note: in expansion of macro ‘poll’
warning:   519 |     if( poll( &fd, 1, 10 ) > 0 )
warning:       |         ^~~~
warning: tracy/common/TracySocket.cpp: In member function ‘bool tracy::UdpBroadcast::Open(const char*, uint16_t)’:
warning: tracy/common/TracySocket.cpp:607:5: error: ‘inet_pton’ was not declared in this scope; did you mean ‘inet_ntoa’?
warning:   607 |     inet_pton( AF_INET, addr, &m_addr );
warning:       |     ^~~~~~~~~
warning:       |     inet_ntoa
warning: tracy/common/TracySocket.cpp: In member function ‘void tracy::IpAddress::Set(const sockaddr&)’:
warning: tracy/common/TracySocket.cpp:651:5: error: ‘inet_ntop’ was not declared in this scope; did you mean ‘inet_ntoa’?
warning:   651 |     inet_ntop( AF_INET, &ai->sin_addr, m_text, 17 );
warning:       |     ^~~~~~~~~
warning:       |     inet_ntoa
warning: tracy/common/TracySocket.cpp: In member function ‘const char* tracy::UdpListen::Read(size_t&, tracy::IpAddress&, int)’:
warning: tracy/common/TracySocket.cpp:736:19: error: aggregate ‘tracy::UdpListen::Read(size_t&, tracy::IpAddress&, int)::pollfd fd’ has incomplete type and cannot be defined
warning:   736 |     struct pollfd fd;
warning:       |                   ^~
warning: tracy/common/TracySocket.cpp:738:17: error: ‘POLLIN’ was not declared in this scope
warning:   738 |     fd.events = POLLIN;
warning:       |                 ^~~~~~
warning: tracy/common/TracySocket.cpp:23:16: error: ‘WSAPoll’ was not declared in this scope
warning:    23 | #  define poll WSAPoll
warning:       |                ^~~~~~~
warning: tracy/common/TracySocket.cpp:739:9: note: in expansion of macro ‘poll’
warning:   739 |     if( poll( &fd, 1, timeout ) <= 0 ) return nullptr;
warning:       |         ^~~~
warning: tracy/common/TracySocket.cpp: In member function ‘int tracy::Socket::Recv(void*, int, int)’:
warning: tracy/common/TracySocket.cpp:354:1: warning: control reaches end of non-void function [-Wreturn-type]
warning:   354 | }
warning:       | ^
warning: tracy/common/TracySocket.cpp: In member function ‘tracy::Socket* tracy::ListenSocket::Accept()’:
warning: tracy/common/TracySocket.cpp:537:1: warning: control reaches end of non-void function [-Wreturn-type]
warning:   537 | }
warning:       | ^

error: failed to run custom build command for `tracy-client-sys v0.16.0`

tracy-client-sys 0.18.0 is not on crates.io

I don't think this crate has been published. Is that on purpose? I got an incompatible message when trying to attach from 0.8.2.

Worked around it by specifying this git repository directly as dependency: tracing-tracy = { git = "https://github.com/nagisa/rust_tracy_client.git" }

Spans with lazily-recorded fields are missing those fields

I'm using code that looks like this:

let span = tracing::trace_span!(
    "image",
    resource_name = #resource_name, step_name = #step_name,
    src_layout = tracing::field::Empty, dst_layout = tracing::field::Empty,
    src_queue_family = tracing::field::Empty, dst_queue_family = tracing::field::Empty,
).entered();
    // function call that I inlined and indented here
    tracing::Span::current().record("src_layout", &format_args!("{this_layout:?}"));
    tracing::Span::current().record("dst_layout", &format_args!("{next_layout:?}"));
    tracing::Span::current().record("src_queue_family", &this_queue_runtime);
    tracing::Span::current().record("dst_queue_family", &next_queue_runtime);
// parent context:
drop(span);

With a tracing_subscriber configured to use this Registry:

let registry = tracing_subscriber::registry()
    .with(tracing_tracy::TracyLayer::new())
    .with(tracing_subscriber::fmt::layer().pretty());

The stdout subscriber has those fields filled in correctly:

2022-03-07T07:48:41.228121Z DEBUG ...
    at src\renderer.rs:3277
    in cut_for_brevity::image with resource_name: "PresentSurface", step_name: "post_present", src_layout: PRESENT_SRC_KHR, dst_layout: TRANSFER_DST_OPTIMAL, src_queue_family: 2, dst_queue_family: 0

But the zone name in Tracy is just image{resource_name="PresentSurface" step_name="blit_reference_rt"}

Is the Tracy subscriber unifying differing instances of Spans as into one archetype that gets submitted to Tracy?

Vulkan profiling

Tracy supports profiling of GPU-side work under Vulkan. It doesn't look like that's exposed yet.

Crash with long messages

veloren-voxygen: tracy/client/TracyProfiler.cpp:2186: void tracy::Profiler::SendString(uint64_t, const char*, tracy::QueueType): Assertion `len <= std::numeric_limits<uint16_t>::max()' failed.
Aborted (core dumped)

When I removed all filtering I got this crash.
I assume one of my deps is producing TRACE level events with a long message.

Assertion failed: size < std::numeric_limits<uint16_t>::max()

When registering Tracy with
tracing_subscriber::registry()
.with(TracyLayer::new().with_stackdepth(0))
.init();

on startup, my application crashes with
Assertion failed: size < std::numeric_limits<uint16_t>::max(), file ...\tracy-client-sys-0.10.0\tracy\client\TracyProfiler.hpp, line 282
error: process didn't exit successfully: target\release\world.exe (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

Docs do not explain what a tracy span is

https://docs.rs/tracy-client/latest/tracy_client/macro.span.html

It is not clear from the rust tracy client docs what a "Tracy span" is.

If we take a look in Tracy itself, they only mention the word "span" four times in their own documentation pdf.

Things that are not clear:

  • Is a Tracy span related to tokio tracing (crate tracing) span?

  • Are Tracy spans used together with Tracy frames? Or are Tracy spans and Tracy frames orthogonal to one-another?

  • When running Tracy connected to rust tracy client, where in Tracy can you see the beginnings, ends and durations of the spans you define using the rust tracy client?

Documentation on the available feature flags is not-trivial to discover

I have a remote server I'd like to profile more than once, however if I disconnect, it says:

The client you are trying to connect to is no longer able to send 
profiling data, because another server was already connected to it.
You can do the following:

1. Restart the client application.
2. Rebuild the client application with on-demand mode enabled.

Is there a way to enable on-demand mode?

Low/Minimal Allocation version of tracing_tracy

We've been extensively using tracing_tracy to profile and optimize bevy. However, one potential pain point with our usage of the crate is the overhead incurred when entering a span. This has been reported in bevyengine/bevy#4892, where I'm seeing ~10us of overhead per span. Using these in tight loops artificially inflates the size of the surrounding span and is leading to inaccurate measurements.

image

@davidbarsky suggested that it might be a good idea to write a tracing subscriber instead of a Layer using sharded_slab and caching the allocation keys in the span instead of using extensions.

Will not build for --target x86_64-pc-windows-gnu

Won't build for --target x86_64-pc-windows-gnu due to a C++ compile error involving #include <mutex>. C++ type std::mutex was apparently moved out of "std" and into "mutex" in the C++ standard library used by x86_64-pc-windows-gnu and now there's a versioning problem.

Compile error:

warning: In file included from tracy/client/TracyProfiler.hpp:18,
warning:                  from tracy/client/TracyScoped.hpp:11,
warning:                  from tracy/client/TracyProfiler.cpp:69,
warning:                  from tracy/TracyClient.cpp:23:
warning: tracy/client/../common/TracyMutex.hpp:19:25: error: ‘mutex’ in namespace ‘std’ does not name a type
warning:    19 | using TracyMutex = std::mutex;
warning:       |                         ^~~~~
warning: tracy/client/../common/TracyMutex.hpp:16:1: note: ‘std::mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
warning:    15 | #include <mutex>
warning:   +++ |+#include <mutex>
warning:    16 | 

Reproduce by

https://github.com/John-Nagle/ui-mock.git
cd ui-mock
cargo build --features tracy --examples --target x86_64-pc-windows-gnu

Run under Ubuntu 20.04.2 LTS.

Stable rustc: rustc 1.69.0 (84c898d65 2023-04-16)

macOS: Segfault just after connecting from Tracy profiler

tracing-tracy 0.3.0, macOS, Tracy 0.7.3.

Just after connecting to my tracing-tracy instrumented application from the Tracy profiler UI tool, my application segfaults. Here is the backtrace:

tracy::_memory_allocate(tracy::heap_t*, unsigned long) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/tracy_rpmalloc.cpp:0)
tracy::rpmalloc(unsigned long) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/tracy_rpmalloc.cpp:2135)
tracy::backtrace_alloc(tracy::backtrace_state*, unsigned long, void (*)(void*, char const*, int), void*) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/alloc.cpp:62)
tracy::macho_add_dsym(tracy::backtrace_state*, char const*, unsigned long, unsigned char const*, void (*)(void*, char const*, int), void*, int (**)(tracy::backtrace_state*, unsigned long, int (*)(void*, unsigned long, unsigned long, char const*, int, char const*), void (*)(void*, char const*, int), void*)) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/macho.cpp:878)
tracy::macho_add(tracy::backtrace_state*, char const*, int, long long, unsigned char const*, unsigned long, int, void (*)(void*, char const*, int), void*, int (**)(tracy::backtrace_state*, unsigned long, int (*)(void*, unsigned long, unsigned long, char const*, int, char const*), void (*)(void*, char const*, int), void*), int*) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/macho.cpp:1161)
tracy::backtrace_initialize(tracy::backtrace_state*, char const*, int, void (*)(void*, char const*, int), void*, int (**)(tracy::backtrace_state*, unsigned long, int (*)(void*, unsigned long, unsigned long, char const*, int, char const*), void (*)(void*, char const*, int), void*)) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/macho.cpp:1226)
tracy::fileline_initialize(tracy::backtrace_state*, void (*)(void*, char const*, int), void*) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/fileline.cpp:245)
tracy::backtrace_pcinfo(tracy::backtrace_state*, unsigned long, int (*)(void*, unsigned long, unsigned long, char const*, int, char const*), void (*)(void*, char const*, int), void*) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/libbacktrace/fileline.cpp:279)
tracy::DecodeCallstackPtr(unsigned long long) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/TracyCallstack.cpp:601)
tracy::Profiler::SendCallstackFrame(unsigned long long) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/TracyProfiler.cpp:2424)
tracy::Profiler::HandleServerQuery() (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/TracyProfiler.cpp:2495)
tracy::Profiler::Worker() (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/TracyProfiler.cpp:1537)
tracy::Thread::Launch(void*) (/Users/robswain/.cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-sys-0.10.0/tracy/client/TracyThread.hpp:75)
_pthread_start (@_pthread_start:42)
thread_start (@thread_start:8)

Garbage characters when using tracing

The tracy client show garbage characters in the output.

When I instrument code like

    #[tracing::instrument(skip(self, tx))]
    pub fn iter<'a>(&'a self, tx: &'a MutTxId, table_id: u32) -> Result<Iter<'a>, DBError> {

the table_id: u32 parameter is joined as zone:

iter{�[3mtable_id�[0m�[2m=�[0m1}

I expect it to be

iter (table_id:1)

or similar.

Change the client port

Hi

Is is possible to change the client port that the server connects to?

For Context:
I am testing a replicated system on localhost. I have multiple instances of the same binary. The tracy cli seems to select one of them at random to capture the profile. I would like to choose one replica myself instead by having all of them listen on different ports.

My understanding is that by including this crate is it automatically enabled at compile time. It would be kind of inconvenient to produce different binaries.

I had a brief look at all three crates but I couldn't find an exposed setting. Happy to submit a PR with some guidance.

Thanks

Control how the static library is linked

In tracy-client-sys in build.rs, inside the build_tracy_client function, you build libtracy-client.a via the cc package. On Windows, we are being provided external dll's that link against the C runtime statically. Unfortunately, your code links against the C runtime dynamically, and on Windows, all libraries that your exectuable links against must link against the C runtime the same way (either statically or dynamically). Being able to control this would be very helpful. At present this is only a problem on Windows. Our hack looks something like this:

// KEVIN: This is a hack, libcef.dll and the sandbox statically link
// to the CRT, but tracy-client-sys doesn't. This causes a linker
// error when the CRT is loaded twice. Here we force static linking.
#[cfg(all(target_os = "windows"))]
{
    builder.flag("/MT");
}

You can see our branch here. Perhaps the best way to handle this is through a feature flag? Thanks in advance.

The `-sys` crate should not unconditionally enable features

Lets make the -sys Tracy crate as general as possible. This means that in the default configuration the -sys crate should not be enabling the MANUAL_INIT and DELAYED_INIT features – this is something tracy-client should be doing via crate features.

This way even if tracy-client isn’t super applicable to somebody, they can still utilize tracy-client-sys for their needs.

Rust-Based Stack Traces Corrupt When Tracy Enabled

A real doozy of an issue here. I honestly don't know if this is a rust_tracy_client problem, a backtrace-rs problem, or a tracy problem, I'm starting here as a first line of action.

Clone this repository: https://github.com/cwfitzgerald/tracy-client-stacktrace-issue on a machine running Windows.


cargo run returns a stacktrace like normal. This is basically just a program which instantly panics.

Normal Stacktrace
thread 'main' panicked at src\main.rs:5:5:
Hello, world!
stack backtrace:
   0:     0x7ff7e03f65ba - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:99
   1:     0x7ff7e03f65ba - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff7e03f65ba - std::sys_common::backtrace::_print_fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:68
   3:     0x7ff7e03f65ba - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:44
   4:     0x7ff7e04048ab - core::fmt::rt::Argument::fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\fmt\rt.rs:142
   5:     0x7ff7e04048ab - core::fmt::write
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\fmt\mod.rs:1153
   6:     0x7ff7e03f4a81 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\io\mod.rs:1843
   7:     0x7ff7e03f63a6 - std::sys_common::backtrace::print
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:34
   8:     0x7ff7e03f83df - std::panicking::default_hook::closure$1
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:272
   9:     0x7ff7e03f8077 - std::panicking::default_hook
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:292
  10:     0x7ff7e03f891d - std::panicking::rust_panic_with_hook
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:779
  11:     0x7ff7e03f879b - std::panicking::begin_panic_handler::closure$0
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:649
  12:     0x7ff7e03f6c49 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:171
  13:     0x7ff7e03f8496 - std::panicking::begin_panic_handler
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:645
  14:     0x7ff7e04097f7 - core::panicking::panic_fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:72
  15:     0x7ff7e03f12ff - tracy_client_stacktrace::main
                               at F:\Programming\tracy-client-stacktrace\src\main.rs:5
  16:     0x7ff7e03f119b - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\core\src\ops\function.rs:250
  17:     0x7ff7e03f136e - core::hint::black_box
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\core\src\hint.rs:337
  18:     0x7ff7e03f136e - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\sys_common\backtrace.rs:155
  19:     0x7ff7e03f1291 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\rt.rs:166
  20:     0x7ff7e03f2f42 - std::rt::lang_start_internal
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\rt.rs:148
  21:     0x7ff7e03f126a - std::rt::lang_start<tuple$<> >
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\rt.rs:165
  22:     0x7ff7e03f1319 - main
  23:     0x7ff7e0407ff0 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  24:     0x7ff7e0407ff0 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  25:     0x7ff8dc9a257d - BaseThreadInitThunk
  26:     0x7ff8dd5caa48 - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\tracy-client-stacktrace.exe` (exit code: 101)

cargo run --features enable now turns on tracy_client, then panics. Pulls a completely nonsensical stacktrace.

Nonsense
thread 'main' panicked at src\main.rs:5:5:
Hello, world!
stack backtrace:
   0:     0x7ff615a8703a - <unknown>
   1:     0x7ff615a9532b - <unknown>
   2:     0x7ff615a85501 - <unknown>
   3:     0x7ff615a86e26 - <unknown>
   4:     0x7ff615a88e5f - <unknown>
   5:     0x7ff615a88af7 - <unknown>
   6:     0x7ff615a8939d - <unknown>
   7:     0x7ff615a8921b - <unknown>
   8:     0x7ff615a876c9 - <unknown>
   9:     0x7ff615a88f16 - <unknown>
  10:     0x7ff615abfd67 - <unknown>
  11:     0x7ff615a812e4 - <unknown>
  12:     0x7ff615a811ab - <unknown>
  13:     0x7ff615a8110e - <unknown>
  14:     0x7ff615a81371 - <unknown>
  15:     0x7ff615a839c2 - <unknown>
  16:     0x7ff615a8134a - <unknown>
  17:     0x7ff615a81309 - <unknown>
  18:     0x7ff615abddac - <unknown>
  19:     0x7ff8dc9a257d - BaseThreadInitThunk
  20:     0x7ff8dd5caa48 - RtlUserThreadStar

If I run this in the visual studio debugger with Break on All C++ exceptions enabled, visual studio gives a sane backtrace, so the stack itself seems correct.

VS Backtrace
 	KernelBase.dll!RaiseException�()	Unknown
>	vcruntime140.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 75	C++
 	[Inline Frame] tracy-client-stacktrace.exe!panic_unwind::real_imp::panic() Line 323	Unknown
 	tracy-client-stacktrace.exe!panic_unwind::__rust_start_panic() Line 106	Unknown
 	tracy-client-stacktrace.exe!std::panicking::rust_panic() Line 831	Unknown
 	tracy-client-stacktrace.exe!std::panicking::rust_panic_with_hook() Line 801	Unknown
 	tracy-client-stacktrace.exe!std::panicking::begin_panic_handler::closure$0() Line 658	Unknown
 	tracy-client-stacktrace.exe!std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>() Line 171	Unknown
 	tracy-client-stacktrace.exe!std::panicking::begin_panic_handler() Line 645	Unknown
 	tracy-client-stacktrace.exe!core::panicking::panic_fmt() Line 72	Unknown
 	tracy-client-stacktrace.exe!tracy_client_stacktrace::main() Line 5	Unknown
 	tracy-client-stacktrace.exe!core::ops::function::FnOnce::call_once<void (*)(),tuple$<>>(void(*)()) Line 250	Unknown
 	[Inline Frame] tracy-client-stacktrace.exe!core::hint::black_box(tuple$<>) Line 155	Unknown
 	tracy-client-stacktrace.exe!std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<>>(void(*)() f) Line 161	Unknown
 	tracy-client-stacktrace.exe!std::rt::lang_start::closure$0<tuple$<>>(std::rt::lang_start::closure_env$0<tuple$<>> *) Line 166	Unknown
 	tracy-client-stacktrace.exe!std::rt::lang_start_internal() Line 148	Unknown
 	tracy-client-stacktrace.exe!std::rt::lang_start<tuple$<>>(void(*)() main, __int64 argc, unsigned char * * argv, unsigned char sigpipe) Line 165	Unknown
 	tracy-client-stacktrace.exe!main�()	Unknown
 	[Inline Frame] tracy-client-stacktrace.exe!invoke_main() Line 78	C++
 	tracy-client-stacktrace.exe!__scrt_common_main_seh() Line 288	C++
 	kernel32.dll!BaseThreadInitThunk()	Unknown
 	ntdll.dll!RtlUserThreadStart�()	Unknown

This happens with all features disabled, only enable. This example uses manual-lifetime, but this happens without.

Tracy 0.7.6

I tried this locally and it worked fine, just needed to bump the git submodule.

I want to test a bit more before saying for certain but I think this fixes #6! :)

Make TracyCZoneCtx Send

Would it be possible to make TracyCZoneCtx Send?

Currently I'm trying to use a tracy span inside an async function, but the compiler tells me the function cannot be spawned because TracyCZoneCtx isn't Send.

error: future cannot be sent between threads safely
  --> src\kernel\kernel_ref.rs:45:14
   |
45 |             .spawn(async move {
   |              ^^^^^ future created by async block is not `Send`
   |
   = help: within `impl core::future::future::Future`, the trait `std::marker::Send` is not implemented for `*mut tracy_client_sys::TracyCZoneCtx`
note: future is not `Send` as this value is used across an await

Possible issue around span's scope

I am having a hard time figuring out if this is caused by the bindings, or tracy itself.

The following will cause the tracy client to print: Instrumentation failure: Invalid order of zone begin and end events.

            if let Some(fd) = fence_fd {
                let mut fence_span = Some(tracing_tracy::client::span!("Wait for fence"));
                let _ = self.loop_handle.insert_source(
                    Generic::new(fd, Interest::READ, calloop::Mode::Level),
                    move |_, _, _| {
                        drop(fence_span.take());
                        Ok(PostAction::Remove)
                    },
                );
            }

As far as I can tell, this should be perfectly fine to do, but it doesn't work.

Frame images

The PDF mentions an API (FrameImage) for sending screengrabs to the server. Is that something that's possible to support in the rust client?

It is possible to attach a screen capture of your application to any frame in the main frame set. This can help
you see the context of what’s happening in various places in the trace. You need to implement retrieval of
the image data from GPU by yourself.
Images are sent using the FrameImage(image, width, height, offset, flip) macro, where image is
a pointer to RGBA32 pixel data, width and height are the image dimensions, which must be divisible by 4,
offset specifies how much frame lag was there for the current image (see chapter 3.3.3.1), and flip should
be set, if the graphics API stores images upside-down33. The profiler copies the image data, so you don’t
need to retain it

Thanks in advance!

I want to be able to enable/disable via command line argument

Hi,

I was previously using version 0.10, and I was able to only enable the tracy client if my program received some CLI argument (enable-tracy, for instance).

On version 0.11, it seems to be only possible to enable/disable via feature, which would require my software to be rebuilt.

Is there any approach to that on 0.11?

Just to mention, I was doing (on 0.10), something like:

    // Redirects all gstreamer logs to tracing.
    gst::log::remove_default_log_function();
    // This fundamentally changes the CPU usage of our streams, so we are only enabling
    // this integration if absolutely necessary.
    if cli::manager::is_tracy() {
        tracing_gstreamer::integrate_events(); // This must be called before any gst::init()
        gst::init().unwrap();
        tracing_gstreamer::integrate_spans(); // This must be called after gst::init(), this is necessary to have GStreamer on tracy
    }

and

tracing-tracy = { version = "0.10.4", features = ["ondemand", "broadcast"] }

Stabilize the CI a little bit (especially the MSRV test)

Once in a while our test that tests MSRV breaks, usually due to dependency changes, and currently the best action to resolve this is to test a higher version.

We probably should check in a lock file that's used for testing of the MSRV only...

Errors resolving call stack

Hi 👋

I'm trying to use this great crate on an aarch64 macOS and running into some errors:

image image

The way I'm emitting this message from my code:

tracy_client::Client::running().unwrap().message("foo", 10);

Any ideas as to what might be going wrong? Thank you in advance!

tracing_tracy segfaults when main thread exits with other threads still running

When the main thread exits, if there are other threads that are still running, closing a span in one of those threads appears to cause a segfault. (The threads are stopped when the process exits, but it seems that they keep running while the main thread is exiting).

This example always causes a segfault on my machine (with tracy-client 0.12.6)

fn main() {
    std::thread::spawn(move || {
        loop {
            let span = tracy_client::span!("Temp");
            drop(span);
        }
    });
    std::thread::sleep(std::time::Duration::from_millis(50));
}

Here's a backtrace from the core dump:

#0  memcpy (__len=1, __src=<synthetic pointer>, __dest=0x7f880042adc0) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29
#1  tracy::MemWrite<tracy::QueueType> (val=tracy::QueueType::Callstack, ptr=0x7f880042adc0) at tracy/client/../common/TracyAlign.hpp:22
#2  tracy::Profiler::SendCallstack (this=<optimized out>, depth=depth@entry=60, skipBefore=skipBefore@entry=0x55c8703a0cf3 "__kernel_rt_sigreturn")
    at tracy/client/TracyProfiler.cpp:3058
#3  0x000055c870365499 in tracy::CrashHandler (signal=11, info=0x7f8802edb170) at tracy/client/TracyProfiler.cpp:900
#4  <signal handler called>
#5  0x000055c870366701 in memcpy (__len=<optimized out>, __src=<optimized out>, __dest=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29
#6  tracy::MemWrite<unsigned long> (val=<optimized out>, ptr=<optimized out>) at tracy/client/../common/TracyAlign.hpp:22
#7  tracy::Profiler::SendCallstack (depth=<optimized out>) at tracy/client/TracyProfiler.hpp:539
#8  ___tracy_emit_zone_begin_alloc_callstack (srcloc=140222099853920, depth=<optimized out>, active=1) at tracy/client/TracyProfiler.cpp:3483
#9  0x000055c8703456fb in tracy_client::Span::new (name=..., function=..., file=..., line=5, callstack_depth=62)
    at cargo/registry/src/github.com-1ecc6299db9ec823/tracy-client-0.12.6/src/lib.rs:92
#10 0x000055c870344f80 in repro::main::{closure#0} () at client/src/bin/repro.rs:5
#11 0x000055c870344f06 in std::sys_common::backtrace::__rust_begin_short_backtrace<repro::main::{closure#0}, ()> (f=...)
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:125
#12 0x000055c8703452bb in std::thread::{impl#0}::spawn_unchecked::{closure#0}::{closure#0}<repro::main::{closure#0}, ()> ()
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/thread/mod.rs:481
#13 core::panic::unwind_safe::{impl#23}::call_once<(), std::thread::{impl#0}::spawn_unchecked::{closure#0}::{closure#0}> (self=..., _args=<optimized out>)
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panic/unwind_safe.rs:271
#14 std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked::{closure#0}::{closure#0}>, ()> (data=<optimized out>)
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:403
#15 std::panicking::try<(), core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked::{closure#0}::{closure#0}>> (f=...)
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:367
#16 std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked::{closure#0}::{closure#0}>, ()> (f=...)
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panic.rs:129
#17 std::thread::{impl#0}::spawn_unchecked::{closure#0}<repro::main::{closure#0}, ()> () at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/thread/mod.rs:480
#18 core::ops::function::FnOnce::call_once<std::thread::{impl#0}::spawn_unchecked::{closure#0}, ()> ()
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227
#19 0x000055c8703835b3 in alloc::boxed::{impl#44}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> ()
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/alloc/src/boxed.rs:1636
#20 alloc::boxed::{impl#44}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> ()
    at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/alloc/src/boxed.rs:1636
#21 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:106
#22 0x00007f880968b450 in start_thread (arg=0x7f8802edc640) at pthread_create.c:473
#23 0x00007f880945dd53 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Client never calls `___tracy_shutdown_profiler`

tracy_client::Client doesn't provide any way to call ___tracy_shutdown_profiler, which leads to incomplete traces and complaints from the Tracy GUI:

image

I gather from other issues that there was previously some reference counting magic somewhere but it got ripped out, so I can believe it's difficult to tell when it is safe to call the shutdown function. But it does seem like not cleaning things up causes problems.

I'd love to hear more about the background than I could glean from reading tracy-client/src/state.rs.

Try to use `fiber` support to implement proper support for non-hierarchical tracing spans

Tracing spans don't need to be hierarchical, it is entirely possible to have spans looking like this

| -- S1 -- |
   | -- S2 -- |
      | -- S3 -- |

Tracy itself requires however that all spans entered in a single thread share a strong hierarchical relationship and requires that S2 and S3 both terminate before S1.

Tracy recently introduced support for fibers which, to the best of my knowledge, should give enough control to properly represent non-hierarchical spans like these.

Tracy 0.7.5

I was able to make these bindings work with tracy 0.7.5 - just needed to bump the submodule.

Logging a span without allocating

Hello! I was profiling a very performance sensitive app, and I wanted to get tracing overhead as low as possible. The implementation of Span calls ___tracy_alloc_strloc_name and ___tracy_emit_zone_begin_alloc_callstack, which were too expensive for my usecase.

In my fork (https://github.com/sujayakar/rust_tracy_client), I've added a static_span! macro that avoids dynamic allocation by using &'static strs for the function name and file name. The implementation (https://github.com/sujayakar/rust_tracy_client/blob/main/tracy-client/src/lib.rs#L67) uses some pretty gnarly nightly features. Would you be interested in my upstreaming this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.