Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "lib/Telemetry/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)
    );
  }
}