Commit Graph

271 Commits

Author SHA1 Message Date
Blake Taylor
cc33846111 Fix unreachable error when compiling warnings as errors + timer fallback 2022-05-02 16:35:48 -07:00
Michael Puskas
a5ea07f107 Fix build options, add TRACY_TIMER_FALLBACK option.
Renamed TRACY_NO_SYS_TRACE -> TRACY_NO_SYSTEM_TRACING to match the
build flag name. Unlike the meson logic, the CMake logic directly
maps the option name to the build flag that is injected. With the
mismatched name, the flag wasn't being properly applied.

Added TRACY_TIMER_FALLBACK option to expose the same-named flag.

Moved signal.h include to get sigaction definition that was missing when
TRACY_NO_CALLSTACK was defined.
2022-05-01 13:52:27 -07:00
Bartosz Taudul
aa2bbfe5f9
Transfer executable image name in source file queries. 2022-05-01 14:30:18 +02:00
Bartosz Taudul
d318f75123
Merge pull request #325 from BrychDaneel/automatic_timer_fallback
Automatic timer fallback
2022-02-21 13:47:50 +01:00
Daniil Brychikov
a9ba1ce688 Codestyle fixes 2022-02-19 11:44:15 +03:00
Daniil Brychikov
73f6c66cde Automatic timer fallback 2022-02-16 15:18:45 +03:00
Bartosz Taudul
9f2ffb05ac
Check if memory can be allocated in a thread.
Consider running the following code with operator new and delete overloaded to
track allocations with call stacks:

