Add telemetry event for FZ editor (#1294)

* trace zones settings changes
This commit is contained in:
Seraphima Zykova 2020-02-17 19:40:02 +03:00 committed by GitHub
parent 93f88800b8
commit 604070763d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include "JsonHelpers.h"
#include "RegistryHelpers.h"
#include "ZoneSet.h"
#include "trace.h"
#include <common/common.h>
@ -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);
}

View file

@ -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();

View file

@ -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<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;
@ -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

View file

@ -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;