mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-15 20:50:42 +00:00
59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "pch.h"
|
|
|
|
#include "inc/TelemetryEvent.h"
|
|
|
|
using namespace _winmlt;
|
|
|
|
static uint64_t s_event_id = 0;
|
|
|
|
static const char*
|
|
EventCategoryToString(
|
|
EventCategory category) {
|
|
switch (category) {
|
|
case EventCategory::kModelLoad:
|
|
return "Model load";
|
|
case EventCategory::kSessionCreation:
|
|
return "Session creation";
|
|
case EventCategory::kBinding:
|
|
return "Binding";
|
|
case EventCategory::kEvaluation:
|
|
return "Evaluation";
|
|
default:
|
|
throw std::invalid_argument("category");
|
|
}
|
|
}
|
|
|
|
TelemetryEvent::TelemetryEvent(
|
|
EventCategory category) {
|
|
auto is_provider_enabled =
|
|
TraceLoggingProviderEnabled(
|
|
winml_trace_logging_provider,
|
|
WINEVENT_LEVEL_VERBOSE,
|
|
WINML_PROVIDER_KEYWORD_START_STOP);
|
|
|
|
if (is_provider_enabled) {
|
|
category_ = category;
|
|
event_id_ = InterlockedIncrement(&s_event_id);
|
|
|
|
WinMLTraceLoggingWrite(
|
|
winml_trace_logging_provider,
|
|
"started event",
|
|
TraceLoggingString(EventCategoryToString(category_), "event"),
|
|
TraceLoggingInt64(event_id_.value(), "eventId"),
|
|
TraceLoggingKeyword(WINML_PROVIDER_KEYWORD_START_STOP));
|
|
}
|
|
}
|
|
|
|
TelemetryEvent::~TelemetryEvent() {
|
|
if (event_id_.has_value()) {
|
|
WinMLTraceLoggingWrite(
|
|
winml_trace_logging_provider,
|
|
"stopped event",
|
|
TraceLoggingString(EventCategoryToString(category_), "event"),
|
|
TraceLoggingInt64(event_id_.value(), "eventId"),
|
|
TraceLoggingKeyword(WINML_PROVIDER_KEYWORD_START_STOP));
|
|
}
|
|
}
|