trace.cpp
1 #include "pch.h" 2 #include "trace.h" 3 4 #include <ProjectTelemetry.h> 5 6 // Telemetry strings should not be localized. 7 #define LoggingProviderKey "Microsoft.PowerToys" 8 9 TRACELOGGING_DEFINE_PROVIDER( 10 g_hProvider, 11 LoggingProviderKey, 12 // {38e8889b-9731-53f5-e901-e8a7c1753074} 13 (0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74), 14 TraceLoggingOptionProjectTelemetry()); 15 16 void Trace::Workspaces::Enable(bool enabled) noexcept 17 { 18 TraceLoggingWriteWrapper( 19 g_hProvider, 20 "Workspaces_Enable", 21 ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), 22 TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), 23 TraceLoggingBoolean(enabled, "Enabled")); 24 } 25 26 void Trace::Workspaces::Launch(bool success, 27 const WorkspacesData::WorkspacesProject& project, 28 InvokePoint invokePoint, 29 double launchTimeSeconds, 30 bool setupIsDifferent, 31 const std::vector<std::pair<std::wstring, std::wstring>> errors) noexcept 32 { 33 int cliCount = 0; 34 int adminCount = 0; 35 for (const auto& app : project.apps) 36 { 37 if (!app.commandLineArgs.empty()) 38 { 39 cliCount++; 40 } 41 42 if (app.isElevated) 43 { 44 adminCount++; 45 } 46 } 47 48 std::string invokePointStr; 49 switch (invokePoint) 50 { 51 case EditorButton: 52 invokePointStr = "launchButton"; 53 break; 54 case Shortcut: 55 invokePointStr = "shortcut"; 56 break; 57 case LaunchAndEdit: 58 invokePointStr = "launchAndEdit"; 59 break; 60 default: 61 break; 62 } 63 64 std::wstring errorStr{}; 65 for (const auto& [exeName, errorMessage] : errors) 66 { 67 errorStr += exeName + L":" + errorMessage + L"; "; 68 } 69 70 TraceLoggingWriteWrapper( 71 g_hProvider, 72 "Workspaces_LaunchEvent", 73 ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), 74 TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), 75 TraceLoggingBoolean(success, "successful"), // True if launch successfully completely. False if ANY app failed. 76 TraceLoggingInt64(project.monitors.size(), "numScreens"), // Number of screens present in the project 77 TraceLoggingInt64(project.apps.size(), "appCount"), // Total number of apps in the project 78 TraceLoggingInt32(cliCount, "cliCount"), // Number of apps with CLI args 79 TraceLoggingInt32(adminCount, "adminCount"), // Number of apps with "Launch as admin" set 80 TraceLoggingString(invokePointStr.c_str(), "invokePoint"), // The method by which the user launched the project. 81 TraceLoggingFloat64(launchTimeSeconds, "launchTime"), // The time, in seconds, it took for the project to completely launch (from when user invoked launch to when last window successfully moved) 82 TraceLoggingBool(setupIsDifferent, "setupDiff"), // True if users monitor setup (in terms of # monitors and monitor resolution & aspect ratio) is different from the setup defined at project creation. False if setup is the same. 83 TraceLoggingWideString(errorStr.c_str(), "failures") // List of errors encountered when applicable. Collects .exe name and error message in String fields 84 ); 85 }