Add telemetry event for measuring time taken to display PT Run (#5201)

* Added LauncherHotkeyEvent

* Split into cold state and warm state events
This commit is contained in:
Arjun Balgovind
2020-07-24 12:38:16 -07:00
committed by GitHub
parent 65b6513207
commit 39ec10cbba
4 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
using System.Diagnostics.Tracing;
namespace Microsoft.PowerLauncher.Telemetry
{
[EventData]
public class LauncherColdStateHotkeyEvent : EventBase, IEvent
{
public double HotkeyToVisibleTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
using System.Diagnostics.Tracing;
namespace Microsoft.PowerLauncher.Telemetry
{
[EventData]
public class LauncherWarmStateHotkeyEvent : EventBase, IEvent
{
public double HotkeyToVisibleTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -28,6 +28,7 @@ namespace PowerLauncher
private bool _isTextSetProgrammatically;
bool _deletePressed = false;
Timer _firstDeleteTimer = new Timer();
bool _coldStateHotkeyPressed = false;
#endregion
@@ -371,6 +372,17 @@ namespace PowerLauncher
{
SearchBox.QueryTextBox.SelectAll();
}
// Log the time taken from pressing the hotkey till launcher is visible as separate events depending on if it's the first hotkey invoke or second
if (!_coldStateHotkeyPressed)
{
PowerToysTelemetry.Log.WriteEvent(new LauncherColdStateHotkeyEvent() { HotkeyToVisibleTimeMs = _viewModel.GetHotkeyEventTimeMs() });
_coldStateHotkeyPressed = true;
}
else
{
PowerToysTelemetry.Log.WriteEvent(new LauncherWarmStateHotkeyEvent() { HotkeyToVisibleTimeMs = _viewModel.GetHotkeyEventTimeMs() });
}
}
else
{

View File

@@ -46,6 +46,7 @@ namespace PowerLauncher.ViewModel
private HotkeyManager _hotkeyManager { get; set; }
private ushort _hotkeyHandle;
private readonly Internationalization _translator = InternationalizationManager.Instance;
private System.Diagnostics.Stopwatch hotkeyTimer = new System.Diagnostics.Stopwatch();
#endregion
@@ -618,7 +619,12 @@ namespace PowerLauncher.ViewModel
{
if (!ShouldIgnoreHotkeys())
{
// If launcher window was hidden and the hotkey was pressed, start telemetry event
if (MainWindowVisibility != Visibility.Visible)
{
StartHotkeyTimer();
}
if (_settings.LastQueryMode == LastQueryMode.Empty)
{
ChangeQueryText(string.Empty);
@@ -811,6 +817,21 @@ namespace PowerLauncher.ViewModel
GC.SuppressFinalize(this);
}
public void StartHotkeyTimer()
{
hotkeyTimer.Start();
}
public long GetHotkeyEventTimeMs()
{
hotkeyTimer.Stop();
long recordedTime = hotkeyTimer.ElapsedMilliseconds;
// Reset the stopwatch and return the time elapsed
hotkeyTimer.Reset();
return recordedTime;
}
#endregion
}
}