|
2 | 2 | // Licensed under the BSD-Clause 2 license.
|
3 | 3 | // See license.txt file in the project root for full license information.
|
4 | 4 |
|
| 5 | +using System; |
5 | 6 | using System.Diagnostics.CodeAnalysis;
|
6 | 7 | using System.Runtime.CompilerServices;
|
7 | 8 | using System.Runtime.InteropServices;
|
@@ -30,13 +31,16 @@ internal static partial class MacOSLibSystem
|
30 | 31 |
|
31 | 32 | public const int TASK_DYLD_INFO = 17;
|
32 | 33 | public const int THREAD_IDENTIFIER_INFO = 4;
|
| 34 | + public const int THREAD_EXTENDED_INFO = 5; |
33 | 35 | public const int x86_THREAD_STATE64 = 4;
|
34 | 36 | public const int ARM_THREAD_STATE64 = 6;
|
35 | 37 | public const int VM_REGION_BASIC_INFO_64 = 9;
|
36 | 38 |
|
37 | 39 | public static readonly unsafe int TASK_DYLD_INFO_COUNT = sizeof(task_dyld_info) / sizeof(uint);
|
38 | 40 |
|
39 | 41 | 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 | + |
40 | 44 |
|
41 | 45 | public static readonly unsafe int x86_THREAD_STATE64_COUNT = sizeof(x86_thread_state64_t) / sizeof(uint);
|
42 | 46 | 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
|
64 | 68 | public static unsafe partial return_t task_resume(task_inspect_t target_task);
|
65 | 69 |
|
66 | 70 | [LibraryImport(LibSystem)]
|
| 71 | + [SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling |
67 | 72 | public static partial return_t thread_suspend(thread_act_t target_act);
|
68 | 73 |
|
69 | 74 | [LibraryImport(LibSystem)]
|
| 75 | + [SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling |
70 | 76 | public static partial return_t thread_resume(thread_act_t target_act);
|
71 | 77 |
|
72 | 78 | [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); |
74 | 81 |
|
75 | 82 | [LibraryImport(LibSystem)]
|
| 83 | + [SuppressGCTransition] // We don't want to transition to preemptive mode as we are dealing high-performance profiling |
76 | 84 | 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);
|
77 | 85 |
|
78 | 86 | [LibraryImport(LibSystem)]
|
@@ -376,6 +384,63 @@ public struct uuid_command {
|
376 | 384 | public uint reserved3; /* reserved */
|
377 | 385 | }
|
378 | 386 |
|
| 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 | + |
379 | 444 | public const uint LC_UUID = 0x1b;
|
380 | 445 | public const uint LC_SEGMENT_64 = 0x19;
|
381 | 446 |
|
|
0 commit comments