mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-23 19:49:17 +08:00
[Telemetry]Re-add preview handlers telemetry logs and add tracers (#35597)
This commit is contained in:
parent
64845b7fd8
commit
515f2386d9
@ -26,7 +26,7 @@ namespace Microsoft.PowerToys.Telemetry
|
|||||||
|
|
||||||
private readonly bool telemetryEnabled = DataDiagnosticsSettings.GetEnabledValue(); // This is the global telemetry setting on whether to log events
|
private readonly bool telemetryEnabled = DataDiagnosticsSettings.GetEnabledValue(); // This is the global telemetry setting on whether to log events
|
||||||
private readonly bool telemetryRecordingEnabled = DataDiagnosticsSettings.GetViewEnabledValue(); // This is the setting for recording telemetry events to disk for viewing
|
private readonly bool telemetryRecordingEnabled = DataDiagnosticsSettings.GetViewEnabledValue(); // This is the setting for recording telemetry events to disk for viewing
|
||||||
private readonly string etwFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\", "etw");
|
private string etwFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\", "etw");
|
||||||
private bool disposedValue;
|
private bool disposedValue;
|
||||||
private string sessionName;
|
private string sessionName;
|
||||||
private string etwFilePath;
|
private string etwFilePath;
|
||||||
@ -49,6 +49,18 @@ namespace Microsoft.PowerToys.Telemetry
|
|||||||
/// Initializes a new instance of the <see cref="ETWTrace"/> class.
|
/// Initializes a new instance of the <see cref="ETWTrace"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ETWTrace()
|
public ETWTrace()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ETWTrace(string etwPath)
|
||||||
|
{
|
||||||
|
this.etwFolderPath = etwPath;
|
||||||
|
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init()
|
||||||
{
|
{
|
||||||
if (File.Exists(etwFolderPath))
|
if (File.Exists(etwFolderPath))
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
using Common;
|
using Common;
|
||||||
using Microsoft.PowerToys.FilePreviewCommon;
|
using Microsoft.PowerToys.FilePreviewCommon;
|
||||||
|
using Microsoft.PowerToys.PreviewHandler.Gcode.Telemetry.Events;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
||||||
{
|
{
|
||||||
@ -84,6 +86,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
|
|
||||||
Resize += FormResized;
|
Resize += FormResized;
|
||||||
base.DoPreview(fs);
|
base.DoPreview(fs);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -153,6 +162,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
/// <param name="dataSource">Stream reference to access source file.</param>
|
/// <param name="dataSource">Stream reference to access source file.</param>
|
||||||
private void PreviewError<T>(Exception exception, T dataSource)
|
private void PreviewError<T>(Exception exception, T dataSource)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewError { Message = exception.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
|
|
||||||
Controls.Clear();
|
Controls.Clear();
|
||||||
_infoBarAdded = true;
|
_infoBarAdded = true;
|
||||||
AddTextBoxControl(Properties.Resource.GcodeNotPreviewedError);
|
AddTextBoxControl(Properties.Resource.GcodeNotPreviewedError);
|
||||||
|
@ -6,6 +6,7 @@ using System.Globalization;
|
|||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using PowerToys.Interop;
|
using PowerToys.Interop;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
||||||
@ -27,6 +28,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
{
|
{
|
||||||
if (args.Length == 6)
|
if (args.Length == 6)
|
||||||
{
|
{
|
||||||
|
ETWTrace etwTrace = new ETWTrace(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"));
|
||||||
|
|
||||||
string filePath = args[0];
|
string filePath = args[0];
|
||||||
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
@ -52,12 +55,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
Rectangle s = default;
|
Rectangle s = default;
|
||||||
if (!_previewHandlerControl.SetRect(s))
|
if (!_previewHandlerControl.SetRect(s))
|
||||||
{
|
{
|
||||||
|
etwTrace?.Dispose();
|
||||||
|
|
||||||
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Dispatcher.CurrentDispatcher,
|
Dispatcher.CurrentDispatcher,
|
||||||
_tokenSource.Token);
|
_tokenSource.Token);
|
||||||
|
|
||||||
|
etwTrace?.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Gcode.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when a svg file has been viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class GcodeFileHandlerLoaded : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Gcode.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when an error has occurred in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class GcodeFilePreviewError : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error message to log as part of the telemetry event.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Gcode.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when a svg file has been viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class GcodeFilePreviewed : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
using Common;
|
using Common;
|
||||||
using Microsoft.PowerToys.PreviewHandler.Markdown.Properties;
|
using Microsoft.PowerToys.PreviewHandler.Markdown.Properties;
|
||||||
|
using Microsoft.PowerToys.PreviewHandler.Markdown.Telemetry.Events;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.Web.WebView2.Core;
|
using Microsoft.Web.WebView2.Core;
|
||||||
using Microsoft.Web.WebView2.WinForms;
|
using Microsoft.Web.WebView2.WinForms;
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
@ -215,9 +217,25 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = ex.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
|
|
||||||
Controls.Clear();
|
Controls.Clear();
|
||||||
_infoBarDisplayed = true;
|
_infoBarDisplayed = true;
|
||||||
_infoBar = GetTextBoxControl(Resources.MarkdownNotPreviewedError);
|
_infoBar = GetTextBoxControl(Resources.MarkdownNotPreviewedError);
|
||||||
|
@ -6,6 +6,7 @@ using System.Globalization;
|
|||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using PowerToys.Interop;
|
using PowerToys.Interop;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
||||||
@ -27,6 +28,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
|||||||
{
|
{
|
||||||
if (args.Length == 6)
|
if (args.Length == 6)
|
||||||
{
|
{
|
||||||
|
ETWTrace etwTrace = new ETWTrace(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"));
|
||||||
|
|
||||||
string filePath = args[0];
|
string filePath = args[0];
|
||||||
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
@ -52,12 +55,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
|||||||
Rectangle s = default;
|
Rectangle s = default;
|
||||||
if (!_previewHandlerControl.SetRect(s))
|
if (!_previewHandlerControl.SetRect(s))
|
||||||
{
|
{
|
||||||
|
etwTrace?.Dispose();
|
||||||
|
|
||||||
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Dispatcher.CurrentDispatcher,
|
Dispatcher.CurrentDispatcher,
|
||||||
_tokenSource.Token);
|
_tokenSource.Token);
|
||||||
|
|
||||||
|
etwTrace?.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Markdown.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when a markdown file is viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class MarkdownFileHandlerLoaded : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.PreviewHandler.Markdown.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when an error occurs while attempting to view a markdown file in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
public class MarkdownFilePreviewError : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Markdown.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when a markdown file is viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class MarkdownFilePreviewed : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,17 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Common;
|
using Common;
|
||||||
|
using Common.Utilities;
|
||||||
using Microsoft.PowerToys.PreviewHandler.Pdf.Properties;
|
using Microsoft.PowerToys.PreviewHandler.Pdf.Properties;
|
||||||
|
using Microsoft.PowerToys.PreviewHandler.Pdf.Telemetry.Events;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Windows.Data.Pdf;
|
using Windows.Data.Pdf;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
using Windows.UI.ViewManagement;
|
using Windows.UI.ViewManagement;
|
||||||
@ -149,9 +158,25 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
|||||||
memStream.Dispose();
|
memStream.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewed());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewError { Message = ex.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
|
|
||||||
Controls.Clear();
|
Controls.Clear();
|
||||||
_infoBar = GetTextBoxControl(Resources.PdfNotPreviewedError);
|
_infoBar = GetTextBoxControl(Resources.PdfNotPreviewedError);
|
||||||
Controls.Add(_infoBar);
|
Controls.Add(_infoBar);
|
||||||
|
@ -5,6 +5,7 @@ using System.Globalization;
|
|||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using PowerToys.Interop;
|
using PowerToys.Interop;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||||
@ -26,6 +27,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
|||||||
{
|
{
|
||||||
if (args.Length == 6)
|
if (args.Length == 6)
|
||||||
{
|
{
|
||||||
|
ETWTrace etwTrace = new ETWTrace(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"));
|
||||||
|
|
||||||
string filePath = args[0];
|
string filePath = args[0];
|
||||||
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
@ -51,12 +54,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
|||||||
Rectangle s = default;
|
Rectangle s = default;
|
||||||
if (!_previewHandlerControl.SetRect(s))
|
if (!_previewHandlerControl.SetRect(s))
|
||||||
{
|
{
|
||||||
|
etwTrace?.Dispose();
|
||||||
|
|
||||||
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Dispatcher.CurrentDispatcher,
|
Dispatcher.CurrentDispatcher,
|
||||||
_tokenSource.Token);
|
_tokenSource.Token);
|
||||||
|
|
||||||
|
etwTrace?.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Pdf.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when a pdf file is viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class PdfFileHandlerLoaded : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.PreviewHandler.Pdf.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when an error occurs while attempting to view a markdown file in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
public class PdfFilePreviewError : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Pdf.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event that is triggered when a markdown file is viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class PdfFilePreviewed : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using System.Globalization;
|
|||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using PowerToys.Interop;
|
using PowerToys.Interop;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
||||||
@ -27,6 +28,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
|||||||
{
|
{
|
||||||
if (args.Length == 6)
|
if (args.Length == 6)
|
||||||
{
|
{
|
||||||
|
ETWTrace etwTrace = new ETWTrace(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"));
|
||||||
|
|
||||||
string filePath = args[0];
|
string filePath = args[0];
|
||||||
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
@ -52,12 +55,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
|||||||
Rectangle s = default;
|
Rectangle s = default;
|
||||||
if (!_previewHandlerControl.SetRect(s))
|
if (!_previewHandlerControl.SetRect(s))
|
||||||
{
|
{
|
||||||
|
etwTrace?.Dispose();
|
||||||
|
|
||||||
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Dispatcher.CurrentDispatcher,
|
Dispatcher.CurrentDispatcher,
|
||||||
_tokenSource.Token);
|
_tokenSource.Token);
|
||||||
|
|
||||||
|
etwTrace?.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
using Common;
|
using Common;
|
||||||
using Microsoft.PowerToys.FilePreviewCommon;
|
using Microsoft.PowerToys.FilePreviewCommon;
|
||||||
|
using Microsoft.PowerToys.PreviewHandler.Qoi.Telemetry.Events;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
||||||
{
|
{
|
||||||
@ -71,6 +73,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
|||||||
|
|
||||||
Resize += FormResized;
|
Resize += FormResized;
|
||||||
base.DoPreview(fs);
|
base.DoPreview(fs);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new QoiFilePreviewed());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -140,6 +149,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Qoi
|
|||||||
/// <param name="dataSource">Stream reference to access source file.</param>
|
/// <param name="dataSource">Stream reference to access source file.</param>
|
||||||
private void PreviewError<T>(Exception exception, T dataSource)
|
private void PreviewError<T>(Exception exception, T dataSource)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new QoiFilePreviewError { Message = exception.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
|
|
||||||
Controls.Clear();
|
Controls.Clear();
|
||||||
_infoBarAdded = true;
|
_infoBarAdded = true;
|
||||||
AddTextBoxControl(Properties.Resource.QoiNotPreviewedError);
|
AddTextBoxControl(Properties.Resource.QoiNotPreviewedError);
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Qoi.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when an error has occurred in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class QoiFilePreviewError : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error message to log as part of the telemetry event.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Qoi.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when a Qoi file has been viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class QoiFilePreviewed : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using System.Globalization;
|
|||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using PowerToys.Interop;
|
using PowerToys.Interop;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.PreviewHandler.Svg
|
namespace Microsoft.PowerToys.PreviewHandler.Svg
|
||||||
@ -27,6 +28,8 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
{
|
{
|
||||||
if (args.Length == 6)
|
if (args.Length == 6)
|
||||||
{
|
{
|
||||||
|
ETWTrace etwTrace = new ETWTrace(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw"));
|
||||||
|
|
||||||
string filePath = args[0];
|
string filePath = args[0];
|
||||||
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
@ -52,12 +55,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
Rectangle s = default;
|
Rectangle s = default;
|
||||||
if (!_previewHandlerControl.SetRect(s))
|
if (!_previewHandlerControl.SetRect(s))
|
||||||
{
|
{
|
||||||
|
etwTrace?.Dispose();
|
||||||
|
|
||||||
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Dispatcher.CurrentDispatcher,
|
Dispatcher.CurrentDispatcher,
|
||||||
_tokenSource.Token);
|
_tokenSource.Token);
|
||||||
|
|
||||||
|
etwTrace?.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
using Common;
|
using Common;
|
||||||
using Common.Utilities;
|
using Common.Utilities;
|
||||||
|
using Microsoft.PowerToys.PreviewHandler.Svg.Telemetry.Events;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.Web.WebView2.Core;
|
using Microsoft.Web.WebView2.Core;
|
||||||
using Microsoft.Web.WebView2.WinForms;
|
using Microsoft.Web.WebView2.WinForms;
|
||||||
using SvgPreviewHandler;
|
using SvgPreviewHandler;
|
||||||
@ -139,8 +142,15 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
|
svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
|
||||||
svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
|
svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = ex.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -157,6 +167,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
AddWebViewControl(svgData);
|
AddWebViewControl(svgData);
|
||||||
Resize += FormResized;
|
Resize += FormResized;
|
||||||
base.DoPreview(dataSource);
|
base.DoPreview(dataSource);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewed());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -284,6 +301,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
/// <param name="dataSource">Stream reference to access source file.</param>
|
/// <param name="dataSource">Stream reference to access source file.</param>
|
||||||
private void PreviewError<T>(Exception exception, T dataSource)
|
private void PreviewError<T>(Exception exception, T dataSource)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = exception.Message });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // Should not crash if sending telemetry is failing. Ignore the exception.
|
||||||
|
}
|
||||||
|
|
||||||
Controls.Clear();
|
Controls.Clear();
|
||||||
_infoBarAdded = true;
|
_infoBarAdded = true;
|
||||||
AddTextBoxControl(Properties.Resource.SvgNotPreviewedError);
|
AddTextBoxControl(Properties.Resource.SvgNotPreviewedError);
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Svg.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when a svg file has been viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class SvgFileHandlerLoaded : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Svg.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when an error has occurred in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class SvgFilePreviewError : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the error message to log as part of the telemetry event.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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 Microsoft.PowerToys.PreviewHandler.Svg.Telemetry.Events
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A telemetry event to be raised when a svg file has been viewed in the preview pane.
|
||||||
|
/// </summary>
|
||||||
|
[EventData]
|
||||||
|
public class SvgFilePreviewed : EventBase, IEvent
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -168,6 +168,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
string etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw");
|
string etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw");
|
||||||
DeleteDiagnosticDataOlderThan28Days(etwDirPath);
|
DeleteDiagnosticDataOlderThan28Days(etwDirPath);
|
||||||
|
|
||||||
|
string localLowEtwDirPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw");
|
||||||
|
DeleteDiagnosticDataOlderThan28Days(localLowEtwDirPath);
|
||||||
|
|
||||||
InitializeLanguages();
|
InitializeLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,7 +1256,26 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
internal void ViewDiagnosticData()
|
internal void ViewDiagnosticData()
|
||||||
{
|
{
|
||||||
|
string localLowEtwDirPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "AppData", "LocalLow", "Microsoft", "PowerToys", "etw");
|
||||||
string etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw");
|
string etwDirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\etw");
|
||||||
|
|
||||||
|
string[] localLowEtlFiles = Directory.GetFiles(localLowEtwDirPath, "*.etl");
|
||||||
|
|
||||||
|
foreach (string file in localLowEtlFiles)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileName(file);
|
||||||
|
string destFile = Path.Combine(etwDirPath, fileName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Copy(file, destFile, overwrite: true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Failed to copy etl file: {fileName}. Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string tracerptPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "system32");
|
string tracerptPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "system32");
|
||||||
|
|
||||||
ETLConverter converter = new ETLConverter(etwDirPath, tracerptPath);
|
ETLConverter converter = new ETLConverter(etwDirPath, tracerptPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user