From 604070763d8ef122a320d6d065f36f5acbe7b4b1 Mon Sep 17 00:00:00 2001 From: Seraphima Zykova Date: Mon, 17 Feb 2020 19:40:02 +0300 Subject: [PATCH] Add telemetry event for FZ editor (#1294) * trace zones settings changes --- src/modules/fancyzones/lib/JsonHelpers.cpp | 7 ++ src/modules/fancyzones/lib/JsonHelpers.h | 5 +- src/modules/fancyzones/lib/trace.cpp | 86 +++++++++++++++++++++- src/modules/fancyzones/lib/trace.h | 1 + 4 files changed, 96 insertions(+), 3 deletions(-) diff --git a/src/modules/fancyzones/lib/JsonHelpers.cpp b/src/modules/fancyzones/lib/JsonHelpers.cpp index ca95162439..c40adc6374 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.cpp +++ b/src/modules/fancyzones/lib/JsonHelpers.cpp @@ -2,6 +2,7 @@ #include "JsonHelpers.h" #include "RegistryHelpers.h" #include "ZoneSet.h" +#include "trace.h" #include @@ -498,6 +499,12 @@ namespace JSONHelpers root.SetNamedValue(L"devices", SerializeDeviceInfos()); root.SetNamedValue(L"custom-zone-sets", SerializeCustomZoneSets()); + auto before = json::from_file(jsonFilePath); + if (!before.has_value() || before.value().Stringify() != root.Stringify()) + { + Trace::FancyZones::DataChanged(); + } + json::to_file(jsonFilePath, root); } diff --git a/src/modules/fancyzones/lib/JsonHelpers.h b/src/modules/fancyzones/lib/JsonHelpers.h index 19feda4aeb..04cc0e9ff0 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.h +++ b/src/modules/fancyzones/lib/JsonHelpers.h @@ -181,22 +181,25 @@ namespace JSONHelpers return activeDeviceId; } -#if defined(UNIT_TESTS) inline const std::unordered_map& GetDeviceInfoMap() const { + std::scoped_lock lock{ dataLock }; return deviceInfoMap; } inline const std::unordered_map& GetCustomZoneSetsMap() const { + std::scoped_lock lock{ dataLock }; return customZoneSetsMap; } inline const std::unordered_map& GetAppZoneHistoryMap() const { + std::scoped_lock lock{ dataLock }; return appZoneHistoryMap; } +#if defined(UNIT_TESTS) inline void clear_data() { appliedZoneSetsMap.clear(); diff --git a/src/modules/fancyzones/lib/trace.cpp b/src/modules/fancyzones/lib/trace.cpp index 864c5cd470..078d8ff69c 100644 --- a/src/modules/fancyzones/lib/trace.cpp +++ b/src/modules/fancyzones/lib/trace.cpp @@ -2,6 +2,7 @@ #include "trace.h" #include "lib/ZoneSet.h" #include "lib/Settings.h" +#include "lib/JsonHelpers.h" TRACELOGGING_DEFINE_PROVIDER( g_hProvider, @@ -64,6 +65,88 @@ void Trace::FancyZones::OnKeyDown(DWORD vkCode, bool win, bool control, bool inM TraceLoggingBoolean(inMoveSize, "InMoveSize")); } +void Trace::FancyZones::DataChanged() noexcept +{ + const JSONHelpers::FancyZonesData& data = JSONHelpers::FancyZonesDataInstance(); + int appsHistorySize = static_cast(data.GetAppZoneHistoryMap().size()); + const auto& customZones = data.GetCustomZoneSetsMap(); + const auto& devices = data.GetDeviceInfoMap(); + + std::unique_ptr customZonesArray(new (std::nothrow) INT32[customZones.size()]); + if (!customZonesArray) + { + return; + } + + auto getCustomZoneCount = [&data](const std::variant& layoutInfo) -> int { + if (std::holds_alternative(layoutInfo)) + { + const auto& info = std::get(layoutInfo); + return (info.rows() * info.columns()); + } + else if (std::holds_alternative(layoutInfo)) + { + const auto& info = std::get(layoutInfo); + return static_cast(info.zones.size()); + } + return 0; + }; + + //NumberOfZonesForEachCustomZoneSet + int i = 0; + for (const auto& [id, customZoneSetData] : customZones) + { + customZonesArray.get()[i] = getCustomZoneCount(customZoneSetData.info); + i++; + } + + //ActiveZoneSetsList + std::wstring activeZoneSetInfo; + for (const auto& [id, device] : devices) + { + const JSONHelpers::ZoneSetLayoutType type = device.activeZoneSet.type; + if (!activeZoneSetInfo.empty()) + { + activeZoneSetInfo += L"; "; + } + activeZoneSetInfo += L"type: " + JSONHelpers::TypeToString(type); + + int zoneCount = -1; + if (type == JSONHelpers::ZoneSetLayoutType::Custom) + { + const auto& activeCustomZone = customZones.find(device.activeZoneSet.uuid); + if (activeCustomZone != customZones.end()) + { + zoneCount = getCustomZoneCount(activeCustomZone->second.info); + } + } + else + { + zoneCount = device.zoneCount; + } + + if (zoneCount != -1) + { + activeZoneSetInfo += L", zone count: " + std::to_wstring(zoneCount); + } + else + { + activeZoneSetInfo += L", custom zone data was deleted"; + } + } + + TraceLoggingWrite( + g_hProvider, + "FancyZones_ZoneSettingsChanged", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), + TraceLoggingInt32(appsHistorySize, "AppsInHistoryCount"), + TraceLoggingInt32(static_cast(customZones.size()), "CustomZoneSetCount"), + TraceLoggingInt32Array(customZonesArray.get(), static_cast(customZones.size()), "NumberOfZonesForEachCustomZoneSet"), + TraceLoggingInt32(static_cast(devices.size()), "ActiveZoneSetsCount"), + TraceLoggingWideString(activeZoneSetInfo.c_str(), "ActiveZoneSetsList")); +} + void Trace::SettingsChanged(const Settings& settings) noexcept { const auto& editorHotkey = settings.editorHotkey; @@ -90,8 +173,7 @@ void Trace::SettingsChanged(const Settings& settings) noexcept TraceLoggingWideString(settings.zoneHightlightColor.c_str(), "ZoneHighlightColor"), TraceLoggingInt32(settings.zoneHighlightOpacity, "ZoneHighlightOpacity"), TraceLoggingWideString(hotkeyStr.c_str(), "Hotkey"), - TraceLoggingInt32(static_cast(settings.excludedAppsArray.size()), "ExcludedAppsCount") - ); + TraceLoggingInt32(static_cast(settings.excludedAppsArray.size()), "ExcludedAppsCount")); } void Trace::VirtualDesktopChanged() noexcept diff --git a/src/modules/fancyzones/lib/trace.h b/src/modules/fancyzones/lib/trace.h index 3d7f9cd405..2cb68d7fe4 100644 --- a/src/modules/fancyzones/lib/trace.h +++ b/src/modules/fancyzones/lib/trace.h @@ -14,6 +14,7 @@ public: public: static void EnableFancyZones(bool enabled) noexcept; static void OnKeyDown(DWORD vkCode, bool win, bool control, bool inMoveSize) noexcept; + static void DataChanged() noexcept; }; static void SettingsChanged(const Settings& settings) noexcept;