Skip to content

Commit

Permalink
Merge branch 'HaxeFoundation:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
MAJigsaw77 authored Oct 24, 2024
2 parents 4e0ec86 + 54af892 commit a13d4ad
Show file tree
Hide file tree
Showing 89 changed files with 45,708 additions and 86 deletions.
48 changes: 21 additions & 27 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: Aidan63/setup-haxe@3d3101bcd0a2001699fc8295f4d9eddd0724d3e9
with:
Expand All @@ -22,16 +24,20 @@ jobs:
run: |
haxe -version
haxelib dev hxcpp .
- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
prefix: v

- name: Set Version
run: haxe -cp tools/version --run Write ${{github.run_number}} > version.env

run: haxe -p tools/version --run Write ${{ steps.previoustag.outputs.tag }} > version.env

- name: Build Tool
run: |
cd tools/hxcpp
haxe compile.hxml
- name: Check XCode
if: startsWith(matrix.os,'macos')
Expand All @@ -49,7 +55,7 @@ jobs:
- name: Archive Linux Results
if: startsWith(matrix.os,'ubuntu')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: linux-64
path: |
Expand All @@ -75,15 +81,15 @@ jobs:
- name: Archive Windows Results
if: startsWith(matrix.os,'windows')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: windows-64
path: |
bin/Windows64/Cppia.exe
- name: Archive Mac Results
if: startsWith(matrix.os,'macos')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mac-64
path: |
Expand All @@ -94,19 +100,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download Linux
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: linux-64
path: hxcpp

- name: Download Mac
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: mac-64
path: hxcpp/bin/Mac64/

- name: Download Windows
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: windows-64
path: hxcpp/bin/Windows64/
Expand All @@ -126,23 +132,11 @@ jobs:
zip -r hxcpp-${{ env.hxcpp_release }}.zip hxcpp-${{ env.hxcpp_release }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: v${{ env.hxcpp_release }}
release_name: Release ${{ env.hxcpp_release }}
tag: v${{ env.hxcpp_release }}
commit: ${{ github.head_ref }}
name: Release ${{ env.hxcpp_release }}
draft: false
prerelease: false

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./hxcpp-${{ env.hxcpp_release }}.zip
asset_name: hxcpp-${{ env.hxcpp_release }}.zip
asset_content_type: application/zip
artifacts: ./hxcpp-${{ env.hxcpp_release }}.zip
3 changes: 3 additions & 0 deletions include/hx/GC.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#ifdef HXCPP_TELEMETRY
extern void __hxt_gc_new(hx::StackContext *inStack, void* obj, int inSize, const char *inName);
extern void __hxt_gc_alloc(void* obj, int inSize);
extern void __hxt_gc_free_large(void* obj);
#endif


Expand Down Expand Up @@ -430,6 +432,7 @@ class ImmixAllocator
#endif

#ifdef HXCPP_TELEMETRY
__hxt_gc_alloc(buffer, inSize);
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
#endif
return buffer;
Expand Down
2 changes: 1 addition & 1 deletion include/hx/StackContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
// Newer code will use the HX_STACKFRAME macro
#define HX_STACKFRAME(pos) ::hx::StackFrame _hx_stackframe(pos);
#define HX_GC_STACKFRAME(pos) ::hx::StackFrame _hx_stackframe(pos);

// Must record the stack state at the catch
#define HX_STACK_BEGIN_CATCH __hxcpp_stack_begin_catch();
#define HX_JUST_GC_STACKFRAME ::hx::JustGcStackFrame _hx_stackframe;
Expand Down
44 changes: 44 additions & 0 deletions include/hx/TelemetryTracy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef HX_TELEMETRY_TRACY_H
#define HX_TELEMETRY_TRACY_H

#ifndef HXCPP_TRACY
#error "Error: HXCPP_TRACY must be defined."
#endif

#define TRACY_ENABLE
#include <hxcpp.h>
#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h"
#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp"

#ifdef HXCPP_TRACY_MEMORY
#ifdef HXCPP_GC_MOVING
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active."
#endif
#ifdef HXCPP_GC_GENERATIONAL
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active."
#endif
#endif

#ifdef HXCPP_TRACY_INCLUDE_CALLSTACKS
#define HXCPP_TRACY_ZONE(name) \
::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \
int TracyConcat(_hx_tracy_str_length, TracyLine); \
const char *TracyConcat(_hx_tracy_str_buffer_ptr, TracyLine) = name.utf8_str(&TracyConcat(_hx_tracy_str_buffer, TracyLine), false, &TracyConcat(_hx_tracy_str_length, TracyLine)); \
::tracy::ScopedZone TracyConcat(_hx_tracy_scoped_zone,TracyLine)(_hx_stackframe.lineNumber, _hx_stackframe.position->fileName, strlen(_hx_stackframe.position->fileName), _hx_stackframe.position->fullName, strlen(_hx_stackframe.position->fullName), TracyConcat(_hx_tracy_str_buffer_ptr, TracyLine), TracyConcat(_hx_tracy_str_length, TracyLine), __hxcpp_tracy_get_zone_count());
#else
#define HXCPP_TRACY_ZONE(name) \
::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \
int TracyConcat(_hx_tracy_str_length, TracyLine); \
const char *TracyConcat(_hx_tracy_str_buffer_ptr, TracyLine) = name.utf8_str(&TracyConcat(_hx_tracy_str_buffer, TracyLine), false, &TracyConcat(_hx_tracy_str_length, TracyLine)); \
::tracy::ScopedZone TracyConcat(_hx_tracy_scoped_zone,TracyLine)(_hx_stackframe.lineNumber, _hx_stackframe.position->fileName, strlen(_hx_stackframe.position->fileName), _hx_stackframe.position->fullName, strlen(_hx_stackframe.position->fullName), TracyConcat(_hx_tracy_str_buffer_ptr, TracyLine), TracyConcat(_hx_tracy_str_length, TracyLine));
#endif

void __hxcpp_tracy_framemark();
void __hxcpp_tracy_plot(::String name, ::Float val);
void __hxcpp_tracy_plot_config(::String name, uint8_t format, bool step, bool fill, int color);
void __hxcpp_tracy_message(::String msg, int color);
void __hxcpp_tracy_message_app_info(::String info);
void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint);
int __hxcpp_tracy_get_zone_count();

