|
7 | 7 | using System.Runtime.InteropServices;
|
8 | 8 | using System.Text.Json;
|
9 | 9 | using ByteSizeLib;
|
10 |
| -using Microsoft.Diagnostics.Tracing.Session; |
11 | 10 |
|
12 | 11 | namespace Ultra.Core;
|
13 | 12 |
|
@@ -87,14 +86,21 @@ public void Dispose()
|
87 | 86 | }
|
88 | 87 |
|
89 | 88 | private protected abstract void DisposeImpl();
|
90 |
| - |
| 89 | + |
91 | 90 | /// <summary>
|
92 | 91 | /// Determines whether the current process is running with elevated privileges.
|
93 | 92 | /// </summary>
|
94 | 93 | /// <returns>True if the current process is running with elevated privileges; otherwise, false.</returns>
|
95 | 94 | public static bool IsElevated()
|
96 | 95 | {
|
97 |
| - var isElevated = TraceEventSession.IsElevated(); |
| 96 | + if (OperatingSystem.IsMacOS()) return true; |
| 97 | + |
| 98 | + return IsElevatedWindows(); |
| 99 | + } |
| 100 | + |
| 101 | + private static bool IsElevatedWindows() |
| 102 | + { |
| 103 | + var isElevated = Microsoft.Diagnostics.Tracing.Session.TraceEventSession.IsElevated(); |
98 | 104 | return isElevated.HasValue && isElevated.Value;
|
99 | 105 | }
|
100 | 106 |
|
@@ -155,7 +161,7 @@ public async Task<string> Run(UltraProfilerOptions ultraProfilerOptions)
|
155 | 161 | }
|
156 | 162 | else if (ultraProfilerOptions.ProgramPath != null)
|
157 | 163 | {
|
158 |
| - if (!ultraProfilerOptions.ProgramPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) |
| 164 | + if (OperatingSystem.IsWindows() && !ultraProfilerOptions.ProgramPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) |
159 | 165 | {
|
160 | 166 | throw new ArgumentException($"Executable path {ultraProfilerOptions.ProgramPath} must end with .exe");
|
161 | 167 | }
|
@@ -300,11 +306,11 @@ public async Task<string> Run(UltraProfilerOptions ultraProfilerOptions)
|
300 | 306 | }
|
301 | 307 |
|
302 | 308 | await runner.OnFinalCleanup();
|
303 |
| - |
| 309 | + |
304 | 310 | return jsonFinalFile;
|
305 | 311 | }
|
306 | 312 |
|
307 |
| - |
| 313 | + |
308 | 314 | private protected abstract ProfilerRunner CreateRunner(UltraProfilerOptions ultraProfilerOptions, List<Process> processList, string baseName, Process? singleProcess);
|
309 | 315 |
|
310 | 316 | /// <summary>
|
@@ -373,7 +379,7 @@ private async Task EnableProfiling(ProfilerRunner runner, UltraProfilerOptions u
|
373 | 379 | // Reset the clock to account for the duration of the profiler
|
374 | 380 | ProfilerClock.Restart();
|
375 | 381 | }
|
376 |
| - |
| 382 | + |
377 | 383 | private protected async Task WaitForStaleFile(string file, UltraProfilerOptions options)
|
378 | 384 | {
|
379 | 385 | var clock = Stopwatch.StartNew();
|
|
0 commit comments