-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for Tracy profiler #1153
Conversation
* add tracy client * add Aidan's StackContext Zone * a bit more documentation * doc cleanup * add HXCPP_TRACY_DISABLE_STACKS flag
Ok, seems like 1426a88 fixes the pipelines. That also means that the tracy include has sideeffects for mysql on macos. Interesting. |
The tracy source files should be moved to Now that we've got a better idea of what we need to do I wonder if a better approach is to make a tracy implementation of the hxcpp telemetry api. I.e. Have a TracyTelemetry.cpp which implements all the Also wonder if we can do something similar for the hxcpp profiler api, might be able to provide a tracy implementation of that for custom zones, advantage being |
Another plus of a dedicated TracyTelemetry.cpp file is then only that needs to include tracy headers, so we dodge that mac sql issue you mentioned entirely. |
…ection in haxe-target.xml
…callstacks in the profiler zones
…cy_source_location_data
Ok, things have settled and we can move out of draft now. Major kudos for @Aidan63 who was instrumental in making this a reality and taking it way beyond the initial scope in a relatively short amount of time! Working on this has been a blast! |
i used hxscout once forever ago and had a hard time figuring it out, so this looks like it would be a big improvement |
The hxscout killer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this with Funkin' and it worked brilliantly with minimal setup.
Note: This works on Haxe 4.3.6 also, as long as the cpp.vm.tracy.TraceyProfiler
class from the linked project is included somewhere in the workspace (you don't need to use a fork of Haxe).
I don't really feel qualified to review this properly, but if @Aidan63 says it's good then I'm happy to merge it. I've already merged HaxeFoundation/haxe#11772, is there anything else we should do before merging here? |
Good morning,
Nothing else required. |
Tracy profiler is increasing the memory usage of my openfl application from megabytes to gigabytes. I think there might be a memory leak somewhere. |
No, this is actually expected. Make sure you have either the UI or the cmdline capturer active & connected to your app. By default your app will start collecting telemetry data from its startup till it receives an active connection to either the Tracy UI application or one of the shell loggers and then it will transmit & release all that data. If you only want to capture telemetry data ONLY when a connections is active, use the mentioned compile flag mentioned in I can only recommend you study documentation here: https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdf |
I'm already trying it this way, please apply the change I made in OpenFL and run the example. |
I have no idea what example you are talking about or why you think this is problematic behavior. You reported that there might be a leak. I'm sorry I lack context to understand what brings you to that conclusion. Do you crash or what is it exactly that you consider a problem there? If you activate Tracy there is a lot of data generated and you need a computer that is able to transfer and crunch all these numbers. If you cant provide some more background information and/or a minimal example that reproduces what you consider an issue I cant help you. |
Please refer to my last comment:
|
Problem Statement
As a Haxe developer I want to be able to reliably profile the performance of my engine & hxcpp apps in a ergonomic, lightweight and battletested manner.
I have looked at HxTelemetry and HxScout and found them lacking in usability and support. The app is constantly crashing for me, like 10 years old and not officially opensource? Also I question the use of the AMF protocol these days.
Solution
This PR adds support for Tracy Profiler
Anyway, we looked around and we found the Tracy Profiler which seems to satisfy my need perfectly. While I'm happy to run & maintain my own fork for my engine, I think this is something the whole community can benefit from, this is why I'm opening a PR for review & discussion.
How to use
To activate the tracy integration, compile your app with:
and use the following call at the very end of your mainloop, so it gets called every frame:
Then start either Tracy's UI-App or cmdline server listening on localhost and start your hxcpp-made binary.
Some notes about the integration
Haxe-Code
We integrate Tracy into hxcpp as a Telemetry option which utilizes
hx::StackPosition
and offer a set of static functions to set zones and other tracy functionality. Through this all your haxe-code will be captured in a profiler-session.There are however native parts of hxcpp that wont be visible by default in Tracy (bc there are no ZoneScopes).
externs
The same is true about externs you might be using in your project. If you want to make these visible, you need to
@:include('hx/TelemetryTracy.h')
and you gain access to Tracy's C-Macros that you can use in your extern's c/cpp-code. Please refer to the official Tracy documentation: https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdfexterns 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
Optional Features
Memory Profiling
The following define adds tracking (de-)allocations of hxcpp's small & large object heap.
Capture Callstacks
By default we only track zones. If you wanna inspect the actual callstack per zone, you should use the following define:
On Demand Profiling
By default this integration will start sampling & collecting telemetry with the start of your application. You can change this behavior by the following define and your app will only generate telemetry if the Tracy Profiler app is open and reachable.
Short-lived Application Support
In cases where you dont have a mainloop or a very short-lived application you can use the following define to let your application stay around to complete sending telemetry data it has collected.
Questions relevant for hxcpp & this PR