-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tracy client * add Aidan's StackContext Zone * a bit more documentation * doc cleanup * add HXCPP_TRACY_DISABLE_STACKS flag
- Loading branch information
Showing
79 changed files
with
45,255 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
To activate the tracy integration, compile your app with: | ||
|
||
``` | ||
-D HXCPP_TRACY | ||
-D HXCPP_STACK_TRACE | ||
``` | ||
|
||
and use the following call in your mainloop: | ||
|
||
``` | ||
#if defined(HXCPP_TRACY) | ||
untyped __cpp__('FrameMark'); | ||
#endif | ||
``` | ||
|
||
> Note: The Tracy-Headers are included with `hxcpp.h` and the Tracy Macros should be available everywhere in your code. | ||
> Alternatively you can use this simple extern class in your project: https://gist.github.com/dazKind/b36475c0846491aefdfb12c5f831daba | ||
|
||
Then start Tracy listening on localhost and start your hxcpp-made exe. | ||
|
||
|
||
## Some notes about the integration | ||
### Haxe-Code | ||
We hook Tracy into hxcpp's `hx::StackContext` and this way it spreads over all generated cpp code catching & measuring all the callstacks. | ||
|
||
There are however native parts of hxcpp that wont be visible by default in Tracy (bc there are no ZoneScopes). | ||
> Note: There is a exception in the GC-Code, so it becomes visible for us. | ||
### externs | ||
The same is true about externs you might be using in your project. If you want to make these visible, you need to add Tracy's C-Macros yourself in the extern's c/cpp-code. You should be able to include Tracy's client headers or if it's cpp-files you can just `#include <hxcpp.h>`, which you need for precompiled headers anyway. | ||
|
||
### externs with static/dynamic libs | ||
Another special case are static or dynamic libs your externs might be using. For these you will have to make more changes that are beyond the scope of this doc here, please refer to Tracy's official documentation over here: https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Tracy profiler | ||
// ---------------- | ||
// | ||
// For fast integration, compile and | ||
// link with this source file (and none | ||
// other) in your executable (or in the | ||
// main DLL / shared object on multi-DLL | ||
// projects). | ||
// | ||
|
||
// Define TRACY_ENABLE to enable profiler. | ||
|
||
#include "hxcpp.h" | ||
#include "common/TracySystem.cpp" | ||
|
||
#ifdef TRACY_ENABLE | ||
|
||
#ifdef _MSC_VER | ||
# pragma warning(push, 0) | ||
#endif | ||
|
||
#include "common/tracy_lz4.cpp" | ||
#include "client/TracyProfiler.cpp" | ||
#include "client/TracyCallstack.cpp" | ||
#include "client/TracySysPower.cpp" | ||
#include "client/TracySysTime.cpp" | ||
#include "client/TracySysTrace.cpp" | ||
#include "common/TracySocket.cpp" | ||
#include "client/tracy_rpmalloc.cpp" | ||
#include "client/TracyDxt1.cpp" | ||
#include "client/TracyAlloc.cpp" | ||
#include "client/TracyOverride.cpp" | ||
#include "client/TracyKCore.cpp" | ||
|
||
#if defined(TRACY_HAS_CALLSTACK) | ||
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6 | ||
# include "libbacktrace/alloc.cpp" | ||
# include "libbacktrace/dwarf.cpp" | ||
# include "libbacktrace/fileline.cpp" | ||
# include "libbacktrace/mmapio.cpp" | ||
# include "libbacktrace/posix.cpp" | ||
# include "libbacktrace/sort.cpp" | ||
# include "libbacktrace/state.cpp" | ||
# if TRACY_HAS_CALLSTACK == 4 | ||
# include "libbacktrace/macho.cpp" | ||
# else | ||
# include "libbacktrace/elf.cpp" | ||
# endif | ||
# include "common/TracyStackFrames.cpp" | ||
# endif | ||
#endif | ||
|
||
#ifdef _MSC_VER | ||
# pragma comment(lib, "ws2_32.lib") | ||
# pragma comment(lib, "dbghelp.lib") | ||
# pragma comment(lib, "advapi32.lib") | ||
# pragma comment(lib, "user32.lib") | ||
# pragma warning(pop) | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "../common/TracyAlloc.hpp" | ||
|
||
#ifdef TRACY_USE_RPMALLOC | ||
|
||
#include <atomic> | ||
|
||
#include "../common/TracyForceInline.hpp" | ||
#include "../common/TracyYield.hpp" | ||
|
||
namespace tracy | ||
{ | ||
|
||
extern thread_local bool RpThreadInitDone; | ||
extern std::atomic<int> RpInitDone; | ||
extern std::atomic<int> RpInitLock; | ||
|
||
tracy_no_inline static void InitRpmallocPlumbing() | ||
{ | ||
const auto done = RpInitDone.load( std::memory_order_acquire ); | ||
if( !done ) | ||
{ | ||
int expected = 0; | ||
while( !RpInitLock.compare_exchange_weak( expected, 1, std::memory_order_release, std::memory_order_relaxed ) ) { expected = 0; YieldThread(); } | ||
const auto done = RpInitDone.load( std::memory_order_acquire ); | ||
if( !done ) | ||
{ | ||
rpmalloc_initialize(); | ||
RpInitDone.store( 1, std::memory_order_release ); | ||
} | ||
RpInitLock.store( 0, std::memory_order_release ); | ||
} | ||
rpmalloc_thread_initialize(); | ||
RpThreadInitDone = true; | ||
} | ||
|
||
TRACY_API void InitRpmalloc() | ||
{ | ||
if( !RpThreadInitDone ) InitRpmallocPlumbing(); | ||
} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.