Skip to content

Commit 5826045

Browse files
committed
Merge remote-tracking branch 'Official_hxcpp/master' into develop
2 parents 7469237 + 54af892 commit 5826045

89 files changed

Lines changed: 45708 additions & 86 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/package.yml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1618

1719
- uses: Aidan63/setup-haxe@3d3101bcd0a2001699fc8295f4d9eddd0724d3e9
1820
with:
@@ -22,16 +24,20 @@ jobs:
2224
run: |
2325
haxe -version
2426
haxelib dev hxcpp .
27+
28+
- name: 'Get Previous tag'
29+
id: previoustag
30+
uses: "WyriHaximus/github-action-get-previous-tag@v1"
31+
with:
32+
prefix: v
2533

2634
- name: Set Version
27-
run: haxe -cp tools/version --run Write ${{github.run_number}} > version.env
28-
35+
run: haxe -p tools/version --run Write ${{ steps.previoustag.outputs.tag }} > version.env
2936

3037
- name: Build Tool
3138
run: |
3239
cd tools/hxcpp
3340
haxe compile.hxml
34-
3541
3642
- name: Check XCode
3743
if: startsWith(matrix.os,'macos')
@@ -49,7 +55,7 @@ jobs:
4955
5056
- name: Archive Linux Results
5157
if: startsWith(matrix.os,'ubuntu')
52-
uses: actions/upload-artifact@v3
58+
uses: actions/upload-artifact@v4
5359
with:
5460
name: linux-64
5561
path: |
@@ -75,15 +81,15 @@ jobs:
7581
7682
- name: Archive Windows Results
7783
if: startsWith(matrix.os,'windows')
78-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
7985
with:
8086
name: windows-64
8187
path: |
8288
bin/Windows64/Cppia.exe
8389
8490
- name: Archive Mac Results
8591
if: startsWith(matrix.os,'macos')
86-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
8793
with:
8894
name: mac-64
8995
path: |
@@ -94,19 +100,19 @@ jobs:
94100
runs-on: ubuntu-latest
95101
steps:
96102
- name: Download Linux
97-
uses: actions/download-artifact@v3
103+
uses: actions/download-artifact@v4
98104
with:
99105
name: linux-64
100106
path: hxcpp
101107

102108
- name: Download Mac
103-
uses: actions/download-artifact@v3
109+
uses: actions/download-artifact@v4
104110
with:
105111
name: mac-64
106112
path: hxcpp/bin/Mac64/
107113

108114
- name: Download Windows
109-
uses: actions/download-artifact@v3
115+
uses: actions/download-artifact@v4
110116
with:
111117
name: windows-64
112118
path: hxcpp/bin/Windows64/
@@ -126,23 +132,11 @@ jobs:
126132
zip -r hxcpp-${{ env.hxcpp_release }}.zip hxcpp-${{ env.hxcpp_release }}
127133
128134
- name: Create Release
129-
id: create_release
130-
uses: actions/create-release@v1
131-
env:
132-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
uses: ncipollo/release-action@v1
133136
with:
134-
tag_name: v${{ env.hxcpp_release }}
135-
release_name: Release ${{ env.hxcpp_release }}
137+
tag: v${{ env.hxcpp_release }}
138+
commit: ${{ github.head_ref }}
139+
name: Release ${{ env.hxcpp_release }}
136140
draft: false
137141
prerelease: false
138-
139-
- name: Upload Release Asset
140-
id: upload-release-asset
141-
uses: actions/upload-release-asset@v1
142-
env:
143-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144-
with:
145-
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
146-
asset_path: ./hxcpp-${{ env.hxcpp_release }}.zip
147-
asset_name: hxcpp-${{ env.hxcpp_release }}.zip
148-
asset_content_type: application/zip
142+
artifacts: ./hxcpp-${{ env.hxcpp_release }}.zip

include/hx/GC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#ifdef HXCPP_TELEMETRY
2525
extern void __hxt_gc_new(hx::StackContext *inStack, void* obj, int inSize, const char *inName);
26+
extern void __hxt_gc_alloc(void* obj, int inSize);
27+
extern void __hxt_gc_free_large(void* obj);
2628
#endif
2729

2830

@@ -432,6 +434,7 @@ class ImmixAllocator
432434
#endif
433435

