mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[General]Add an option for telemetry opt-in and visualization(#34078)
* Data diagnostics opt-in
* [c++] Drop DROP_PII flag
* Bump telemtry package to 2.0.2
* Drop DropPii from custom actions
* Cleanup
* Do not start manually C# EtwTrace. FZ engine exit event.
* ImageResizer, PowerRename, FileLocksmith prev handlers
* Revert C# handlers exe logging
* Revert "Revert C# handlers exe logging"
This reverts commit 4c75a3953b.
* Do not recreate EtwTrace
* consume package
* xaml formatting
* Fix deps.json audit
* Update telem package paths
* Address PR comments
* Fix AdvancedPaste close on PT close
* Override etl file name for explorer loaded dlls
Start/stop tracer when needed for explorer loaded dlls to prevent explorer overload
* Fix setting desc
* Fix missing events
* Add infobar to restart when enable data viewing
* Flush on timer every 30s
* [Settings] Update View Data diagnostic description text
[New+] Add tracer
* Show Restart info bar for both enable/disable data viewer
* Fix newplus
* Fix stuck on restart and terminate AdvPaste exe on destroy()
* [Installer] Add tracer
* Address PR comment
* Add missing tracers
* Exclude etw dir from BugReport
* Fix bad merge
* [Hosts] Proper exit on initial dialog
* [OOBE] Make Data diagnostic setting visible without scroll
* [OOBE] Add hiperlynk to open general settings
* Disable data view on disabling data diagnostics
* Don't disable View data button
* Fix disabling data viewing
* Add missing dot
* Revert formatting
This commit is contained in:
102
src/settings-ui/Settings.UI/Helpers/ETLConverter.cs
Normal file
102
src/settings-ui/Settings.UI/Helpers/ETLConverter.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
public class ETLConverter
|
||||
{
|
||||
private const int TracerptConversionTimeout = 60000; // 60 seconds in milliseconds
|
||||
private const string ETLConversionOutputFormat = "xml"; // Assuming XML output format
|
||||
|
||||
private readonly string etwDirPath;
|
||||
|
||||
private readonly string tracerptPath;
|
||||
|
||||
public ETLConverter(string etwDirPath, string tracerptPath)
|
||||
{
|
||||
this.etwDirPath = etwDirPath;
|
||||
this.tracerptPath = tracerptPath;
|
||||
}
|
||||
|
||||
private bool ETLConversionsFailed { get; set; }
|
||||
|
||||
public async Task ConvertDiagnosticsETLsAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var etlConversionTasks = new List<Task>();
|
||||
var directoryInfo = new DirectoryInfo(etwDirPath);
|
||||
|
||||
foreach (var fileInfo in directoryInfo.GetFiles("*.etl", SearchOption.AllDirectories))
|
||||
{
|
||||
var task = Task.Run(() => ConvertETLAsync(fileInfo.FullName, cancellationToken), cancellationToken);
|
||||
etlConversionTasks.Add(task);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(etlConversionTasks);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
ETLConversionsFailed = true;
|
||||
}
|
||||
|
||||
if (ETLConversionsFailed)
|
||||
{
|
||||
throw new InvalidOperationException("One or more ETL conversions failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ConvertETLAsync(string etlFilePathToConvert, CancellationToken cancellationToken)
|
||||
{
|
||||
var outputFilePath = Path.ChangeExtension(etlFilePathToConvert, $".{ETLConversionOutputFormat}");
|
||||
|
||||
if (File.Exists(outputFilePath))
|
||||
{
|
||||
File.Delete(outputFilePath);
|
||||
}
|
||||
|
||||
var tracerPtArguments = $"\"{etlFilePathToConvert}\" -o \"{outputFilePath}\" -lr -y -of {ETLConversionOutputFormat}";
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = tracerptPath + "\\tracerpt.exe",
|
||||
Arguments = tracerPtArguments,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
using (var process = Process.Start(startInfo))
|
||||
{
|
||||
if (process == null)
|
||||
{
|
||||
Logger.LogError("Failed to start tracerpt process.");
|
||||
}
|
||||
|
||||
var processExited = process.WaitForExit(TracerptConversionTimeout);
|
||||
|
||||
if (!processExited)
|
||||
{
|
||||
process.Kill();
|
||||
Logger.LogError("ETL conversion process timed out.");
|
||||
}
|
||||
|
||||
var exitCode = process.ExitCode;
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Logger.LogError($"ETL conversion failed with exit code {exitCode}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs
Normal file
30
src/settings-ui/Settings.UI/Helpers/NativeEventWaiter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.UI.Dispatching;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
public static class NativeEventWaiter
|
||||
{
|
||||
public static void WaitForEventLoop(string eventName, Action callback)
|
||||
{
|
||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
new Thread(() =>
|
||||
{
|
||||
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
||||
while (true)
|
||||
{
|
||||
if (eventHandle.WaitOne())
|
||||
{
|
||||
dispatcherQueue.TryEnqueue(() => callback());
|
||||
}
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
public static class StartProcessHelper
|
||||
{
|
||||
public const string ColorsSettings = "ms-settings:colors";
|
||||
public const string DiagnosticsAndFeedback = "ms-settings:privacy-feedback";
|
||||
|
||||
public static string AnimationsSettings => OSVersionHelper.IsWindows11()
|
||||
? "ms-settings:easeofaccess-visualeffects"
|
||||
|
||||
Reference in New Issue
Block a user