Skip to content

Commit

Permalink
Telemetry events
Browse files Browse the repository at this point in the history
* Don't trace event on exit
change 'PowertoyModuleDeleter' to not call 'module->disable();' before 'module->destroy();' so the module can distinguish between being turned off and PowerToys exiting.
Code formatting.

* uppercase for event name

* Trace on/off event for ShortcutGuide module

* Trace the 'hide' event only if the guide was visible
'on_hide()' is invoked when the module is turned off, in that case don't trace the hide event.

* Remove spaces in data field names
Remove 'ShowGuide' event since it's not providing any useful data.

* Include build number in version number
  • Loading branch information
enricogior committed Oct 22, 2019
1 parent 5fb59cd commit a07a426
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 49 deletions.
4 changes: 3 additions & 1 deletion src/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ std::wstring get_process_path(HWND window) noexcept {
std::wstring get_product_version() {
static std::wstring version = std::to_wstring(VERSION_MAJOR) +
L"." + std::to_wstring(VERSION_MINOR) +
L"." + std::to_wstring(VERSION_REVISION);
L"." + std::to_wstring(VERSION_REVISION) +
L"." + std::to_wstring(VERSION_BUILD);

return version;
}
21 changes: 14 additions & 7 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ class FancyZonesModule : public PowertoyModuleIface
// Disable the powertoy
virtual void disable()
{
if (m_app)
{
Trace::FancyZones::EnableFancyZones(false);
m_app->Destroy();
m_app = nullptr;
}
Disable(true);
}

// Returns if the powertoy is enabled
Expand Down Expand Up @@ -190,7 +185,7 @@ class FancyZonesModule : public PowertoyModuleIface
// Destroy the powertoy and free memory
virtual void destroy() override
{
disable();
Disable(false);
delete this;
}

Expand All @@ -207,6 +202,18 @@ class FancyZonesModule : public PowertoyModuleIface
return WI_IsFlagSet(style, WS_MAXIMIZEBOX) && WI_IsFlagClear(style, WS_CHILD) && WI_IsFlagClear(exStyle, WS_EX_TOOLWINDOW);
}

void Disable(bool const traceEvent)
{
if (m_app) {
if (traceEvent)
{
Trace::FancyZones::EnableFancyZones(false);
}
m_app->Destroy();
m_app = nullptr;
}
}

intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
void HandleWinHookEvent(WinHookEvent* data) noexcept;
void MoveSizeStart(HWND window, POINT const& ptScreen) noexcept;
Expand Down
24 changes: 12 additions & 12 deletions src/modules/fancyzones/lib/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ void Trace::SettingsChanged(const Settings& settings) noexcept
"FancyZones::Event::SettingsChanged",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingBoolean(settings.shiftDrag, "Shift drag"),
TraceLoggingBoolean(settings.displayChange_moveWindows, "Move Windows On Display Change"),
TraceLoggingBoolean(settings.virtualDesktopChange_moveWindows, "Move Windows On Virtual Desktop Change"),
TraceLoggingBoolean(settings.zoneSetChange_flashZones, "Flash zones On Zone Set Change"),
TraceLoggingBoolean(settings.zoneSetChange_moveWindows, "Move Windows On Zone Set Change"),
TraceLoggingBoolean(settings.overrideSnapHotkeys, "Override snap hot keys"),
TraceLoggingWideString(settings.zoneHightlightColor.c_str(), "Zone highlight color"));
TraceLoggingBoolean(settings.shiftDrag, "ShiftDrag"),
TraceLoggingBoolean(settings.displayChange_moveWindows, "MoveWindowsOnDisplayChange"),
TraceLoggingBoolean(settings.virtualDesktopChange_moveWindows, "MoveWindowsOnVirtualDesktopChange"),
TraceLoggingBoolean(settings.zoneSetChange_flashZones, "FlashZonesOnZoneSetChange"),
TraceLoggingBoolean(settings.zoneSetChange_moveWindows, "MoveWindowsOnZoneSetChange"),
TraceLoggingBoolean(settings.overrideSnapHotkeys, "OverrideSnapHotKeys"),
TraceLoggingWideString(settings.zoneHightlightColor.c_str(), "ZoneHighlightColor"));
}

void Trace::VirtualDesktopChanged() noexcept
Expand All @@ -107,8 +107,8 @@ void Trace::ZoneWindow::KeyUp(WPARAM wParam, bool isEditorMode) noexcept
"FancyZones::Event::ZoneWindowKeyUp",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingValue(wParam, "Keyboard value"),
TraceLoggingBoolean(isEditorMode, "Editor Mode"));
TraceLoggingValue(wParam, "KeyboardValue"),
TraceLoggingBoolean(isEditorMode, "EditorMode"));
}

