trace.cpp
 1  #include "pch.h"
 2  #include "trace.h"
 3  
 4  #include <common/Telemetry/TraceBase.h>
 5  
 6  TRACELOGGING_DEFINE_PROVIDER(
 7      g_hProvider,
 8      "Microsoft.PowerToys",
 9      // {38e8889b-9731-53f5-e901-e8a7c1753074}
10      (0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
11      TraceLoggingOptionProjectTelemetry());
12  
13  // Log number of key remaps when the user uses Edit Keyboard and saves settings
14  void Trace::KeyRemapCount(const DWORD keyToKeyCount, const DWORD keyToShortcutCount, const DWORD keyToTextCount) noexcept
15  {
16      TraceLoggingWriteWrapper(
17          g_hProvider,
18          "KeyboardManager_KeyRemapCount",
19          ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
20          TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
21          TraceLoggingValue(keyToKeyCount + keyToShortcutCount, "KeyRemapCount"),
22          TraceLoggingValue(keyToKeyCount, "KeyToKeyRemapCount"),
23          TraceLoggingValue(keyToShortcutCount, "KeyToShortcutRemapCount"),
24          TraceLoggingValue(keyToTextCount, "KeyToTextRemapCount"));
25  }
26  
27  // Log number of os level shortcut remaps when the user uses Edit Shortcuts and saves settings
28  void Trace::OSLevelShortcutRemapCount(const DWORD shortcutToShortcutCount, const DWORD shortcutToKeyCount) noexcept
29  {
30      TraceLoggingWriteWrapper(
31          g_hProvider,
32          "KeyboardManager_OSLevelShortcutRemapCount",
33          ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
34          TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
35          TraceLoggingValue(shortcutToShortcutCount + shortcutToKeyCount, "OSLevelShortcutRemapCount"),
36          TraceLoggingValue(shortcutToShortcutCount, "OSLevelShortcutToShortcutRemapCount"),
37          TraceLoggingValue(shortcutToKeyCount, "OSLevelShortcutToKeyRemapCount"));
38  }
39  
40  // Log number of app specific shortcut remaps when the user uses Edit Shortcuts and saves settings
41  void Trace::AppSpecificShortcutRemapCount(const DWORD shortcutToShortcutCount, const DWORD shortcutToKeyCount) noexcept
42  {
43      TraceLoggingWriteWrapper(
44          g_hProvider,
45          "KeyboardManager_AppSpecificShortcutRemapCount",
46          ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
47          TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
48          TraceLoggingValue(shortcutToShortcutCount + shortcutToKeyCount, "AppSpecificShortcutRemapCount"),
49          TraceLoggingValue(shortcutToShortcutCount, "AppSpecificShortcutToShortcutRemapCount"),
50          TraceLoggingValue(shortcutToKeyCount, "AppSpecificShortcutToKeyRemapCount"));
51  }
52  
53  // Log if an error occurs in KBM
54  void Trace::Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept
55  {
56      TraceLoggingWriteWrapper(
57          g_hProvider,
58          "KeyboardManager_Error",
59          ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
60          TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
61          TraceLoggingValue(methodName.c_str(), "MethodName"),
62          TraceLoggingValue(errorCode, "ErrorCode"),
63          TraceLoggingValue(errorMessage.c_str(), "ErrorMessage"));
64  }