Skip to content

Commit 030a67f

Browse files
committed
Add support for compressed frames
1 parent 0b47f48 commit 030a67f

12 files changed

+316
-101
lines changed

src/Ultra.Core/DiagnosticPortSession.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Diagnostics.Tracing;
88
using Microsoft.Diagnostics.NETCore.Client;
99
using Microsoft.Diagnostics.Tracing.Parsers;
10+
using Ultra.Sampler;
1011

1112
namespace Ultra.Core;
1213

src/Ultra.Sampler/MacOS/NativeModuleEventKind.cs src/Ultra.Core/Parser/UltraSamplerNativeModuleEventKind.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Licensed under the BSD-Clause 2 license.
33
// See license.txt file in the project root for full license information.
44

5-
namespace Ultra.Sampler.MacOS;
5+
namespace Ultra.Core;
66

7-
internal enum NativeModuleEventKind
7+
public enum UltraSamplerNativeModuleEventKind
88
{
99
AlreadyLoaded = 0,
10+
1011
Loaded = 1,
12+
1113
Unloaded = 2
1214
}

src/Ultra.Core/Parser/UltraSamplerParser.cs

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Text;
66
using Microsoft.Diagnostics.Tracing;
7+
using Ultra.Sampler;
78

89
namespace Ultra.Core;
910

@@ -142,7 +143,7 @@ internal UltraNativeModuleTraceEvent(Action<UltraNativeModuleTraceEvent>? target
142143
_target = target;
143144
}
144145

145-
public UltraNativeModuleEventKind NativeModuleEventKind => (UltraNativeModuleEventKind)GetInt32At(0);
146+
public UltraSamplerNativeModuleEventKind NativeModuleEventKind => (UltraSamplerNativeModuleEventKind)GetInt32At(0);
146147

147148
public ulong LoadAddress => (ulong)GetInt64At(4);
148149

@@ -198,13 +199,4 @@ protected override void Dispatch()
198199
protected override void Validate()
199200
{
200201
}
201-
}
202-
203-
public enum UltraNativeModuleEventKind
204-
{
205-
AlreadyLoaded = 0,
206-
207-
Loaded = 1,
208-
209-
Unloaded = 2
210-
}
202+
}

src/Ultra.Sampler/MacOS/MacOSLibSystem.cs

+66-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the BSD-Clause 2 license.
33
// See license.txt file in the project root for full license information.
44

5+
using System;
56
using System.Diagnostics.CodeAnalysis;
67
using System.Runtime.CompilerServices;
78
using System.Runtime.InteropServices;
@@ -30,13 +31,16 @@ internal static partial class MacOSLibSystem
3031

3132
public const int TASK_DYLD_INFO = 17;
3233
public const int THREAD_IDENTIFIER_INFO = 4;
34+
public const int THREAD_EXTENDED_INFO = 5;
3335
public const int x86_THREAD_STATE64 = 4;
3436
public const int ARM_THREAD_STATE64 = 6;
3537
public const int VM_REGION_BASIC_INFO_64 = 9;
3638

3739
public static readonly unsafe int TASK_DYLD_INFO_COUNT = sizeof(task_dyld_info) / sizeof(uint);
3840

3941
public static readonly unsafe int THREAD_IDENTIFIER_INFO_COUNT = sizeof(thread_identifier_info) / sizeof(uint);
42+
public static readonly unsafe int THREAD_EXTENDED_INFO_COUNT = sizeof(thread_extended_info) / sizeof(uint);
43+
4044

4145
public static readonly unsafe int x86_THREAD_STATE64_COUNT = sizeof(x86_thread_state64_t) / sizeof(uint);
4246
public static readonly unsafe int ARM_THREAD_STATE64_COUNT = sizeof(arm_thread_state64_t) / sizeof(uint);
@@ -64,15 +68,19 @@ internal static partial class MacOSLibSystem
6468
public static unsafe partial return_t task_resume(task_inspect_t target_task);
6569