434436
#ifdef HXCPP_TELEMETRY
437+
__hxt_gc_alloc(buffer, inSize);
435438
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
436439
#endif
437440
return buffer;

include/hx/StackContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
// Newer code will use the HX_STACKFRAME macro
7474
#define HX_STACKFRAME(pos) ::hx::StackFrame _hx_stackframe(pos);
7575
#define HX_GC_STACKFRAME(pos) ::hx::StackFrame _hx_stackframe(pos);
76-
76+
7777
// Must record the stack state at the catch
7878
#define HX_STACK_BEGIN_CATCH __hxcpp_stack_begin_catch();
7979
#define HX_JUST_GC_STACKFRAME ::hx::JustGcStackFrame _hx_stackframe;

include/hx/TelemetryTracy.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef HX_TELEMETRY_TRACY_H
2+
#define HX_TELEMETRY_TRACY_H
3+
4+
#ifndef HXCPP_TRACY
5+
#error "Error: HXCPP_TRACY must be defined."
6+
#endif
7+
8+
#define TRACY_ENABLE
9+
#include <hxcpp.h>
10+
#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h"
11+
#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp"
12+
13+
#ifdef HXCPP_TRACY_MEMORY
14+
#ifdef HXCPP_GC_MOVING
15+
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active."
16+
#endif
17+
#ifdef HXCPP_GC_GENERATIONAL
18+
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active."
19+
#endif
20+
#endif
21+
22+
#ifdef HXCPP_TRACY_INCLUDE_CALLSTACKS
23+
#define HXCPP_TRACY_ZONE(name) \
24+
::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \
25+
int TracyConcat(_hx_tracy_str_length, TracyLine); \
26+
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)); \
27+
::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());
28+
#else
29+
#define HXCPP_TRACY_ZONE(name) \
30+
::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \
31+
int TracyConcat(_hx_tracy_str_length, TracyLine); \
32+
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)); \
33+
::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));
34+
#endif
35+
36+
void __hxcpp_tracy_framemark();
37+
void __hxcpp_tracy_plot(::String name, ::Float val);
38+
void __hxcpp_tracy_plot_config(::String name, uint8_t format, bool step, bool fill, int color);
39+
void __hxcpp_tracy_message(::String msg, int color);
40+
void __hxcpp_tracy_message_app_info(::String info);
41+
void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint);
42+
int __hxcpp_tracy_get_zone_count();
43+
44+
#endif

include/hxcpp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#endif
7676

7777

78-
7978
// Some compilers are over-enthusiastic about what they #define ...
8079
//#ifdef NULL
8180
//#undef NULL
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
## How to use
3+
4+
To activate the tracy integration, compile your app with:
5+
6+
```
7+
-D HXCPP_TRACY
8+
-D HXCPP_TELEMETRY
9+
-D HXCPP_STACK_TRACE
10+
-D HXCPP_STACK_LINE
11+
```
12+
13+
and use the following call in your mainloop:
14+
15+
```
16+
cpp.vm.tracy.TracyProfiler.frameMark();
17+
```
18+
19+
Then start either Tracy's UI-App or cmdline server listening on localhost and start your hxcpp-made binary.
20+
21+
22+
## Some notes about the integration
23+
24+
### Haxe-Code
25+
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.
26+
27+
There are however native parts of hxcpp that wont be visible by default in Tracy (bc there are no ZoneScopes).
28+
29+
> Note: Exceptions are in a few spots in the GC-Code, so GC becomes visible for us.
30+
31+
> Note: Hxcpp's native calls will become visible if you use the option to capture callstacks.
32+
33+
> 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.
34+
35+
### externs
36+
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
37+
38+
### externs with static/dynamic libs
39+
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
40+
41+
## Optional Features
42+
43+
### Memory Profiling
44+
45+
The following define adds tracking (de-)allocations of hxcpp's small & large object heap.
46+
47+
```
48+
-D HXCPP_TRACY_MEMORY
49+
```
50+
51+
### Capture Callstacks
52+
53+
By default we only track zones. If you wanna inspect the actual callstack per zone, you should use the following define:
54+
55+
```
56+
-D HXCPP_TRACY_INCLUDE_CALLSTACKS
57+
```
58+
59+
> Note: This will inflate the telemetry data A LOT and cost more performance. Please be aware.
60+
61+
62+
### On Demand Profiling
63+
64+
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.
65+
66+
```
67+
-D HXCPP_TRACY_ON_DEMAND
68+
```
69+
70+
### Short-lived Application Support
71+
72+
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.
73+
74+
```
75+
-D HXCPP_TRACY_NO_EXIT
76+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Tracy profiler
3+
// ----------------
4+
//
5+
// For fast integration, compile and
6+
// link with this source file (and none
7+
// other) in your executable (or in the
8+
// main DLL / shared object on multi-DLL
9+
// projects).
10+
//
11+
12+
// Define TRACY_ENABLE to enable profiler.
13+
14+
#include "common/TracySystem.cpp"
15+
16+
#ifdef TRACY_ENABLE
17+
18+
#ifdef _MSC_VER
19+
# pragma warning(push, 0)
20+
#endif
21+
22+
#include "common/tracy_lz4.cpp"
23+
#include "client/TracyProfiler.cpp"
24+
#include "client/TracyCallstack.cpp"
25+
#include "client/TracySysPower.cpp"
26+
#include "client/TracySysTime.cpp"
27+
#include "client/TracySysTrace.cpp"
28+
#include "common/TracySocket.cpp"
29+
#include "client/tracy_rpmalloc.cpp"
30+
#include "client/TracyDxt1.cpp"
31+
#include "client/TracyAlloc.cpp"
32+
#include "client/TracyOverride.cpp"
33+
#include "client/TracyKCore.cpp"
34+
35+
#if defined(TRACY_HAS_CALLSTACK)
36+
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
37+
# include "libbacktrace/alloc.cpp"
38+
# include "libbacktrace/dwarf.cpp"
39+
# include "libbacktrace/fileline.cpp"
40+
# include "libbacktrace/mmapio.cpp"
41+
# include "libbacktrace/posix.cpp"
42+
# include "libbacktrace/sort.cpp"
43+
# include "libbacktrace/state.cpp"
44+
# if TRACY_HAS_CALLSTACK == 4
45+
# include "libbacktrace/macho.cpp"
46+
# else
47+
# include "libbacktrace/elf.cpp"
48+
# endif
49+
# include "common/TracyStackFrames.cpp"
50+
# endif
51+
#endif
52+
53+
#ifdef _MSC_VER
54+
# pragma comment(lib, "ws2_32.lib")
55+
# pragma comment(lib, "dbghelp.lib")
56+
# pragma comment(lib, "advapi32.lib")
57+
# pragma comment(lib, "user32.lib")
58+
# pragma warning(pop)
59+
#endif
60+
61+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "../common/TracyAlloc.hpp"
2+
3+
#ifdef TRACY_USE_RPMALLOC
4+
5+
#include <atomic>
6+
7+
#include "../common/TracyForceInline.hpp"
8+
#include "../common/TracyYield.hpp"
9+
10+
namespace tracy
11+
{
12+
13+
extern thread_local bool RpThreadInitDone;
14+
extern std::atomic<int> RpInitDone;
15+
extern std::atomic<int> RpInitLock;
16+
17+
tracy_no_inline static void InitRpmallocPlumbing()
18+
{
19+
const auto done = RpInitDone.load( std::memory_order_acquire );
20+
if( !done )
21+
{
22+
int expected = 0;
23+
while( !RpInitLock.compare_exchange_weak( expected, 1, std::memory_order_release, std::memory_order_relaxed ) ) { expected = 0; YieldThread(); }
24+
const auto done = RpInitDone.load( std::memory_order_acquire );
25+
if( !done )
26+
{
27+
rpmalloc_initialize();
28+
RpInitDone.store( 1, std::memory_order_release );
29+
}
30+
RpInitLock.store( 0, std::memory_order_release );
31+
}
32+
rpmalloc_thread_initialize();
33+
RpThreadInitDone = true;
34+
}
35+
36+
TRACY_API void InitRpmalloc()
37+
{
38+
if( !RpThreadInitDone ) InitRpmallocPlumbing();
39+
}
40+
41+
}
42+
43+
#endif

0 commit comments

Comments
 (0)