void Trace::ZoneWindow::MoveSizeEnd(_In_opt_ winrt::com_ptr<IZoneSet> activeSet) noexcept
Expand All @@ -119,7 +119,7 @@ void Trace::ZoneWindow::MoveSizeEnd(_In_opt_ winrt::com_ptr<IZoneSet> activeSet)
"FancyZones::Event::MoveSizeEnd",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "Active Set"),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "ActiveSet"),
TraceLoggingValue(zoneInfo.NumberOfZones, "NumberOfZones"),
TraceLoggingValue(zoneInfo.NumberOfWindows, "NumberOfWindows"),
TraceLoggingValue(static_cast<int>(zoneInfo.Layout), "LayoutKind"));
Expand All @@ -133,7 +133,7 @@ void Trace::ZoneWindow::CycleActiveZoneSet(_In_opt_ winrt::com_ptr<IZoneSet> act
"FancyZones::Event::CycleActiveZoneSet",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "Active Set"),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "ActiveSet"),
TraceLoggingValue(zoneInfo.NumberOfZones, "NumberOfZones"),
TraceLoggingValue(zoneInfo.NumberOfWindows, "NumberOfWindows"),
TraceLoggingValue(static_cast<int>(zoneInfo.Layout), "LayoutKind"),
Expand All @@ -156,7 +156,7 @@ void Trace::ZoneWindow::EditorModeActivity::Stop(_In_opt_ winrt::com_ptr<IZoneSe
m_activity.value(),
"FancyZones::Activity::EditorMode",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "Active Set"),
TraceLoggingValue(reinterpret_cast<void*>(activeSet.get()), "ActiveSet"),
TraceLoggingValue(zoneInfo.NumberOfZones, "NumberOfZones"),
TraceLoggingValue(zoneInfo.NumberOfWindows, "NumberOfWindows"),
TraceLoggingValue(static_cast<int>(zoneInfo.Layout), "LayoutKind"));
Expand Down
1 change: 0 additions & 1 deletion src/modules/interface/powertoy_module_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
- signal_event() to send an event the PowerToy registered to.
When terminating, the runner will:
- call disable(),
- call destroy() which should free all the memory and delete the PowerToy object,
- unload the DLL.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/modules/shortcut_guide/overlay_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ void D2DOverlayWindow::show(HWND active_window) {
tasklist_cv_mutex.unlock();
tasklist_cv.notify_one();
}
Trace::EventShow();
}

void D2DOverlayWindow::animate(int vk_code) {
Expand Down Expand Up @@ -350,7 +349,11 @@ void D2DOverlayWindow::on_hide() {
DwmUnregisterThumbnail(thumbnail);
}
std::chrono::steady_clock::time_point shown_end_time = std::chrono::steady_clock::now();
Trace::EventHide(std::chrono::duration_cast<std::chrono::milliseconds>(shown_end_time - shown_start_time).count(), key_pressed);
// Trace the event only if the overaly window was visible.
if (shown_start_time.time_since_epoch().count() > 0) {
Trace::EventHide(std::chrono::duration_cast<std::chrono::milliseconds>(shown_end_time - shown_start_time).count(), key_pressed);
shown_start_time = {};
}
key_pressed.clear();
}

