diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 680c521747..78353bc7b4 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -84,6 +84,7 @@ option(onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS "Dump node input shapes and output option(onnxruntime_USE_DML "Build with DirectML support" OFF) option(onnxruntime_USE_ACL "Build with ACL support" OFF) option(onnxruntime_ENABLE_INSTRUMENT "Enable Instrument with Event Tracing for Windows (ETW)" OFF) +option(onnxruntime_USE_TELEMETRY "Build with Telemetry" OFF) set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) #nsync tests failed on Mac Build diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 1cbced43f7..63a8283429 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -52,6 +52,10 @@ source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_common_src}) add_library(onnxruntime_common ${onnxruntime_common_src}) +if (onnxruntime_USE_TELEMETRY) + set_target_properties(onnxruntime_common PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h") +endif() + if (onnxruntime_USE_MIMALLOC) if(onnxruntime_USE_CUDA OR onnxruntime_USE_OPENVINO) message(WARNING "Ignoring directive to use mimalloc on unimplemented targets") diff --git a/docs/Privacy.md b/docs/Privacy.md index 9292d989ec..4ec1b2ed25 100644 --- a/docs/Privacy.md +++ b/docs/Privacy.md @@ -14,5 +14,5 @@ Currently telemetry is only implemented for Windows builds, but may be expanded #### Technical Details The Windows provider uses the [TraceLogging](https://docs.microsoft.com/en-us/windows/win32/tracelogging/trace-logging-about) API for its implementation. -For API usage details to turn this on/off, please check the API pages: +Windows ML and onnxruntime C APIs allow telemetry collection to be turned on/off (see API pages for details). It is turned off by default in all official builds. * [C API](./C_API.md#telemetry) diff --git a/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h b/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h new file mode 100644 index 0000000000..d9aed52b87 --- /dev/null +++ b/include/onnxruntime/core/platform/windows/TraceLoggingConfig.h @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/* ++ +Module Name: + TraceLoggingConfig.h +Abstract: + Macro definitions used by this project's TraceLogging ETW providers: + - Configuration macros that select the ETW Provider Groups to be used by + this project. + - Constants for tags that are commonly used in Microsoft's + TraceLogging-based ETW. + Different versions of this file use different definitions for the + TraceLoggingOption configuration macros. The definitions in this file are + empty. As a result, providers using this configuration file will not join + any ETW Provider Groups and will not be given any special treatment by + group-sensitive ETW listeners. +Environment: + User mode or kernel mode. +--*/ + +#pragma once + +// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition +// in this file configures the provider as a normal (non-telemetry) provider. +#ifndef ENABLE_TELEMETRY +#define TraceLoggingOptionMicrosoftTelemetry() \ + TraceLoggingOptionGroup(0000000000, 00000, 00000, 0000, 0000, 0000, 0000, 0000, 000, 0000, 0000) + // Empty definition for TraceLoggingOptionMicrosoftTelemetry +#endif + +// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition +// in this file configures the provider as a normal (non-telemetry) provider. +#define TraceLoggingOptionWindowsCoreTelemetry() \ + // Empty definition for TraceLoggingOptionWindowsCoreTelemetry + +// Event privacy tags. Use the PDT macro values for the tag parameter, e.g.: +// TraceLoggingWrite(..., +// TelemetryPrivacyDataTag(PDT_BrowsingHistory | PDT_ProductAndServiceUsage), +// ...); +#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags") +#define PDT_BrowsingHistory 0x0000000000000002u +#define PDT_DeviceConnectivityAndConfiguration 0x0000000000000800u +#define PDT_InkingTypingAndSpeechUtterance 0x0000000000020000u +#define PDT_ProductAndServicePerformance 0x0000000001000000u +#define PDT_ProductAndServiceUsage 0x0000000002000000u +#define PDT_SoftwareSetupAndInventory 0x0000000080000000u + +// Event categories specified via keywords, e.g.: +// TraceLoggingWrite(..., +// TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), +// ...); +#define MICROSOFT_KEYWORD_CRITICAL_DATA 0x0000800000000000 // Bit 47 +#define MICROSOFT_KEYWORD_MEASURES 0x0000400000000000 // Bit 46 +#define MICROSOFT_KEYWORD_TELEMETRY 0x0000200000000000 // Bit 45 +#define MICROSOFT_KEYWORD_RESERVED_44 0x0000100000000000 // Bit 44 (reserved for future assignment) + +// Event categories specified via event tags, e.g.: +// TraceLoggingWrite(..., +// TraceLoggingEventTag(MICROSOFT_EVENTTAG_REALTIME_LATENCY), +// ...); +#define MICROSOFT_EVENTTAG_DROP_USER_IDS 0x00008000 +#define MICROSOFT_EVENTTAG_AGGREGATE 0x00010000 +#define MICROSOFT_EVENTTAG_DROP_PII_EXCEPT_IP 0x00020000 +#define MICROSOFT_EVENTTAG_COSTDEFERRED_LATENCY 0x00040000 +#define MICROSOFT_EVENTTAG_CORE_DATA 0x00080000 +#define MICROSOFT_EVENTTAG_INJECT_XTOKEN 0x00100000 +#define MICROSOFT_EVENTTAG_REALTIME_LATENCY 0x00200000 +#define MICROSOFT_EVENTTAG_NORMAL_LATENCY 0x00400000 +#define MICROSOFT_EVENTTAG_CRITICAL_PERSISTENCE 0x00800000 +#define MICROSOFT_EVENTTAG_NORMAL_PERSISTENCE 0x01000000 +#define MICROSOFT_EVENTTAG_DROP_PII 0x02000000 +#define MICROSOFT_EVENTTAG_HASH_PII 0x04000000 +#define MICROSOFT_EVENTTAG_MARK_PII 0x08000000 + +// Field categories specified via field tags, e.g.: +// TraceLoggingWrite(..., +// TraceLoggingString(szUser, "UserName", "User's name", MICROSOFT_FIELDTAG_HASH_PII), +// ...); +#define MICROSOFT_FIELDTAG_DROP_PII 0x04000000 +#define MICROSOFT_FIELDTAG_HASH_PII 0x08000000 \ No newline at end of file diff --git a/onnxruntime/core/platform/windows/telemetry.h b/onnxruntime/core/platform/windows/telemetry.h index def4a1e67f..dd5da6205b 100644 --- a/onnxruntime/core/platform/windows/telemetry.h +++ b/onnxruntime/core/platform/windows/telemetry.h @@ -4,20 +4,9 @@ #pragma once #include "core/platform/telemetry.h" #include "core/platform/ort_mutex.h" +#include "core/platform/windows/TraceLoggingConfig.h" #include -// *** -// platform specific control bits -#ifndef TraceLoggingOptionMicrosoftTelemetry -#define TraceLoggingOptionMicrosoftTelemetry() \ - TraceLoggingOptionGroup(0000000000, 00000, 00000, 0000, 0000, 0000, 0000, 0000, 000, 0000, 0000) -#endif -#define MICROSOFT_KEYWORD_MEASURES 0x0000400000000000 // Bit 46 -#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags") -#define PDT_ProductAndServicePerformance 0x0000000001000000u -#define PDT_ProductAndServiceUsage 0x0000000002000000u -// *** - namespace onnxruntime { /** diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index d5be9f2129..134313fc6c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -158,6 +158,7 @@ Use the individual flags to only run the specified stages. default='Visual Studio 15 2017', help="Specify the generator that CMake invokes. This is only supported on Windows") parser.add_argument("--enable_multi_device_test", action='store_true', help="Test with multi-device. Mostly used for multi-device GPU") parser.add_argument("--use_dml", action='store_true', help="Build with DirectML.") + parser.add_argument("--use_telemetry", action='store_true', help="Only official builds can set this flag to enable telemetry.") return parser.parse_args() def resolve_executable_path(command_or_path): @@ -328,6 +329,7 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home # enable pyop if it is nightly build "-Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=" + ("ON" if args.enable_language_interop_ops or (args.config != 'Debug' and bool(os.getenv('NIGHTLY_BUILD') == '1')) else "OFF"), "-Donnxruntime_USE_DML=" + ("ON" if args.use_dml else "OFF"), + "-Donnxruntime_USE_TELEMETRY=" + ("ON" if args.use_telemetry else "OFF"), ] if args.use_brainslice: bs_pkg_name = args.brain_slice_package_name.split('.', 1) diff --git a/tools/ci_build/github/azure-pipelines/nuget/templates/cpu.yml b/tools/ci_build/github/azure-pipelines/nuget/templates/cpu.yml index 702a20254a..7a58bc9994 100644 --- a/tools/ci_build/github/azure-pipelines/nuget/templates/cpu.yml +++ b/tools/ci_build/github/azure-pipelines/nuget/templates/cpu.yml @@ -13,7 +13,7 @@ jobs: parameters: AgentPool : $(AgentPoolWin) JobName: 'Windows_CI_Dev' - BuildCommand: '$(Build.SourcesDirectory)\tools\ci_build\build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --cmake_path $(Build.BinariesDirectory)\cmake\bin\cmake.exe --ctest_path $(Build.BinariesDirectory)\cmake\bin\ctest.exe --use_openmp --build_shared_lib --build_csharp --enable_onnx_tests' + BuildCommand: '$(Build.SourcesDirectory)\tools\ci_build\build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --cmake_path $(Build.BinariesDirectory)\cmake\bin\cmake.exe --ctest_path $(Build.BinariesDirectory)\cmake\bin\ctest.exe --use_openmp --build_shared_lib --build_csharp --enable_onnx_tests --use_telemetry' DoDebugBuild: 'false' DoNugetPack : 'true' DoCompliance: ${{ parameters.DoCompliance }} @@ -28,7 +28,7 @@ jobs: parameters: AgentPool : $(AgentPoolWin) JobName: 'Windows_CI_Dev_x86' - BuildCommand: '$(Build.SourcesDirectory)\tools\ci_build\build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --cmake_path $(Build.BinariesDirectory)\cmake\bin\cmake.exe --ctest_path $(Build.BinariesDirectory)\cmake\bin\ctest.exe --use_openmp --build_shared_lib --build_csharp --enable_onnx_tests --x86' + BuildCommand: '$(Build.SourcesDirectory)\tools\ci_build\build.py --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --cmake_path $(Build.BinariesDirectory)\cmake\bin\cmake.exe --ctest_path $(Build.BinariesDirectory)\cmake\bin\ctest.exe --use_openmp --build_shared_lib --build_csharp --enable_onnx_tests --x86 --use_telemetry' DoDebugBuild: 'false' DoNugetPack : 'true' DoCompliance: 'false' diff --git a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml index 545bdc56c7..92ebe320a2 100644 --- a/tools/ci_build/github/azure-pipelines/templates/win-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/win-ci.yml @@ -33,6 +33,15 @@ jobs: CUDA_VERSION: ${{ parameters.CudaVersion }} steps: + - powershell: | + if($env:TELEMETRYGUID) + { + $length = $env:TELEMETRYGUID.length + $fileContent = "#define ENABLE_TELEMETRY`n#define TraceLoggingOptionMicrosoftTelemetry() \ + TraceLoggingOptionGroup("+$env:TELEMETRYGUID.substring(1, $length-2)+")" + New-Item -Path "$(Build.SourcesDirectory)\include\onnxruntime\core\platform\windows\TraceLoggingConfigPrivate.h" -ItemType "file" -Value "$fileContent" -Force + } + displayName: 'Create TraceLoggingConfigPrivate.h For WinML Telemetry' - template: set-test-data-variables-step.yml - template: windows-build-tools-setup-steps.yml parameters: diff --git a/tools/ci_build/github/azure-pipelines/templates/win-x86-ci.yml b/tools/ci_build/github/azure-pipelines/templates/win-x86-ci.yml index 73e774d635..37923918d9 100644 --- a/tools/ci_build/github/azure-pipelines/templates/win-x86-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/win-x86-ci.yml @@ -33,6 +33,15 @@ jobs: RuntimeIdentifier: win-x86 steps: + - powershell: | + if($env:TELEMETRYGUID) + { + $length = $env:TELEMETRYGUID.length + $fileContent = "#define ENABLE_TELEMETRY`n#define ENABLE_TELEMETRY\n#define TraceLoggingOptionMicrosoftTelemetry() \ + TraceLoggingOptionGroup("+$env:TELEMETRYGUID.substring(1, $length-2)+")" + New-Item -Path "$(Build.SourcesDirectory)\include\onnxruntime\core\platform\windows\TraceLoggingConfigPrivate.h" -ItemType "file" -Value "$fileContent" -Force + } + displayName: 'Create TraceLoggingConfigPrivate.h For WinML Telemetry' - template: set-test-data-variables-step.yml - template: windows-build-tools-setup-steps.yml parameters: