Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions onnxruntime/core/platform/telemetry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,39 @@
ORT_UNUSED_PARAMETER(captureState);
}

void Telemetry::LogModelLoadStart(uint32_t session_id) const {
ORT_UNUSED_PARAMETER(session_id);
}

void Telemetry::LogModelLoadEnd(uint32_t session_id, const common::Status& status) const {
ORT_UNUSED_PARAMETER(session_id);
ORT_UNUSED_PARAMETER(status);
}

void Telemetry::LogSessionCreationEnd(uint32_t session_id,
const common::Status& status) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const {
const common::Status& status) const {

ORT_UNUSED_PARAMETER(session_id);
ORT_UNUSED_PARAMETER(status);
}

void Telemetry::LogRunStart(uint32_t session_id) const {
ORT_UNUSED_PARAMETER(session_id);
}

void Telemetry::LogRegisterEpLibraryWithLibPath(const std::string& registration_name,
const std::string& lib_path) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const std::string& lib_path) const {
const std::string& lib_path) const {

ORT_UNUSED_PARAMETER(registration_name);
ORT_UNUSED_PARAMETER(lib_path);
}

void Telemetry::LogRegisterEpLibraryStart(const std::string& registration_name) const {
ORT_UNUSED_PARAMETER(registration_name);
}

void Telemetry::LogRegisterEpLibraryEnd(const std::string& registration_name,

Check warning on line 189 in onnxruntime/core/platform/telemetry.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/platform/telemetry.cc:189: Add #include <string> for string [build/include_what_you_use] [4]
const common::Status& status) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const {
const common::Status& status) const {

ORT_UNUSED_PARAMETER(registration_name);
ORT_UNUSED_PARAMETER(status);
}

} // namespace onnxruntime
17 changes: 17 additions & 0 deletions onnxruntime/core/platform/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ class Telemetry {
const std::string& provider_options_string,
bool captureState) const;

virtual void LogModelLoadStart(uint32_t session_id) const;

virtual void LogModelLoadEnd(uint32_t session_id, const common::Status& status) const;

virtual void LogSessionCreationEnd(uint32_t session_id,
const common::Status& status) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const;
const common::Status& status) const;


virtual void LogRunStart(uint32_t session_id) const;

virtual void LogRegisterEpLibraryWithLibPath(const std::string& registration_name,
const std::string& lib_path) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const std::string& lib_path) const;
const std::string& lib_path) const;


virtual void LogRegisterEpLibraryStart(const std::string& registration_name) const;

virtual void LogRegisterEpLibraryEnd(const std::string& registration_name,
const common::Status& status) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const;
const common::Status& status) const;


private:
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(Telemetry);
};
Expand Down
134 changes: 132 additions & 2 deletions onnxruntime/core/platform/windows/telemetry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ void WindowsTelemetry::LogCompileModelStart(uint32_t session_id,
TraceLoggingInt32(graph_optimization_level, "graphOptimizationLevel"),
TraceLoggingBool(embed_ep_context, "embedEpContext"),
TraceLoggingBool(has_external_initializers_file, "hasExternalInitializersFile"),
TraceLoggingString(execution_provider_string.c_str(), "executionProviderIds"));
TraceLoggingString(execution_provider_string.c_str(), "executionProviderIds"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogCompileModelComplete(uint32_t session_id,
Expand All @@ -480,7 +481,8 @@ void WindowsTelemetry::LogCompileModelComplete(uint32_t session_id,
TraceLoggingBool(success, "success"),
TraceLoggingUInt32(error_code, "errorCode"),
TraceLoggingUInt32(error_category, "errorCategory"),
TraceLoggingString(error_message.c_str(), "errorMessage"));
TraceLoggingString(error_message.c_str(), "errorMessage"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogRuntimeError(uint32_t session_id, const common::Status& status, const char* file,
Expand Down Expand Up @@ -668,4 +670,132 @@ void WindowsTelemetry::LogProviderOptions(const std::string& provider_id, const
}
}

void WindowsTelemetry::LogModelLoadStart(uint32_t session_id) const {
if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"ModelLoadStart",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingUInt32(session_id, "sessionId"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogModelLoadEnd(uint32_t session_id, const common::Status& status) const {
if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"ModelLoadEnd",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingUInt32(session_id, "sessionId"),
TraceLoggingBool(status.IsOK(), "isSuccess"),
TraceLoggingUInt32(status.Code(), "errorCode"),
TraceLoggingUInt32(status.Category(), "errorCategory"),
TraceLoggingString(status.IsOK() ? "" : status.ErrorMessage().c_str(), "errorMessage"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogSessionCreationEnd(uint32_t session_id,
const common::Status& status) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const {
const common::Status& status) const {

if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"SessionCreationEnd",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingUInt32(session_id, "sessionId"),
TraceLoggingBool(status.IsOK(), "isSuccess"),
TraceLoggingUInt32(status.Code(), "errorCode"),
TraceLoggingUInt32(status.Category(), "errorCategory"),
TraceLoggingString(status.IsOK() ? "" : status.ErrorMessage().c_str(), "errorMessage"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogRunStart(uint32_t session_id) const {
if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"RunStart",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingUInt32(session_id, "sessionId"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogRegisterEpLibraryWithLibPath(const std::string& registration_name,
const std::string& lib_path) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const std::string& lib_path) const {
const std::string& lib_path) const {

if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"RegisterEpLibraryWithLibPath",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingString(registration_name.c_str(), "registrationName"),
TraceLoggingString(lib_path.c_str(), "libPath"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogRegisterEpLibraryStart(const std::string& registration_name) const {
if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"RegisterEpLibraryStart",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingString(registration_name.c_str(), "registrationName"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

void WindowsTelemetry::LogRegisterEpLibraryEnd(const std::string& registration_name,
const common::Status& status) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const {
const common::Status& status) const {

if (global_register_count_ == 0 || enabled_ == false)
return;

TraceLoggingWrite(telemetry_provider_handle,
"RegisterEpLibraryEnd",
TraceLoggingBool(true, "UTCReplace_AppSessionGuid"),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
// Telemetry info
TraceLoggingUInt8(0, "schemaVersion"),
TraceLoggingString(registration_name.c_str(), "registrationName"),
TraceLoggingBool(status.IsOK(), "isSuccess"),
TraceLoggingUInt32(status.Code(), "errorCode"),
TraceLoggingUInt32(status.Category(), "errorCategory"),
TraceLoggingString(status.IsOK() ? "" : status.ErrorMessage().c_str(), "errorMessage"),
TraceLoggingString(ORT_CALLER_FRAMEWORK, "frameworkName"));
}

} // namespace onnxruntime
17 changes: 17 additions & 0 deletions onnxruntime/core/platform/windows/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@
const std::string& provider_options_string,
bool captureState) const override;

void LogModelLoadStart(uint32_t session_id) const override;

void LogModelLoadEnd(uint32_t session_id, const common::Status& status) const override;

void LogSessionCreationEnd(uint32_t session_id,
const common::Status& status) const override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const override;
const common::Status& status) const override;


void LogRunStart(uint32_t session_id) const override;

void LogRegisterEpLibraryWithLibPath(const std::string& registration_name,
const std::string& lib_path) const override;

void LogRegisterEpLibraryStart(const std::string& registration_name) const override;

void LogRegisterEpLibraryEnd(const std::string& registration_name,

Check warning on line 111 in onnxruntime/core/platform/windows/telemetry.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/platform/windows/telemetry.h:111: Add #include <string> for string [build/include_what_you_use] [4]
const common::Status& status) const override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const common::Status& status) const override;
const common::Status& status) const override;


using EtwInternalCallback = std::function<void(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level,
ULONGLONG MatchAnyKeyword, ULONGLONG MatchAllKeyword,
PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext)>;
Expand Down
10 changes: 9 additions & 1 deletion onnxruntime/core/session/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,13 @@ bool AreVirtualDevicesAllowed(std::string_view lib_registration_name) {
Status Environment::RegisterExecutionProviderLibrary(const std::string& registration_name,
std::unique_ptr<EpLibrary> ep_library,
const std::vector<EpFactoryInternal*>& internal_factories) {
const Env& env = Env::Default();
env.GetTelemetryProvider().LogRegisterEpLibraryStart(registration_name);

if (ep_libraries_.count(registration_name) > 0) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "library is already registered under ", registration_name);
auto status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "library is already registered under ", registration_name);
env.GetTelemetryProvider().LogRegisterEpLibraryEnd(registration_name, status);
return status;
}

auto status = Status::OK();
Expand Down Expand Up @@ -592,6 +597,7 @@ Status Environment::RegisterExecutionProviderLibrary(const std::string& registra
});
}

env.GetTelemetryProvider().LogRegisterEpLibraryEnd(registration_name, status);
return status;
}

Expand All @@ -611,6 +617,8 @@ Status Environment::CreateAndRegisterInternalEps() {
Status Environment::RegisterExecutionProviderLibrary(const std::string& registration_name, const ORTCHAR_T* lib_path) {
std::lock_guard<std::mutex> lock{mutex_};

Env::Default().GetTelemetryProvider().LogRegisterEpLibraryWithLibPath(registration_name, ToUTF8String(lib_path));

std::vector<EpFactoryInternal*> internal_factories = {};
std::unique_ptr<EpLibrary> ep_library;

Expand Down
40 changes: 38 additions & 2 deletions onnxruntime/core/session/inference_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@
tp = session_profiler_.Start();
}
ORT_TRY {
const Env& env = Env::Default();
env.GetTelemetryProvider().LogModelLoadStart(session_id_);

std::lock_guard<std::mutex> l(session_mutex_);
if (is_model_loaded_) { // already loaded
LOGS(*session_logger_, ERROR) << "This session already contains a loaded model.";
Expand Down Expand Up @@ -1011,6 +1014,11 @@
session_profiler_.EndTimeAndRecordEvent(profiling::SESSION_EVENT, event_name, tp);
}

{
const Env& env = Env::Default();
env.GetTelemetryProvider().LogModelLoadEnd(session_id_, status);
}

return status;
}

Expand Down Expand Up @@ -1647,6 +1655,9 @@
}

Status InferenceSession::LoadOrtModelWithLoader(std::function<Status()> load_ort_format_model_bytes) {
const Env& env = Env::Default();
env.GetTelemetryProvider().LogModelLoadStart(session_id_);

std::lock_guard<std::mutex> l(session_mutex_);

if (is_model_loaded_) { // already loaded
Expand Down Expand Up @@ -1767,6 +1778,8 @@

is_model_loaded_ = true;

env.GetTelemetryProvider().LogModelLoadEnd(session_id_, Status::OK());

return Status::OK();
}

Expand Down Expand Up @@ -2618,6 +2631,12 @@
}
}

// Log session creation end telemetry
{
const Env& init_env = Env::Default();
init_env.GetTelemetryProvider().LogSessionCreationEnd(session_id_, status);
}

return status;
}
#if defined(_MSC_VER) && !defined(__clang__)
Expand Down Expand Up @@ -3015,6 +3034,19 @@
Status retval = Status::OK();
const Env& env = Env::Default();

// Determine whether to emit Run telemetry
bool emit_run_telemetry = false;
{
std::lock_guard<std::mutex> telemetry_lock(telemetry_mutex_);
if (TimeDiffMicroSeconds(telemetry_.time_sent_last_) > telemetry_.runtime_perf_interval_) {
emit_run_telemetry = true;
}
}

if (emit_run_telemetry) {
env.GetTelemetryProvider().LogRunStart(session_id_);
}

int graph_annotation_id = 0;
const std::string& graph_annotation_str =
run_options.config_options.GetConfigOrDefault(kOrtRunOptionsConfigCudaGraphAnnotation, "");
Expand Down Expand Up @@ -3210,8 +3242,8 @@
telemetry_.total_run_duration_since_last_ += TimeDiffMicroSeconds(tp);
telemetry_.duration_per_batch_size_[batch_size] += TimeDiffMicroSeconds(tp);

if (TimeDiffMicroSeconds(telemetry_.time_sent_last_) > Telemetry::kDurationBetweenSending) {
// send the telemetry
// Emit RuntimePerf
if (emit_run_telemetry) {
env.GetTelemetryProvider().LogRuntimePerf(session_id_, telemetry_.total_runs_since_last_,
telemetry_.total_run_duration_since_last_,
telemetry_.duration_per_batch_size_);
Expand All @@ -3220,6 +3252,10 @@
telemetry_.total_runs_since_last_ = 0;
telemetry_.total_run_duration_since_last_ = 0;
telemetry_.duration_per_batch_size_.clear();

// Double the interval, capping at kRuntimePerfMaxInterval
telemetry_.runtime_perf_interval_ = std::min(telemetry_.runtime_perf_interval_ * 2,

Check warning on line 3257 in onnxruntime/core/session/inference_session.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <algorithm> for min [build/include_what_you_use] [4] Raw Output: onnxruntime/core/session/inference_session.cc:3257: Add #include <algorithm> for min [build/include_what_you_use] [4]
Telemetry::kRuntimePerfMaxInterval);
}
}

Expand Down
6 changes: 4 additions & 2 deletions onnxruntime/core/session/inference_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,10 @@
std::unordered_map<int64_t, long long> duration_per_batch_size_; // the duration (us) of Run() calls per batch size since the last report

TimePoint time_sent_last_; // the TimePoint of the last report
// Event Rate per provider < 20 peak events per second
constexpr static long long kDurationBetweenSending = 1000 * 1000 * 60 * 10; // duration in (us). send a report every 10 mins
// RuntimePerf backoff: starts at 2s, doubles each emission, caps at 10 min
constexpr static long long kRuntimePerfInitialInterval = 2 * 1000 * 1000; // 2 seconds in (us)

Check warning on line 980 in onnxruntime/core/session/inference_session.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] Raw Output: onnxruntime/core/session/inference_session.h:980: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]
constexpr static long long kRuntimePerfMaxInterval = 1000 * 1000 * 60 * 10; // 10 minutes in (us)

Check warning on line 981 in onnxruntime/core/session/inference_session.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] Raw Output: onnxruntime/core/session/inference_session.h:981: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]
Comment on lines +980 to +981
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constexpr static long long kRuntimePerfInitialInterval = 2 * 1000 * 1000; // 2 seconds in (us)
constexpr static long long kRuntimePerfMaxInterval = 1000 * 1000 * 60 * 10; // 10 minutes in (us)
constexpr static long long kRuntimePerfInitialInterval = 2 * 1000 * 1000; // 2 seconds in (us)
constexpr static long long kRuntimePerfMaxInterval = 1000 * 1000 * 60 * 10; // 10 minutes in (us)

long long runtime_perf_interval_ = kRuntimePerfInitialInterval;

Check warning on line 982 in onnxruntime/core/session/inference_session.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] Raw Output: onnxruntime/core/session/inference_session.h:982: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]
} telemetry_;

mutable std::mutex telemetry_mutex_; // to ensure thread-safe access to telemetry data
Expand Down
Loading