From e2a265ac3b86dd4ab661c243235a89233dfa22c8 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 10:14:23 +0200 Subject: [PATCH 01/15] add Windows support for ITT Reference Collector --- CMakeLists.txt | 24 ++++++ buildall.py | 5 +- src/ittnotify_refcol/itt_refcol_impl.c | 114 ++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c97cf9..231f4e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(FORCE_32 "Force a 32-bit compile on 64-bit" OFF) option(ITT_API_IPT_SUPPORT "ptmarks support" OFF) option(ITT_API_FORTRAN_SUPPORT "fortran support" OFF) option(ITT_API_CPP_SUPPORT "C++ wrapper support" OFF) +option(ITT_API_REFERENCE_COLLECTOR "Build reference collector shared library" OFF) option(ITT_API_INSTALL "Enable ITT API installation rules" ON) if(FORCE_32 AND UNIX) @@ -141,6 +142,29 @@ add_library(ittapi::ittnotify ALIAS ittnotify) set(JITPROFILING_SRC "src/ittnotify/jitprofiling.c") add_library(jitprofiling STATIC ${JITPROFILING_SRC}) +if(ITT_API_REFERENCE_COLLECTOR) + add_library(ittnotify_refcol SHARED src/ittnotify_refcol/itt_refcol_impl.c) + + target_include_directories(ittnotify_refcol + PUBLIC $ + PRIVATE src/ittnotify + ) + + target_link_libraries(ittnotify_refcol PRIVATE ${CMAKE_DL_LIBS}) + set_target_properties(ittnotify_refcol PROPERTIES + LINKER_LANGUAGE C + RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) + + if(WIN32) + set_target_properties(ittnotify_refcol PROPERTIES + OUTPUT_NAME libittnotify_refcol + WINDOWS_EXPORT_ALL_SYMBOLS ON) + else() + set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME ittnotify_refcol) + endif() +endif() + if(WIN32) set_target_properties(ittnotify PROPERTIES OUTPUT_NAME libittnotify) set_target_properties(jitprofiling PROPERTIES OUTPUT_NAME libjitprofiling) diff --git a/buildall.py b/buildall.py index 180f7fe..058cd46 100755 --- a/buildall.py +++ b/buildall.py @@ -119,6 +119,8 @@ def main(): "-ft", "--fortran", help="enable fortran support", action="store_true") parser.add_argument( "-cpp", "--cpp", help="enable C++ wrapper support", action="store_true") + parser.add_argument( + "--refcol", help="enable reference collector build", action="store_true") parser.add_argument( "--force_bits", choices=["32", "64"], help="specify bit version for the target") if sys.platform == 'win32' and vs_versions: @@ -180,7 +182,8 @@ def main(): ('-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' if args.verbose else ''), ("-DITT_API_IPT_SUPPORT=1" if args.ptmark else ""), ("-DITT_API_FORTRAN_SUPPORT=1" if args.fortran else ""), - ("-DITT_API_CPP_SUPPORT=ON" if args.cpp else "") + ("-DITT_API_CPP_SUPPORT=ON" if args.cpp else ""), + ("-DITT_API_REFERENCE_COLLECTOR=ON" if args.refcol else "") ]))) if sys.platform == 'win32': diff --git a/src/ittnotify_refcol/itt_refcol_impl.c b/src/ittnotify_refcol/itt_refcol_impl.c index 42571e8..bab88d5 100644 --- a/src/ittnotify_refcol/itt_refcol_impl.c +++ b/src/ittnotify_refcol/itt_refcol_impl.c @@ -4,8 +4,10 @@ SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause */ +#include #include #include +#include #include #include #include @@ -45,15 +47,37 @@ static struct ref_collector_global { __itt_histogram* histogram_list; } g_ref_collector_global = {MUTEX_INITIALIZER, 0, NULL, NULL, NULL, NULL}; +#ifdef _WIN32 + #define REFCOL_LOCALTIME(out_tm, in_time) (localtime_s((out_tm), (in_time)) == 0) +#else + #define REFCOL_LOCALTIME(out_tm, in_time) (localtime_r((in_time), (out_tm)) != NULL) +#endif + static char* log_file_name_generate() { time_t time_now = time(NULL); - struct tm* time_info = localtime(&time_now); + struct tm* time_info = malloc(sizeof(struct tm)); char* log_file_name = malloc(sizeof(char) * (LOG_BUFFER_MAX_SIZE/2)); + if (log_file_name == NULL) + { + printf("ERROR: Failed to allocate memory for log file name\n"); + free(time_info); + return NULL; + } + + if (!REFCOL_LOCALTIME(time_info, &time_now)) + { + printf("ERROR: Failed to get local time for log file name\n"); + free(time_info); + free(log_file_name); + return NULL; + } + sprintf(log_file_name,"libittnotify_refcol_%d%d%d%d%d%d.log", time_info->tm_year+1900, time_info->tm_mon+1, time_info->tm_mday, time_info->tm_hour, time_info->tm_min, time_info->tm_sec); + free(time_info); return log_file_name; } @@ -85,6 +109,10 @@ static void ref_collector_init() { sprintf(file_name_buffer,"%s\\%s", temp_dir, log_file); } + else + { + sprintf(file_name_buffer,"%s", log_file); + } #else sprintf(file_name_buffer,"/tmp/%s", log_file); #endif @@ -364,7 +392,45 @@ static char* get_context_metadata_element(__itt_context_type type, void* metadat return metadata_str; } +#ifdef _WIN32 +static char* wchar2char(const wchar_t* wide_str) +{ + if (wide_str == NULL) + { + return NULL; + } + + int narrow_size = WideCharToMultiByte(CP_UTF8, 0, wide_str, -1, NULL, 0, NULL, NULL); + if (narrow_size <= 0) + { + return NULL; + } + + char* narrow_str = (char*)malloc((size_t)narrow_size); + if (narrow_str == NULL) + { + return NULL; + } + + if (!WideCharToMultiByte(CP_UTF8, 0, wide_str, -1, narrow_str, narrow_size, NULL, NULL)) + { + free(narrow_str); + return NULL; + } + + return narrow_str; +} +#endif + +#ifdef _WIN32 +ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_createW(const wchar_t *name) +{ + return __itt_domain_createA(wchar2char(name)); +} +ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_createA(const char *name) +#else ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_create(const char *name) +#endif { if (!g_ref_collector_global.mutex_initialized || name == NULL) { @@ -396,7 +462,15 @@ ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_create(const char *name) return h; } +#ifdef _WIN32 +ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_createW(const wchar_t* name) +{ + return __itt_string_handle_createA(wchar2char(name)); +} +ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_createA(const char* name) +#else ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_create(const char* name) +#endif { if (!g_ref_collector_global.mutex_initialized || name == NULL) { @@ -428,21 +502,49 @@ ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_create(const char* return h; } +#ifdef _WIN32 +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createW(const wchar_t *name, const wchar_t *domain) +{ + return __itt_counter_createA(wchar2char(name), wchar2char(domain)); +} +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createA(const char *name, const char *domain) +#else ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create(const char *name, const char *domain) +#endif { LOG_FUNC_CALL_INFO("function call"); return __itt_counter_create_typed(name, domain, __itt_metadata_u64); } +#ifdef _WIN32 +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createW_v3( + const __itt_domain* domain, const wchar_t* name, __itt_metadata_type type) +{ + return __itt_counter_create_typed(wchar2char(name), domain->nameA, type); +} +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createA_v3( + const __itt_domain* domain, const char* name, __itt_metadata_type type) +#else ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_v3( const __itt_domain* domain, const char* name, __itt_metadata_type type) +#endif { LOG_FUNC_CALL_INFO("function call"); return __itt_counter_create_typed(name, domain->nameA, type); } +#ifdef _WIN32 +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typedW( + const wchar_t *name, const wchar_t *domain, __itt_metadata_type type) +{ + return __itt_counter_create_typedA(wchar2char(name), wchar2char(domain), type); +} +ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typedA( + const char *name, const char *domain, __itt_metadata_type type) +#else ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typed( const char *name, const char *domain, __itt_metadata_type type) +#endif { if (!g_ref_collector_global.mutex_initialized || name == NULL || domain == NULL) { @@ -478,8 +580,18 @@ ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typed( return (__itt_counter)h; } +#ifdef _WIN32 +ITT_EXTERN_C __itt_histogram* ITTAPI __itt_histogram_createW( + const __itt_domain* domain, const wchar_t* name, __itt_metadata_type x_type, __itt_metadata_type y_type) +{ + return __itt_histogram_createA(domain, wchar2char(name), x_type, y_type); +} +ITT_EXTERN_C __itt_histogram* ITTAPI __itt_histogram_createA( + const __itt_domain* domain, const char* name, __itt_metadata_type x_type, __itt_metadata_type y_type) +#else ITT_EXTERN_C __itt_histogram* ITTAPI __itt_histogram_create( const __itt_domain* domain, const char* name, __itt_metadata_type x_type, __itt_metadata_type y_type) +#endif { if (!g_ref_collector_global.mutex_initialized || name == NULL || domain == NULL) { From c1beb410b627bec5f4eaa711e4e42af8d1ddaf49 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 10:20:41 +0200 Subject: [PATCH 02/15] add reference collector build into CI --- .github/workflows/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 659c1d6..72d91c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,6 +60,21 @@ jobs: run: ctest --test-dir build_win/64/cpp --build-config Release --output-on-failure if: runner.os == 'Windows' + reference_collector: + name: Check reference collector + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + - os: windows-latest + steps: + - name: Checkout sources + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Build C++ wrapper + run: python buildall.py --force_bits 64 --refcol + rust_format: name: Check Rust formatting runs-on: ubuntu-latest From 3245cb0a93d3a6d185c5c3e4f887d87bc5442653 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 11:45:03 +0200 Subject: [PATCH 03/15] add smoke tests --- .github/workflows/main.yml | 33 ++++++++++++++++++- src/ittnotify_refcol/tests/smoke_test.c | 44 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/ittnotify_refcol/tests/smoke_test.c diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 72d91c5..f3f49ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,6 +39,37 @@ jobs: # doesn't work in case of CMake + VS (https://github.com/fortran-lang/setup-fortran/issues/45) run: python buildall.py --force_bits 64 -ft ${{ matrix.optional_args }} + refcol_smoke: + name: Reference collector smoke test + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Build reference collector library + run: python buildall.py --force_bits 64 --refcol + - name: Build smoke test app + run: | + gcc src/ittnotify_refcol/tests/smoke_test.c src/ittnotify/ittnotify_static.c \ + -o smoke_test \ + -I include \ + -I src/ittnotify \ + -ldl + - name: Run smoke test + run: | + mkdir -p /tmp/refcol_logs + INTEL_LIBITTNOTIFY64=$(pwd)/build_linux/64/libittnotify_refcol.so \ + INTEL_LIBITTNOTIFY_LOG_DIR=/tmp/refcol_logs \ + ./smoke_test + - name: Verify log output + run: | + log=$(ls /tmp/refcol_logs/libittnotify_refcol_*.log 2>/dev/null | head -1) + if [ -z "$log" ]; then echo "ERROR: no log file found"; exit 1; fi + echo "Log file: $log" + grep -q "__itt_task_begin" "$log" || { echo "ERROR: __itt_task_begin not found"; exit 1; } + grep -q "__itt_task_end" "$log" || { echo "ERROR: __itt_task_end not found"; exit 1; } + grep -q "__itt_metadata_add" "$log" || { echo "ERROR: __itt_metadata_add not found"; exit 1; } + echo "Smoke test passed." + cpp_wrapper: name: Check C++ wrapper runs-on: ${{ matrix.os }} @@ -72,7 +103,7 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Build C++ wrapper + - name: Build ITT Reference Collector run: python buildall.py --force_bits 64 --refcol rust_format: diff --git a/src/ittnotify_refcol/tests/smoke_test.c b/src/ittnotify_refcol/tests/smoke_test.c new file mode 100644 index 0000000..b1b9e61 --- /dev/null +++ b/src/ittnotify_refcol/tests/smoke_test.c @@ -0,0 +1,44 @@ +/* + Copyright (C) 2025 Intel Corporation + + SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause +*/ + +#include +#include "ittnotify.h" +#include "ittnotify_types.h" + +int main() +{ + __itt_domain* domain = __itt_domain_create("smoke_test_domain"); + __itt_string_handle* handle = __itt_string_handle_create("smoke_test_handler"); + __itt_string_handle* handle_work = __itt_string_handle_create("smoke_test_worker"); + + const int n = 10; + int a[10][10], b[10][10], mul[10][10], i, j, k, count = 0; + + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + { + a[i][j] = i; + b[i][j] = j; + mul[i][j] = 0; + } + + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + for (k = 0; k < n; k++) + { + mul[i][j] += a[i][k] * b[k][j]; + count++; + if (count % 100 == 0) + { + __itt_task_begin(domain, __itt_null, __itt_null, handle_work); + unsigned long long data[5] = { i, j, k, count, mul[i][j] }; + __itt_metadata_add(domain, __itt_null, handle, __itt_metadata_u64, 5, data); + __itt_task_end(domain); + } + } + + return 0; +} From cd1db1fc00548bee2efc69caeae952533f806253 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 11:54:58 +0200 Subject: [PATCH 04/15] fix CI --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3f49ca..7abeeee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,7 +57,7 @@ jobs: - name: Run smoke test run: | mkdir -p /tmp/refcol_logs - INTEL_LIBITTNOTIFY64=$(pwd)/build_linux/64/libittnotify_refcol.so \ + INTEL_LIBITTNOTIFY64=$(pwd)/build_linux/64/bin/libittnotify_refcol.so \ INTEL_LIBITTNOTIFY_LOG_DIR=/tmp/refcol_logs \ ./smoke_test - name: Verify log output From 52f508cdd8da64edeade2839ccd6a0d77e5bcd6e Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 12:59:30 +0200 Subject: [PATCH 05/15] add windows testing for reference collector --- .github/workflows/main.yml | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7abeeee..0459b43 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,33 +41,57 @@ jobs: refcol_smoke: name: Reference collector smoke test - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + lib: build_linux/64/bin/libittnotify_refcol.so + exe: smoke_test + - os: windows-latest + lib: build_win/64/bin/libittnotify_refcol.dll + exe: smoke_test.exe + defaults: + run: + shell: bash steps: - name: Checkout sources uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Setup MSVC environment + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@0b201ec74f55ad10e66500d07fc9ecfd7bfde614 # v1.13.0 - name: Build reference collector library - run: python buildall.py --force_bits 64 --refcol - - name: Build smoke test app + run: python buildall.py --force_bits 64 --refcol ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} + - name: Build smoke test app (Linux) + if: runner.os == 'Linux' run: | gcc src/ittnotify_refcol/tests/smoke_test.c src/ittnotify/ittnotify_static.c \ -o smoke_test \ -I include \ -I src/ittnotify \ -ldl + - name: Build smoke test app (Windows) + if: runner.os == 'Windows' + run: | + cl.exe /nologo \ + src/ittnotify_refcol/tests/smoke_test.c src/ittnotify/ittnotify_static.c \ + /I include /I src/ittnotify \ + /Fe smoke_test.exe - name: Run smoke test run: | - mkdir -p /tmp/refcol_logs - INTEL_LIBITTNOTIFY64=$(pwd)/build_linux/64/bin/libittnotify_refcol.so \ - INTEL_LIBITTNOTIFY_LOG_DIR=/tmp/refcol_logs \ - ./smoke_test + mkdir -p "$RUNNER_TEMP/refcol_logs" + INTEL_LIBITTNOTIFY64=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") \ + INTEL_LIBITTNOTIFY_LOG_DIR="$RUNNER_TEMP/refcol_logs" \ + ./${{ matrix.exe }} - name: Verify log output run: | - log=$(ls /tmp/refcol_logs/libittnotify_refcol_*.log 2>/dev/null | head -1) + log=$(ls "$RUNNER_TEMP/refcol_logs"/libittnotify_refcol_*.log 2>/dev/null | head -1) if [ -z "$log" ]; then echo "ERROR: no log file found"; exit 1; fi echo "Log file: $log" - grep -q "__itt_task_begin" "$log" || { echo "ERROR: __itt_task_begin not found"; exit 1; } - grep -q "__itt_task_end" "$log" || { echo "ERROR: __itt_task_end not found"; exit 1; } - grep -q "__itt_metadata_add" "$log" || { echo "ERROR: __itt_metadata_add not found"; exit 1; } + grep -q "__itt_task_begin" "$log" || { echo "ERROR: __itt_task_begin not found"; exit 1; } + grep -q "__itt_task_end" "$log" || { echo "ERROR: __itt_task_end not found"; exit 1; } + grep -q "__itt_metadata_add" "$log" || { echo "ERROR: __itt_metadata_add not found"; exit 1; } echo "Smoke test passed." cpp_wrapper: From f11b9785bc2b4ec9813e47b84d7c0956926abe66 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:08:16 +0200 Subject: [PATCH 06/15] move refcol smoke test target into CMakeLists.txt --- .github/workflows/main.yml | 26 ++++---------------------- CMakeLists.txt | 12 ++++++++++++ buildall.py | 5 ++++- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0459b43..4c1546a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,36 +48,18 @@ jobs: include: - os: ubuntu-latest lib: build_linux/64/bin/libittnotify_refcol.so - exe: smoke_test + exe: build_linux/64/bin/refcol_smoke_test - os: windows-latest lib: build_win/64/bin/libittnotify_refcol.dll - exe: smoke_test.exe + exe: build_win/64/bin/refcol_smoke_test.exe defaults: run: shell: bash steps: - name: Checkout sources uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Setup MSVC environment - if: runner.os == 'Windows' - uses: ilammy/msvc-dev-cmd@0b201ec74f55ad10e66500d07fc9ecfd7bfde614 # v1.13.0 - - name: Build reference collector library - run: python buildall.py --force_bits 64 --refcol ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} - - name: Build smoke test app (Linux) - if: runner.os == 'Linux' - run: | - gcc src/ittnotify_refcol/tests/smoke_test.c src/ittnotify/ittnotify_static.c \ - -o smoke_test \ - -I include \ - -I src/ittnotify \ - -ldl - - name: Build smoke test app (Windows) - if: runner.os == 'Windows' - run: | - cl.exe /nologo \ - src/ittnotify_refcol/tests/smoke_test.c src/ittnotify/ittnotify_static.c \ - /I include /I src/ittnotify \ - /Fe smoke_test.exe + - name: Build reference collector library and smoke test + run: python buildall.py --force_bits 64 --smoke ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} - name: Run smoke test run: | mkdir -p "$RUNNER_TEMP/refcol_logs" diff --git a/CMakeLists.txt b/CMakeLists.txt index 231f4e1..18805f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,18 @@ if(ITT_API_REFERENCE_COLLECTOR) else() set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME ittnotify_refcol) endif() + + option(ITT_API_REFCOL_SMOKE_TESTS "Build reference collector smoke tests" OFF) + if(ITT_API_REFCOL_SMOKE_TESTS) + add_executable(refcol_smoke_test src/ittnotify_refcol/tests/smoke_test.c) + target_include_directories(refcol_smoke_test + PRIVATE include + src/ittnotify + ) + target_link_libraries(refcol_smoke_test PRIVATE ittnotify ${CMAKE_DL_LIBS}) + set_target_properties(refcol_smoke_test PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) + endif() endif() if(WIN32) diff --git a/buildall.py b/buildall.py index 058cd46..7e2455b 100755 --- a/buildall.py +++ b/buildall.py @@ -121,6 +121,8 @@ def main(): "-cpp", "--cpp", help="enable C++ wrapper support", action="store_true") parser.add_argument( "--refcol", help="enable reference collector build", action="store_true") + parser.add_argument( + "--smoke", help="enable reference collector smoke tests", action="store_true") parser.add_argument( "--force_bits", choices=["32", "64"], help="specify bit version for the target") if sys.platform == 'win32' and vs_versions: @@ -183,7 +185,8 @@ def main(): ("-DITT_API_IPT_SUPPORT=1" if args.ptmark else ""), ("-DITT_API_FORTRAN_SUPPORT=1" if args.fortran else ""), ("-DITT_API_CPP_SUPPORT=ON" if args.cpp else ""), - ("-DITT_API_REFERENCE_COLLECTOR=ON" if args.refcol else "") + ("-DITT_API_REFERENCE_COLLECTOR=ON" if (args.refcol or args.smoke) else ""), + ("-DITT_API_REFCOL_SMOKE_TESTS=ON" if args.smoke else "") ]))) if sys.platform == 'win32': From 4f8b3a186335efb93b0b0c90fb441522c2755827 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:16:24 +0200 Subject: [PATCH 07/15] update GH workflows --- .github/workflows/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c1546a..c6a41f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,8 +63,10 @@ jobs: - name: Run smoke test run: | mkdir -p "$RUNNER_TEMP/refcol_logs" - INTEL_LIBITTNOTIFY64=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") \ - INTEL_LIBITTNOTIFY_LOG_DIR="$RUNNER_TEMP/refcol_logs" \ + lib_path=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") + log_dir=$(cygpath -w "$RUNNER_TEMP/refcol_logs" 2>/dev/null || echo "$RUNNER_TEMP/refcol_logs") + INTEL_LIBITTNOTIFY64="$lib_path" \ + INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" \ ./${{ matrix.exe }} - name: Verify log output run: | From fd2e7eb63d697ab8a88d286770d9d4354512f22c Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:22:02 +0200 Subject: [PATCH 08/15] update GH workflows --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6a41f6..70a19b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,8 +65,8 @@ jobs: mkdir -p "$RUNNER_TEMP/refcol_logs" lib_path=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") log_dir=$(cygpath -w "$RUNNER_TEMP/refcol_logs" 2>/dev/null || echo "$RUNNER_TEMP/refcol_logs") - INTEL_LIBITTNOTIFY64="$lib_path" \ - INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" \ + export INTEL_LIBITTNOTIFY64="$lib_path" + export INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" ./${{ matrix.exe }} - name: Verify log output run: | From 1c3a0c34f789f24282fa342c9188922f5b34a205 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:29:15 +0200 Subject: [PATCH 09/15] update GH workflows --- .github/workflows/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70a19b3..4371233 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,9 +65,16 @@ jobs: mkdir -p "$RUNNER_TEMP/refcol_logs" lib_path=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") log_dir=$(cygpath -w "$RUNNER_TEMP/refcol_logs" 2>/dev/null || echo "$RUNNER_TEMP/refcol_logs") + echo "lib_path=$lib_path" + echo "log_dir=$log_dir" + ls "$(pwd)/${{ matrix.lib }}" && echo "DLL/SO exists" || echo "ERROR: DLL/SO not found" export INTEL_LIBITTNOTIFY64="$lib_path" export INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" + echo "Running: ./${{ matrix.exe }}" ./${{ matrix.exe }} + echo "Exit code: $?" + echo "Contents of log dir:" + ls -la "$RUNNER_TEMP/refcol_logs/" || echo "(empty or missing)" - name: Verify log output run: | log=$(ls "$RUNNER_TEMP/refcol_logs"/libittnotify_refcol_*.log 2>/dev/null | head -1) From 23ad0b86e45f307aecf41bb991b22667ba2bd803 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:34:03 +0200 Subject: [PATCH 10/15] update GH workflows --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4371233..36ad764 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,6 +60,8 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Build reference collector library and smoke test run: python buildall.py --force_bits 64 --smoke ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} + - name: Find built artifacts + run: find build_win build_linux -name "libittnotify_refcol*" -o -name "refcol_smoke_test*" 2>/dev/null || true - name: Run smoke test run: | mkdir -p "$RUNNER_TEMP/refcol_logs" From 8442bfb24910870d854a4874ee722354079b73ef Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 13:50:42 +0200 Subject: [PATCH 11/15] update GH workflows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36ad764..361f179 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: lib: build_linux/64/bin/libittnotify_refcol.so exe: build_linux/64/bin/refcol_smoke_test - os: windows-latest - lib: build_win/64/bin/libittnotify_refcol.dll + lib: build_win/64/bin/liblibittnotify_refcol.dll exe: build_win/64/bin/refcol_smoke_test.exe defaults: run: From 1b79adc62c7df3201cd13df08527d5638e8f8154 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 14:16:56 +0200 Subject: [PATCH 12/15] update docs and build settings --- .github/workflows/main.yml | 2 +- CMakeLists.txt | 1 + src/ittnotify_refcol/README.md | 47 +++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 361f179..36ad764 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: lib: build_linux/64/bin/libittnotify_refcol.so exe: build_linux/64/bin/refcol_smoke_test - os: windows-latest - lib: build_win/64/bin/liblibittnotify_refcol.dll + lib: build_win/64/bin/libittnotify_refcol.dll exe: build_win/64/bin/refcol_smoke_test.exe defaults: run: diff --git a/CMakeLists.txt b/CMakeLists.txt index 18805f2..45929da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,7 @@ if(ITT_API_REFERENCE_COLLECTOR) if(WIN32) set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME libittnotify_refcol + PREFIX "" WINDOWS_EXPORT_ALL_SYMBOLS ON) else() set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME ittnotify_refcol) diff --git a/src/ittnotify_refcol/README.md b/src/ittnotify_refcol/README.md index ee30fc5..9b68c9b 100644 --- a/src/ittnotify_refcol/README.md +++ b/src/ittnotify_refcol/README.md @@ -5,24 +5,52 @@ performs tracing data from ITT API function calls to log files. To use this solution, build the collector as a shared library and point the full library path to the `INTEL_LIBITTNOTIFY64` or `INTEL_LIBITTNOTIFY32` -environment variable: +environment variable. -**On Linux** +## Building + +### CMake (all platforms, recommended) + +``` +cmake -DITT_API_REFERENCE_COLLECTOR=ON +cmake --build . +``` + +The shared library is placed in the `bin/` subdirectory of the CMake build +directory. Alternatively, use the provided `buildall.py` script: + +``` +python buildall.py --refcol +``` + +### Make (Linux / FreeBSD) ``` make -export INTEL_LIBITTNOTIFY64=/libittnotify_refcol.so +``` + +## Usage + +**On Linux** + +``` +export INTEL_LIBITTNOTIFY64=/bin/libittnotify_refcol.so ``` **On FreeBSD** ``` -make -setenv INTEL_LIBITTNOTIFY64 /libittnotify_refcol.so +setenv INTEL_LIBITTNOTIFY64 /bin/libittnotify_refcol.so +``` + +**On Windows** + +``` +set INTEL_LIBITTNOTIFY64=\bin\libittnotify_refcol.dll ``` -By default, log files save in the `tmp` directory. To change the location, -use the `INTEL_LIBITTNOTIFY_LOG_DIR` environment variable: +By default, log files are saved in the system temporary directory. To change +the location, use the `INTEL_LIBITTNOTIFY_LOG_DIR` environment variable: **On Linux** @@ -35,6 +63,11 @@ export INTEL_LIBITTNOTIFY_LOG_DIR= setenv INTEL_LIBITTNOTIFY_LOG_DIR ``` +**On Windows** +``` +set INTEL_LIBITTNOTIFY_LOG_DIR= +``` + This implementation adds logging of some of the ITT API function calls. Adding logging of other ITT API function calls is welcome. The solution provides 4 functions with different log levels that take `printf` format for logging: From 60f3b7b33c5d366e4de1c0072022ae40a847dd2b Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Thu, 7 May 2026 15:52:21 +0200 Subject: [PATCH 13/15] remove duplicated checks --- .github/workflows/main.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36ad764..c0a5438 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,23 +60,14 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Build reference collector library and smoke test run: python buildall.py --force_bits 64 --smoke ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} - - name: Find built artifacts - run: find build_win build_linux -name "libittnotify_refcol*" -o -name "refcol_smoke_test*" 2>/dev/null || true - name: Run smoke test run: | mkdir -p "$RUNNER_TEMP/refcol_logs" lib_path=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") log_dir=$(cygpath -w "$RUNNER_TEMP/refcol_logs" 2>/dev/null || echo "$RUNNER_TEMP/refcol_logs") - echo "lib_path=$lib_path" - echo "log_dir=$log_dir" - ls "$(pwd)/${{ matrix.lib }}" && echo "DLL/SO exists" || echo "ERROR: DLL/SO not found" export INTEL_LIBITTNOTIFY64="$lib_path" export INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" - echo "Running: ./${{ matrix.exe }}" ./${{ matrix.exe }} - echo "Exit code: $?" - echo "Contents of log dir:" - ls -la "$RUNNER_TEMP/refcol_logs/" || echo "(empty or missing)" - name: Verify log output run: | log=$(ls "$RUNNER_TEMP/refcol_logs"/libittnotify_refcol_*.log 2>/dev/null | head -1) @@ -108,21 +99,6 @@ jobs: run: ctest --test-dir build_win/64/cpp --build-config Release --output-on-failure if: runner.os == 'Windows' - reference_collector: - name: Check reference collector - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-latest - - os: windows-latest - steps: - - name: Checkout sources - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Build ITT Reference Collector - run: python buildall.py --force_bits 64 --refcol - rust_format: name: Check Rust formatting runs-on: ubuntu-latest From 267aa4077dc5a4ea080898771e7019992a26e070 Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Fri, 8 May 2026 00:12:46 +0200 Subject: [PATCH 14/15] remove duplicated checks --- .github/workflows/main.yml | 19 ++--------- CMakeLists.txt | 34 +------------------ buildall.py | 8 ++--- src/ittnotify_refcol/itt_refcol_impl.c | 45 ++++++++++++++++++------- src/ittnotify_refcol/tests/smoke_test.c | 5 ++- 5 files changed, 41 insertions(+), 70 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0a5438..ca588ce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,24 +59,9 @@ jobs: - name: Checkout sources uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Build reference collector library and smoke test - run: python buildall.py --force_bits 64 --smoke ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} + run: python buildall.py --force_bits 64 --refcol -DITT_API_REFCOL_SMOKE_TESTS=ON ${{ runner.os == 'Windows' && '--cmake_gen ninja' || '' }} - name: Run smoke test - run: | - mkdir -p "$RUNNER_TEMP/refcol_logs" - lib_path=$(cygpath -w "$(pwd)/${{ matrix.lib }}" 2>/dev/null || echo "$(pwd)/${{ matrix.lib }}") - log_dir=$(cygpath -w "$RUNNER_TEMP/refcol_logs" 2>/dev/null || echo "$RUNNER_TEMP/refcol_logs") - export INTEL_LIBITTNOTIFY64="$lib_path" - export INTEL_LIBITTNOTIFY_LOG_DIR="$log_dir" - ./${{ matrix.exe }} - - name: Verify log output - run: | - log=$(ls "$RUNNER_TEMP/refcol_logs"/libittnotify_refcol_*.log 2>/dev/null | head -1) - if [ -z "$log" ]; then echo "ERROR: no log file found"; exit 1; fi - echo "Log file: $log" - grep -q "__itt_task_begin" "$log" || { echo "ERROR: __itt_task_begin not found"; exit 1; } - grep -q "__itt_task_end" "$log" || { echo "ERROR: __itt_task_end not found"; exit 1; } - grep -q "__itt_metadata_add" "$log" || { echo "ERROR: __itt_metadata_add not found"; exit 1; } - echo "Smoke test passed." + run: python src/ittnotify_refcol/tests/run_smoke_test.py --lib ${{ matrix.lib }} --exe ${{ matrix.exe }} cpp_wrapper: name: Check C++ wrapper diff --git a/CMakeLists.txt b/CMakeLists.txt index 45929da..bf9dd45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,39 +143,7 @@ set(JITPROFILING_SRC "src/ittnotify/jitprofiling.c") add_library(jitprofiling STATIC ${JITPROFILING_SRC}) if(ITT_API_REFERENCE_COLLECTOR) - add_library(ittnotify_refcol SHARED src/ittnotify_refcol/itt_refcol_impl.c) - - target_include_directories(ittnotify_refcol - PUBLIC $ - PRIVATE src/ittnotify - ) - - target_link_libraries(ittnotify_refcol PRIVATE ${CMAKE_DL_LIBS}) - set_target_properties(ittnotify_refcol PROPERTIES - LINKER_LANGUAGE C - RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) - - if(WIN32) - set_target_properties(ittnotify_refcol PROPERTIES - OUTPUT_NAME libittnotify_refcol - PREFIX "" - WINDOWS_EXPORT_ALL_SYMBOLS ON) - else() - set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME ittnotify_refcol) - endif() - - option(ITT_API_REFCOL_SMOKE_TESTS "Build reference collector smoke tests" OFF) - if(ITT_API_REFCOL_SMOKE_TESTS) - add_executable(refcol_smoke_test src/ittnotify_refcol/tests/smoke_test.c) - target_include_directories(refcol_smoke_test - PRIVATE include - src/ittnotify - ) - target_link_libraries(refcol_smoke_test PRIVATE ittnotify ${CMAKE_DL_LIBS}) - set_target_properties(refcol_smoke_test PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) - endif() + add_subdirectory(src/ittnotify_refcol) endif() if(WIN32) diff --git a/buildall.py b/buildall.py index 7e2455b..96a5f99 100755 --- a/buildall.py +++ b/buildall.py @@ -122,7 +122,8 @@ def main(): parser.add_argument( "--refcol", help="enable reference collector build", action="store_true") parser.add_argument( - "--smoke", help="enable reference collector smoke tests", action="store_true") + "-D", dest="cmake_defines", metavar="VAR=VALUE", action="append", default=[], + help="pass extra -D defines to cmake (may be specified multiple times)") parser.add_argument( "--force_bits", choices=["32", "64"], help="specify bit version for the target") if sys.platform == 'win32' and vs_versions: @@ -185,9 +186,8 @@ def main(): ("-DITT_API_IPT_SUPPORT=1" if args.ptmark else ""), ("-DITT_API_FORTRAN_SUPPORT=1" if args.fortran else ""), ("-DITT_API_CPP_SUPPORT=ON" if args.cpp else ""), - ("-DITT_API_REFERENCE_COLLECTOR=ON" if (args.refcol or args.smoke) else ""), - ("-DITT_API_REFCOL_SMOKE_TESTS=ON" if args.smoke else "") - ]))) + ("-DITT_API_REFERENCE_COLLECTOR=ON" if args.refcol else ""), + ] + ["-D" + d for d in args.cmake_defines]))) if sys.platform == 'win32': target_project = 'ALL_BUILD' if not use_ninja else 'all' diff --git a/src/ittnotify_refcol/itt_refcol_impl.c b/src/ittnotify_refcol/itt_refcol_impl.c index bab88d5..3e4829a 100644 --- a/src/ittnotify_refcol/itt_refcol_impl.c +++ b/src/ittnotify_refcol/itt_refcol_impl.c @@ -56,28 +56,25 @@ static struct ref_collector_global { static char* log_file_name_generate() { time_t time_now = time(NULL); - struct tm* time_info = malloc(sizeof(struct tm)); + struct tm time_info; char* log_file_name = malloc(sizeof(char) * (LOG_BUFFER_MAX_SIZE/2)); if (log_file_name == NULL) { printf("ERROR: Failed to allocate memory for log file name\n"); - free(time_info); return NULL; } - if (!REFCOL_LOCALTIME(time_info, &time_now)) + if (!REFCOL_LOCALTIME(&time_info, &time_now)) { printf("ERROR: Failed to get local time for log file name\n"); - free(time_info); free(log_file_name); return NULL; } sprintf(log_file_name,"libittnotify_refcol_%d%d%d%d%d%d.log", - time_info->tm_year+1900, time_info->tm_mon+1, time_info->tm_mday, - time_info->tm_hour, time_info->tm_min, time_info->tm_sec); - free(time_info); + time_info.tm_year+1900, time_info.tm_mon+1, time_info.tm_mday, + time_info.tm_hour, time_info.tm_min, time_info.tm_sec); return log_file_name; } @@ -425,7 +422,10 @@ static char* wchar2char(const wchar_t* wide_str) #ifdef _WIN32 ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_createW(const wchar_t *name) { - return __itt_domain_createA(wchar2char(name)); + char* name_a = wchar2char(name); + __itt_domain* result = __itt_domain_createA(name_a); + free(name_a); + return result; } ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_createA(const char *name) #else @@ -465,7 +465,10 @@ ITT_EXTERN_C __itt_domain* ITTAPI __itt_domain_create(const char *name) #ifdef _WIN32 ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_createW(const wchar_t* name) { - return __itt_string_handle_createA(wchar2char(name)); + char* name_a = wchar2char(name); + __itt_string_handle* result = __itt_string_handle_createA(name_a); + free(name_a); + return result; } ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_createA(const char* name) #else @@ -505,7 +508,12 @@ ITT_EXTERN_C __itt_string_handle* ITTAPI __itt_string_handle_create(const char* #ifdef _WIN32 ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createW(const wchar_t *name, const wchar_t *domain) { - return __itt_counter_createA(wchar2char(name), wchar2char(domain)); + char* name_a = wchar2char(name); + char* domain_a = wchar2char(domain); + __itt_counter result = __itt_counter_createA(name_a, domain_a); + free(name_a); + free(domain_a); + return result; } ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createA(const char *name, const char *domain) #else @@ -520,7 +528,10 @@ ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create(const char *name, const c ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createW_v3( const __itt_domain* domain, const wchar_t* name, __itt_metadata_type type) { - return __itt_counter_create_typed(wchar2char(name), domain->nameA, type); + char* name_a = wchar2char(name); + __itt_counter result = __itt_counter_create_typed(name_a, domain->nameA, type); + free(name_a); + return result; } ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_createA_v3( const __itt_domain* domain, const char* name, __itt_metadata_type type) @@ -537,7 +548,12 @@ ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_v3( ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typedW( const wchar_t *name, const wchar_t *domain, __itt_metadata_type type) { - return __itt_counter_create_typedA(wchar2char(name), wchar2char(domain), type); + char* name_a = wchar2char(name); + char* domain_a = wchar2char(domain); + __itt_counter result = __itt_counter_create_typedA(name_a, domain_a, type); + free(name_a); + free(domain_a); + return result; } ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typedA( const char *name, const char *domain, __itt_metadata_type type) @@ -584,7 +600,10 @@ ITT_EXTERN_C __itt_counter ITTAPI __itt_counter_create_typed( ITT_EXTERN_C __itt_histogram* ITTAPI __itt_histogram_createW( const __itt_domain* domain, const wchar_t* name, __itt_metadata_type x_type, __itt_metadata_type y_type) { - return __itt_histogram_createA(domain, wchar2char(name), x_type, y_type); + char* name_a = wchar2char(name); + __itt_histogram* result = __itt_histogram_createA(domain, name_a, x_type, y_type); + free(name_a); + return result; } ITT_EXTERN_C __itt_histogram* ITTAPI __itt_histogram_createA( const __itt_domain* domain, const char* name, __itt_metadata_type x_type, __itt_metadata_type y_type) diff --git a/src/ittnotify_refcol/tests/smoke_test.c b/src/ittnotify_refcol/tests/smoke_test.c index b1b9e61..4c2a5bf 100644 --- a/src/ittnotify_refcol/tests/smoke_test.c +++ b/src/ittnotify_refcol/tests/smoke_test.c @@ -1,14 +1,13 @@ /* - Copyright (C) 2025 Intel Corporation + Copyright (C) 2026 Intel Corporation SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause */ -#include #include "ittnotify.h" #include "ittnotify_types.h" -int main() +int main(void) { __itt_domain* domain = __itt_domain_create("smoke_test_domain"); __itt_string_handle* handle = __itt_string_handle_create("smoke_test_handler"); From f297a158ecde6cf9990e2845f4bb70910437e91f Mon Sep 17 00:00:00 2001 From: "Kireev, Alexey" Date: Fri, 8 May 2026 00:16:36 +0200 Subject: [PATCH 15/15] update smoke tests --- src/ittnotify_refcol/CMakeLists.txt | 33 +++++++++ src/ittnotify_refcol/tests/run_smoke_test.py | 77 ++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/ittnotify_refcol/CMakeLists.txt create mode 100644 src/ittnotify_refcol/tests/run_smoke_test.py diff --git a/src/ittnotify_refcol/CMakeLists.txt b/src/ittnotify_refcol/CMakeLists.txt new file mode 100644 index 0000000..9cc93fa --- /dev/null +++ b/src/ittnotify_refcol/CMakeLists.txt @@ -0,0 +1,33 @@ +add_library(ittnotify_refcol SHARED itt_refcol_impl.c) + +target_include_directories(ittnotify_refcol + PUBLIC $ + PRIVATE ${CMAKE_SOURCE_DIR}/src/ittnotify +) + +target_link_libraries(ittnotify_refcol PRIVATE ${CMAKE_DL_LIBS}) +set_target_properties(ittnotify_refcol PROPERTIES + LINKER_LANGUAGE C + RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) + +if(WIN32) + set_target_properties(ittnotify_refcol PROPERTIES + OUTPUT_NAME libittnotify_refcol + PREFIX "" + WINDOWS_EXPORT_ALL_SYMBOLS ON) +else() + set_target_properties(ittnotify_refcol PROPERTIES OUTPUT_NAME ittnotify_refcol) +endif() + +option(ITT_API_REFCOL_SMOKE_TESTS "Build reference collector smoke tests" OFF) +if(ITT_API_REFCOL_SMOKE_TESTS) + add_executable(refcol_smoke_test tests/smoke_test.c) + target_include_directories(refcol_smoke_test + PRIVATE ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/ittnotify + ) + target_link_libraries(refcol_smoke_test PRIVATE ittnotify ${CMAKE_DL_LIBS}) + set_target_properties(refcol_smoke_test PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) +endif() diff --git a/src/ittnotify_refcol/tests/run_smoke_test.py b/src/ittnotify_refcol/tests/run_smoke_test.py new file mode 100644 index 0000000..cea0c65 --- /dev/null +++ b/src/ittnotify_refcol/tests/run_smoke_test.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause +# + +import argparse +import glob +import os +import subprocess +import sys +import tempfile + + +EXPECTED_SYMBOLS = [ + "__itt_task_begin", + "__itt_task_end", + "__itt_metadata_add", +] + + +def main(): + parser = argparse.ArgumentParser(description="Run reference collector smoke test") + parser.add_argument("--lib", required=True, help="Path to libittnotify_refcol shared library") + parser.add_argument("--exe", required=True, help="Path to refcol_smoke_test executable") + parser.add_argument("--log-dir", help="Directory for log files (default: temp dir)") + args = parser.parse_args() + + lib = os.path.abspath(args.lib) + exe = os.path.abspath(args.exe) + + if not os.path.isfile(lib): + print(f"ERROR: library not found: {lib}") + return 1 + if not os.path.isfile(exe): + print(f"ERROR: executable not found: {exe}") + return 1 + + log_dir = os.path.abspath(args.log_dir) if args.log_dir else tempfile.mkdtemp(prefix="refcol_logs_") + os.makedirs(log_dir, exist_ok=True) + + env = os.environ.copy() + env["INTEL_LIBITTNOTIFY64"] = lib + env["INTEL_LIBITTNOTIFY_LOG_DIR"] = log_dir + + print(f"Library: {lib}") + print(f"Exe: {exe}") + print(f"Log dir: {log_dir}") + + result = subprocess.run([exe], env=env) + if result.returncode != 0: + print(f"ERROR: smoke test executable exited with code {result.returncode}") + return 1 + + logs = glob.glob(os.path.join(log_dir, "libittnotify_refcol_*.log")) + if not logs: + print("ERROR: no log file found in", log_dir) + return 1 + + log_path = logs[0] + print(f"Log file: {log_path}") + + with open(log_path, encoding="utf-8", errors="replace") as f: + content = f.read() + + missing = [sym for sym in EXPECTED_SYMBOLS if sym not in content] + if missing: + for sym in missing: + print(f"ERROR: '{sym}' not found in log") + return 1 + + print("Smoke test passed.") + return 0 + + +if __name__ == "__main__": + sys.exit(main())