Expand Down
11 changes: 10 additions & 1 deletion src/modules/shortcut_guide/shortcut_guide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void OverlayWindow::set_config(const wchar_t * config) {

void OverlayWindow::enable() {
if (!_enabled) {
Trace::EnableShortcutGuide(true);
winkey_popup = new D2DOverlayWindow();
winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value)/100.0f);
winkey_popup->set_theme(theme.value);
Expand All @@ -97,8 +98,11 @@ void OverlayWindow::enable() {
_enabled = true;
}

void OverlayWindow::disable() {
void OverlayWindow::disable(bool trace_event) {
if (_enabled) {
if (trace_event) {
Trace::EnableShortcutGuide(false);
}
winkey_popup->hide();
target_state->exit();
delete target_state;
Expand All @@ -109,6 +113,10 @@ void OverlayWindow::disable() {
_enabled = false;
}

void OverlayWindow::disable() {
this->disable(true);
}

bool OverlayWindow::is_enabled() {
return _enabled;
}
Expand Down Expand Up @@ -142,6 +150,7 @@ void OverlayWindow::was_hidden() {
}

void OverlayWindow::destroy() {
this->disable(false);
delete this;
instance = nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/shortcut_guide/shortcut_guide.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class OverlayWindow : public PowertoyModuleIface {
void was_hidden();

virtual void destroy() override;

private:
TargetState* target_state;
D2DOverlayWindow *winkey_popup;
bool _enabled = false;

void init_settings();
void disable(bool trace_event);

struct PressTime {
PCWSTR name = L"press_time";
Expand Down
31 changes: 16 additions & 15 deletions src/modules/shortcut_guide/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ TRACELOGGING_DEFINE_PROVIDER(
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
TraceLoggingOptionProjectTelemetry());

void Trace::RegisterProvider() {
void Trace::RegisterProvider() noexcept {
TraceLoggingRegister(g_hProvider);
}

void Trace::UnregisterProvider() {
void Trace::UnregisterProvider() noexcept {
TraceLoggingUnregister(g_hProvider);
}

void Trace::EventShow() {
TraceLoggingWrite(
g_hProvider,
"ShortcutGuide::Event::ShowGuide",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
}

void Trace::EventHide(const __int64 duration_ms, std::vector<int> &key_pressed) {
void Trace::EventHide(const __int64 duration_ms, std::vector<int> &key_pressed) noexcept {
std::string vk_codes;
std::vector<int>::iterator it;
for (it = key_pressed.begin(); it != key_pressed.end(); ) {
Expand All @@ -38,9 +29,19 @@ void Trace::EventHide(const __int64 duration_ms, std::vector<int> &key_pressed)
TraceLoggingWrite(
g_hProvider,
"ShortcutGuide::Event::HideGuide",
TraceLoggingInt64(duration_ms, "Duration in ms"),
TraceLoggingInt64(key_pressed.size(), "# of key pressed"),
TraceLoggingString(vk_codes.c_str(), "list of key pressed"),
TraceLoggingInt64(duration_ms, "DurationInMs"),
TraceLoggingInt64(key_pressed.size(), "NumberOfKeysPressed"),
TraceLoggingString(vk_codes.c_str(), "ListOfKeysPressed"),
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
}

void Trace::EnableShortcutGuide(bool enabled) noexcept {
TraceLoggingWrite(
g_hProvider,
"ShortcutGuide::Event::EnableGuide",
TraceLoggingBoolean(enabled, "Enabled"),
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
Expand Down
8 changes: 4 additions & 4 deletions src/modules/shortcut_guide/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class Trace {
public:
static void RegisterProvider();
static void UnregisterProvider();
static void EventShow();
static void EventHide(const __int64 duration_ms, std::vector<int> &key_pressed);
static void RegisterProvider() noexcept;
static void UnregisterProvider() noexcept;
static void EventHide(const __int64 duration_ms, std::vector<int> &key_pressed) noexcept;
static void EnableShortcutGuide(bool enabled) noexcept;
};
17 changes: 12 additions & 5 deletions src/runner/powertoy_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct PowertoyModuleDeleter {
void operator()(PowertoyModuleIface* module) const {
if (module) {
powertoys_events().unregister_receiver(module);
module->disable();
module->destroy();
}
}
Expand All @@ -26,12 +25,12 @@ struct PowertoyModuleDLLDeleter {
}
};


class PowertoyModule {
public:
PowertoyModule(PowertoyModuleIface* module, HMODULE handle) : handle(handle), module(module) {
if (!module)
if (!module) {
throw std::runtime_error("Module not initialized");
}
name = module->get_name();
auto want_signals = module->get_events();
if (want_signals) {
Expand All @@ -40,9 +39,11 @@ class PowertoyModule {
}
}
}

const std::wstring& get_name() const {
return name;
}

const std::wstring get_config() const {
std::wstring result;
int size = 0;
Expand All @@ -54,30 +55,36 @@ class PowertoyModule {
delete[] buffer;
return result;
}

void set_config(const std::wstring& config) {
module->set_config(config.c_str());
}

void call_custom_action(const std::wstring& action) {
module->call_custom_action(action.c_str());
}

intptr_t signal_event(const std::wstring& signal_event, intptr_t data) {
return module->signal_event(signal_event.c_str(), data);
}

bool is_enabled() {
return module->is_enabled();
}

void enable() {
module->enable();
}

void disable() {
module->disable();
}

private:
std::unique_ptr<HMODULE, PowertoyModuleDLLDeleter> handle;
std::unique_ptr<PowertoyModuleIface, PowertoyModuleDeleter> module;
std::wstring name;
};


PowertoyModule load_powertoy(const std::wstring& filename);
std::unordered_map<std::wstring, PowertoyModule>& modules();
std::unordered_map<std::wstring, PowertoyModule>& modules();
2 changes: 1 addition & 1 deletion src/runner/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Trace::EventLaunch(const std::wstring& versionNumber) {
TraceLoggingWrite(
g_hProvider,
"Runner::Event::Launch",
TraceLoggingWideString(versionNumber.c_str(), "version"),
TraceLoggingWideString(versionNumber.c_str(), "Version"),
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
Expand Down

0 comments on commit a07a426

Please sign in to comment.