6670
[LibraryImport(LibSystem)]
71+
[SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling
6772
public static partial return_t thread_suspend(thread_act_t target_act);
6873

6974
[LibraryImport(LibSystem)]
75+
[SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling
7076
public static partial return_t thread_resume(thread_act_t target_act);
7177

7278
[LibraryImport(LibSystem)]
73-
public static partial return_t thread_info(thread_act_t target_act, uint flavor, out /*int*/thread_identifier_info thread_info, ref /*uint*/int thread_info_count);
79+
[SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling
80+
public static unsafe partial return_t thread_info(thread_act_t target_act, uint flavor, void* thread_info, ref /*uint*/int thread_info_count);
7481

7582
[LibraryImport(LibSystem)]
83+
[SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling
7684
public static partial return_t thread_get_state(thread_inspect_t target_act, uint flavor, /*uint**/nint old_state, ref /*uint*/int old_state_count);
7785

7886
[LibraryImport(LibSystem)]
@@ -376,6 +384,63 @@ public struct uuid_command {
376384
public uint reserved3; /* reserved */
377385
}
378386

387+
public const int THREAD_BASIC_INFO = 3;
388+
389+
public struct thread_basic_info_data_t
390+
{
391+
public uint user_time;
392+
public uint system_time;
393+
public int cpu_usage;
394+
public int policy;
395+
public TH_STATE run_state;
396+
public TH_FLAGS flags;
397+
public int suspend_count;
398+
public int sleep_time;
399+
}
400+
401+
public unsafe struct thread_extended_info
402+
{ // same as proc_threadinfo (from proc_info.h) & proc_threadinfo_internal (from bsd_taskinfo.h)
403+
public ulong pth_user_time; /* user run time */
404+
public ulong pth_system_time; /* system run time */
405+
public int pth_cpu_usage; /* scaled cpu usage percentage */
406+
public int pth_policy; /* scheduling policy in effect */
407+
public TH_STATE pth_run_state; /* run state (see below) */
408+
public TH_FLAGS pth_flags; /* various flags (see below) */
409+
public int pth_sleep_time; /* number of seconds that thread */
410+
public int pth_curpri; /* cur priority*/
411+
public int pth_priority; /* priority*/
412+
public int pth_maxpriority; /* max priority*/
413+
public fixed byte pth_name[64]; /* thread name, if any */
414+
};
415+
public enum TH_STATE
416+
{
417+
TH_STATE_RUNNING = 1, /* thread is running normally */
418+
TH_STATE_STOPPED = 2, /* thread is stopped */
419+
TH_STATE_WAITING = 3, /* thread is waiting normally */
420+
TH_STATE_UNINTERRUPTIBLE = 4, /* thread is in an uninterruptible wait */
421+
TH_STATE_HALTED = 5 /* thread is halted at a clean point */
422+
}
423+
424+
public const TH_STATE TH_STATE_RUNNING = TH_STATE.TH_STATE_RUNNING;
425+
public const TH_STATE TH_STATE_STOPPED = TH_STATE.TH_STATE_STOPPED;
426+
public const TH_STATE TH_STATE_WAITING = TH_STATE.TH_STATE_WAITING;
427+
public const TH_STATE TH_STATE_UNINTERRUPTIBLE = TH_STATE.TH_STATE_UNINTERRUPTIBLE;
428+
public const TH_STATE TH_STATE_HALTED = TH_STATE.TH_STATE_HALTED;
429+
430+
public const int TH_USAGE_SCALE = 1000; // Scale factor for usage values
431+
432+
[Flags]
433+
public enum TH_FLAGS
434+
{
435+
TH_FLAGS_SWAPPED = 0x1, /* thread is swapped out */
436+
TH_FLAGS_IDLE = 0x2, /* thread is an idle thread */
437+
TH_FLAGS_GLOBAL_FORCED_IDLE = 0x4 /* thread performs global forced idle */
438+
}
439+
440+
public const TH_FLAGS TH_FLAGS_SWAPPED = TH_FLAGS.TH_FLAGS_SWAPPED;
441+
public const TH_FLAGS TH_FLAGS_IDLE = TH_FLAGS.TH_FLAGS_IDLE;
442+
public const TH_FLAGS TH_FLAGS_GLOBAL_FORCED_IDLE = TH_FLAGS.TH_FLAGS_GLOBAL_FORCED_IDLE;
443+
379444
public const uint LC_UUID = 0x1b;
380445
public const uint LC_SEGMENT_64 = 0x19;
381446

0 commit comments

Comments
 (0)