Skip to content

Commit

Permalink
Add telemetry event for FZ editor (#1294)
Browse files Browse the repository at this point in the history
* trace zones settings changes
  • Loading branch information
SeraphimaZykova authored Feb 17, 2020
1 parent 93f8880 commit 6040707
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/modules/fancyzones/lib/JsonHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "JsonHelpers.h"
#include "RegistryHelpers.h"
#include "ZoneSet.h"
#include "trace.h"

#include <common/common.h>

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion src/modules/fancyzones/lib/JsonHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,25 @@ namespace JSONHelpers
return activeDeviceId;
}

#if defined(UNIT_TESTS)
inline const std::unordered_map<std::wstring, DeviceInfoData>& GetDeviceInfoMap() const
{
std::scoped_lock lock{ dataLock };
return deviceInfoMap;
}

inline const std::unordered_map<std::wstring, CustomZoneSetData>& GetCustomZoneSetsMap() const
{
std::scoped_lock lock{ dataLock };
return customZoneSetsMap;
}

inline const std::unordered_map<std::wstring, AppZoneHistoryData>& GetAppZoneHistoryMap() const
{
std::scoped_lock lock{ dataLock };
return appZoneHistoryMap;
}

#if defined(UNIT_TESTS)
inline void clear_data()
{
appliedZoneSetsMap.clear();
Expand Down
86 changes: 84 additions & 2 deletions src/modules/fancyzones/lib/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "trace.h"
#include "lib/ZoneSet.h"
#include "lib/Settings.h"
#include "lib/JsonHelpers.h"

TRACELOGGING_DEFINE_PROVIDER(
g_hProvider,
Expand Down Expand Up @@ -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<int>(data.GetAppZoneHistoryMap().size());
const auto& customZones = data.GetCustomZoneSetsMap();
const auto& devices = data.GetDeviceInfoMap();

std::unique_ptr<INT32[]> customZonesArray(new (std::nothrow) INT32[customZones.size()]);
if (!customZonesArray)
{
return;
}

auto getCustomZoneCount = [&data](const std::variant<JSONHelpers::CanvasLayoutInfo, JSONHelpers::GridLayoutInfo>& layoutInfo) -> int {
if (std::holds_alternative<JSONHelpers::GridLayoutInfo>(layoutInfo))
{
const auto& info = std::get<JSONHelpers::GridLayoutInfo>(layoutInfo);
return (info.rows() * info.columns());
}
else if (std::holds_alternative<JSONHelpers::CanvasLayoutInfo>(layoutInfo))
{
const auto& info = std::get<JSONHelpers::CanvasLayoutInfo>(layoutInfo);
return static_cast<int>(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<int>(customZones.size()), "CustomZoneSetCount"),
TraceLoggingInt32Array(customZonesArray.get(), static_cast<int>(customZones.size()), "NumberOfZonesForEachCustomZoneSet"),
TraceLoggingInt32(static_cast<int>(devices.size()), "ActiveZoneSetsCount"),
TraceLoggingWideString(activeZoneSetInfo.c_str(), "ActiveZoneSetsList"));
}

void Trace::SettingsChanged(const Settings& settings) noexcept
{
const auto& editorHotkey = settings.editorHotkey;
Expand All @@ -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<int>(settings.excludedAppsArray.size()), "ExcludedAppsCount")
);
TraceLoggingInt32(static_cast<int>(settings.excludedAppsArray.size()), "ExcludedAppsCount"));
}

void Trace::VirtualDesktopChanged() noexcept
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Trace
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;
Expand Down

0 comments on commit 6040707

Please sign in to comment.