std::thread( []({ thread_local std::string str; });

Each call stack requires a memory allocation to be performed by the profiler,
to make the stack available at a later time. When the thread is created, the
TLS block is initialized and the std::string buffer can be allocated. To track
this allocation, rpmalloc has to be initialized. This initialization also
happens within the TLS block.

Now, when the thread exits, the heap managed by rpmalloc may be released first
during the TLS block destruction (and if the destruction is performed in
reverse creation order, then it *will* be destroyed first, as rpmalloc was
initialized only after the std::string initialization, to track the allocation
performed within). The next thing to happen is destruction of std::string and
release of the memory block it contains.

The release is tracked by the profiler, and as mentioned earlier, to save the
call stack for later use, a memory allocation is needed. But the allocator is
no longer available in this thread, because rpmalloc was released just before!

As a solution to this issue, profiler will detect whether the allocator is
still available and will ignore the call stack, if it's not. The other
solution is to disable the rpmalloc thread cleanup, which may potentially
cause leak-like behavior, in case a large number of threads is spawned and
destroyed.

Note that this is not a water-tight solution. Other functions will still want
to allocate memory for call stacks, but it is rather unlikely that such calls
would be performed during TLS block destruction. It is also possible that the
event queue will run out of allocated space for events at this very moment,
and in such a case the allocator will also fail.
2022-02-14 17:55:46 +01:00
Bartosz Taudul
793e6b0e29
Add rpmalloc thread state accessor. 2022-02-14 17:53:27 +01:00
Bartosz Taudul
8428ede59d
Retrieve kernel symbols on Windows. 2021-11-25 23:12:41 +01:00
Bartosz Taudul
4bde9022e1
Properly acknowledge unavailable symbol code. 2021-11-25 22:44:56 +01:00
Bartosz Taudul
e8fb2abb2a
Dispatch kernel code retrieval. 2021-11-25 22:27:35 +01:00
Bartosz Taudul
a203eb5aef
Adapt to SPSCQueue interface. 2021-11-14 18:50:59 +01:00
Bartosz Taudul
765561de81
Serialize continuous frame events. 2021-11-05 01:13:24 +01:00
Nathan Day
4fece233d9 Added unused parameters when TRACY_HAS_CALLSTACK is undefined 2021-11-04 15:24:58 +00:00
Bartosz Taudul
229d547e91
Add fiber support on client side. 2021-11-02 00:11:09 +01:00
Bartosz Taudul
02ce9b7d8b
Extract symbol queue item handling. 2021-10-23 01:35:01 +02:00
Bartosz Taudul
2b9265cc40
Move symbol resolution to a separate thread. 2021-10-22 22:25:09 +02:00
Bartosz Taudul
b4cfb1f2d5
Add SPSC symbol queue. 2021-10-22 22:22:27 +02:00
Bartosz Taudul
6d490ffd28
Revert "Use SPSC queue for frame images."
This reverts commit 02e76faff7.

Let's not limit frame image reporting to just one thread.
2021-10-20 23:18:03 +02:00
Bartosz Taudul
ce2a7d6741
Offset field is not used. 2021-10-20 22:57:23 +02:00
Bartosz Taudul
02e76faff7
Use SPSC queue for frame images. 2021-10-20 22:57:23 +02:00
Bartosz Taudul
5ccf369919
Implement callstack serialization. 2021-10-10 16:14:17 +02:00
Bartosz Taudul
082255f940
Messages may now use serialized queue. 2021-10-10 15:54:21 +02:00
Bartosz Taudul
2cea5bc5b2
Add C API async-or-sync queue macros. 2021-10-09 15:50:30 +02:00
Bartosz Taudul
2d5d4293a9
Move thread context check to a separate function. 2021-10-09 15:16:36 +02:00
Bartosz Taudul
6411b35d68
Provide macros for async-or-sync queue insertion.
If fibers are enabled, then some events which were traditionally stored in
async queues will have to be serialized. These macros provide the needed
infrastructure for this.
2021-10-09 14:55:32 +02:00
Bartosz Taudul
250ef2cf6e
Change thread id size from 64 to 32 bits.
Both Windows and Linux use 32-bit thread identifiers. MacOS has a 64-bit
counter, but in practice it will never overflow during profiling and no false
aliasing will happen.

These changes are only done client-side and in the network protocol. The
server still uses 64-bit thread identifiers, to enable virtual threads, etc.
2021-10-08 00:42:52 +02:00
Bartosz Taudul
07bc665d8c
Drop support for Cygwin. 2021-10-07 23:28:40 +02:00
Bartosz Taudul
924224501e
Remove exception handler during profiler destruction. 2021-07-25 11:48:27 +02:00
Bartosz Taudul
61c9e8e6d8
Crash handler may be not installed. 2021-07-25 11:46:20 +02:00
Bartosz Taudul
54fa21bcbb
Restore original signal handlers on profiler exit. 2021-07-25 11:40:22 +02:00
Bartosz Taudul
b0fc0d5dcc
Check if rpmalloc has to be initialized before each operation.
The C++11 spec states in [basic.stc.thread] thread storage duration:

2. A variable with thread storage duration shall be initialized before its
   first odr-use (3.2) and, if constructed, shall be destroyed on thread exit.

Previously Tracy relied on the TLS data being initialized:
- During thread creation (MSVC).
- Or during first use in a thread, but the initialization was performed for
  the whole TLS block.

It seems that new compilers are more granular with how they perform the
initialization, hence rpmalloc init has to be checked before each allocation,
as it cannot be "folded" into, for example, initialization of the profiler
itself.
2021-05-31 02:31:42 +02:00
Bartosz Taudul
eb7d220eea
Added support for TRACY_NO_FRAME_IMAGE define. 2021-04-29 20:55:16 +02:00
Bartosz Taudul
c288a7903b
Make {Startup,Shutdown}Profiler() signatures consistent. 2021-03-08 02:39:51 +01:00
Bartosz Taudul
9cfc36f92e Preserve valid order of server query acknowledgements. 2021-02-07 20:53:20 +01:00
Bartosz Taudul
ad2062fb40 Last-resort source code transfer from client to server. 2021-02-04 00:45:00 +01:00
Bartosz Taudul
0ce113a96c Check mtime of profiled executable. 2021-01-31 17:45:31 +01:00
Bartosz Taudul
33ca38b581 Add a define for fallback timer usage. 2021-01-28 18:49:17 +01:00
Bartosz Taudul
b58358f81f Cosmetics. 2021-01-28 18:49:12 +01:00
Bartosz Taudul
6b276a1a64 Init rpmalloc thread-local data when sending messages.
There was a possibility of having uninitialized TLS block there, if the first
thing done in a thread was sending a message.
2021-01-27 02:14:23 +01:00
Bartosz Taudul
90de2d2f73 Support queuing serial items with callstack. 2021-01-15 22:11:34 +01:00
Bartosz Taudul
d4c0d4fbb7 Rename CallstackMemory to CallstackSerial. 2021-01-15 20:49:39 +01:00
Felipe Oliveira Carvalho
c9865c5f95 Fix integer type warnings
This is necessary to compile Tracy-instrumented code in
codebases built with -Werror.
2020-11-19 16:36:01 +01:00
Bartosz Taudul
bd31e3d2d6 Send callstacks before sending events they belong to. 2020-09-29 16:40:19 +02:00
Bartosz Taudul
4db092437c Add support for custom allocator tracking to client. 2020-09-24 01:31:23 +02:00
Bartosz Taudul
9258e2ced0 Restore TSC usage on Linux. 2020-08-13 01:41:05 +02:00
Bartosz Taudul
649994706b Use clock monotonic raw on Linux.
Because Linux kernel interfaces are fucking stupid.
2020-08-12 16:49:30 +02:00
Bartosz Taudul
b76726c597 No need for lean callstack, callstack memory messages. 2020-07-26 14:23:03 +02:00
Bartosz Taudul
b7af9a0860 Reduce frame images frame index to 32 bit. 2020-07-26 13:46:05 +02:00
Bartosz Taudul
c0b73c248f Add second single string transfer. 2020-07-26 01:47:49 +02:00