[Awake]Add telemetry (#22214)

* [Awake]Add telemetry

* fix wrong event call
This commit is contained in:
Jaime Bernardo
2022-11-21 19:24:56 +00:00
committed by GitHub
parent 994652a535
commit e160e223f0
6 changed files with 53 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.PowerToys.Telemetry;
using Microsoft.Win32; using Microsoft.Win32;
using NLog; using NLog;
using Windows.Win32; using Windows.Win32;
@@ -83,6 +84,8 @@ namespace Awake.Core
public static void SetIndefiniteKeepAwake(Action<bool> callback, Action failureCallback, bool keepDisplayOn = false) public static void SetIndefiniteKeepAwake(Action<bool> callback, Action failureCallback, bool keepDisplayOn = false)
{ {
PowerToysTelemetry.Log.WriteEvent(new Awake.Telemetry.AwakeIndefinitelyKeepAwakeEvent());
_tokenSource.Cancel(); _tokenSource.Cancel();
try try
@@ -131,6 +134,8 @@ namespace Awake.Core
public static void SetTimedKeepAwake(uint seconds, Action<bool> callback, Action failureCallback, bool keepDisplayOn = true) public static void SetTimedKeepAwake(uint seconds, Action<bool> callback, Action failureCallback, bool keepDisplayOn = true)
{ {
PowerToysTelemetry.Log.WriteEvent(new Awake.Telemetry.AwakeTimedKeepAwakeEvent());
_tokenSource.Cancel(); _tokenSource.Cancel();
try try

View File

@@ -0,0 +1,16 @@
// 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 System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Awake.Telemetry
{
[EventData]
public class AwakeIndefinitelyKeepAwakeEvent : EventBase, IEvent
{
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -0,0 +1,16 @@
// 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 System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Awake.Telemetry
{
[EventData]
public class AwakeTimedKeepAwakeEvent : EventBase, IEvent
{
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -136,6 +136,7 @@ public:
virtual void enable() virtual void enable()
{ {
Trace::EnableAwake(true);
ResetEvent(send_telemetry_event); ResetEvent(send_telemetry_event);
ResetEvent(m_hInvokeEvent); ResetEvent(m_hInvokeEvent);
launch_process(); launch_process();
@@ -146,6 +147,7 @@ public:
{ {
if (m_enabled) if (m_enabled)
{ {
Trace::EnableAwake(false);
Logger::trace(L"Disabling Awake..."); Logger::trace(L"Disabling Awake...");
ResetEvent(send_telemetry_event); ResetEvent(send_telemetry_event);
ResetEvent(m_hInvokeEvent); ResetEvent(m_hInvokeEvent);

View File

@@ -17,3 +17,14 @@ void Trace::UnregisterProvider()
{ {
TraceLoggingUnregister(g_hProvider); TraceLoggingUnregister(g_hProvider);
} }
// Log if the user has Awake enabled or disabled
void Trace::EnableAwake(const bool enabled) noexcept
{
TraceLoggingWrite(
g_hProvider,
"Awake_EnableAwake",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingBoolean(enabled, "Enabled"));
}

View File

@@ -5,4 +5,7 @@ class Trace
public: public:
static void RegisterProvider(); static void RegisterProvider();
static void UnregisterProvider(); static void UnregisterProvider();
// Log if the user has Awake enabled or disabled
static void EnableAwake(const bool enabled) noexcept;
}; };