#endif
1 change: 0 additions & 1 deletion include/hxcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#endif



// Some compilers are over-enthusiastic about what they #define ...
//#ifdef NULL
//#undef NULL
Expand Down
76 changes: 76 additions & 0 deletions project/thirdparty/tracy-0.11.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

## How to use

To activate the tracy integration, compile your app with:

```
-D HXCPP_TRACY
-D HXCPP_TELEMETRY
-D HXCPP_STACK_TRACE
-D HXCPP_STACK_LINE
```

and use the following call in your mainloop:

```
cpp.vm.tracy.TracyProfiler.frameMark();
```

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).

> Note: Exceptions are in a few spots in the GC-Code, so GC becomes visible for us.
> Note: Hxcpp's native calls will become visible if you use the option to capture callstacks.
> Note: We capture source-locations and their filepaths. By default these are relative to your project and thus the sourcecode preview / browsing in Tracy wont work since it expects absolute paths. To solve this you can use `-D absolute-path` in your builds.
### 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.pdf

### 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

## Optional Features

### Memory Profiling

The following define adds tracking (de-)allocations of hxcpp's small & large object heap.

```
-D HXCPP_TRACY_MEMORY
```

### Capture Callstacks

By default we only track zones. If you wanna inspect the actual callstack per zone, you should use the following define:

```
-D HXCPP_TRACY_INCLUDE_CALLSTACKS
```

> Note: This will inflate the telemetry data A LOT and cost more performance. Please be aware.

### 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.

```
-D HXCPP_TRACY_ON_DEMAND
```

### 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.

```
-D HXCPP_TRACY_NO_EXIT
```
61 changes: 61 additions & 0 deletions project/thirdparty/tracy-0.11.1/TracyClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// 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 "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
43 changes: 43 additions & 0 deletions project/thirdparty/tracy-0.11.1/client/TracyAlloc.cpp
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
Loading

0 comments on commit a13d4ad

Please sign in to comment.