threadStates.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {t} from 'sentry/locale';
  2. import {defined} from 'sentry/utils';
  3. export enum ThreadStates {
  4. RUNNABLE = 'Runnable',
  5. TIMED_WAITING = 'Timed waiting',
  6. BLOCKED = 'Blocked',
  7. WAITING = 'Waiting',
  8. NEW = 'New',
  9. TERMINATED = 'Terminated',
  10. }
  11. type ThreadStatesMap = Record<string, ThreadStates>;
  12. export const javaThreadStatesMap: ThreadStatesMap = {
  13. RUNNABLE: ThreadStates.RUNNABLE,
  14. TIMED_WAITING: ThreadStates.TIMED_WAITING,
  15. BLOCKED: ThreadStates.BLOCKED,
  16. WAITING: ThreadStates.WAITING,
  17. NEW: ThreadStates.NEW,
  18. TERMINATED: ThreadStates.TERMINATED,
  19. // Android VM thread states https://cs.android.com/android/platform/superproject/+/master:art/runtime/thread_state.h
  20. kTerminated: ThreadStates.TERMINATED, // Thread.run has returned, but Thread* still around
  21. kRunnable: ThreadStates.RUNNABLE, // runnable
  22. kTimedWaiting: ThreadStates.TIMED_WAITING, // in Object.wait() with a timeout
  23. kSleeping: ThreadStates.TIMED_WAITING, // in Thread.sleep()
  24. kBlocked: ThreadStates.BLOCKED, // blocked on a monitor
  25. kWaiting: ThreadStates.WAITING, // in Object.wait()
  26. kWaitingForLockInflation: ThreadStates.WAITING, // blocked inflating a thin-lock
  27. kWaitingForTaskProcessor: ThreadStates.WAITING, // blocked waiting for taskProcessor
  28. kWaitingForGcToComplete: ThreadStates.WAITING, // blocked waiting for GC
  29. kWaitingForCheckPointsToRun: ThreadStates.WAITING, // GC waiting for checkpoints to run
  30. kWaitingPerformingGc: ThreadStates.WAITING, // performing GC
  31. kWaitingForDebuggerSend: ThreadStates.WAITING, // blocked waiting for events to be sent
  32. kWaitingForDebuggerToAttach: ThreadStates.WAITING, // blocked waiting for debugger to attach
  33. kWaitingInMainDebuggerLoop: ThreadStates.WAITING, // blocking/reading/processing debugger events
  34. kWaitingForDebuggerSuspension: ThreadStates.WAITING, // waiting for debugger suspend all
  35. kWaitingForJniOnLoad: ThreadStates.WAITING, // waiting for execution of dlopen and JNI on load code
  36. kWaitingForSignalCatcherOutput: ThreadStates.WAITING, // waiting for signal catcher IO to complete
  37. kWaitingInMainSignalCatcherLoop: ThreadStates.WAITING, // blocking/reading/processing signals
  38. kWaitingForDeoptimization: ThreadStates.WAITING, // waiting for deoptimization suspend all
  39. kWaitingForMethodTracingStart: ThreadStates.WAITING, // waiting for method tracing to start
  40. kWaitingForVisitObjects: ThreadStates.WAITING, // waiting for visiting objects
  41. kWaitingForGetObjectsAllocated: ThreadStates.WAITING, // waiting for getting the number of allocated objects
  42. kWaitingWeakGcRootRead: ThreadStates.WAITING, // waiting on the GC to read a weak root
  43. kWaitingForGcThreadFlip: ThreadStates.WAITING, // waiting on the GC thread flip (CC collector) to finish
  44. kNativeForAbort: ThreadStates.WAITING, // checking other threads are not run on abort.
  45. kStarting: ThreadStates.NEW, // native thread started, not yet ready to run managed code
  46. kNative: ThreadStates.RUNNABLE, // running in a JNI native method
  47. kSuspended: ThreadStates.RUNNABLE, // suspended by GC or debugger
  48. };
  49. export const THREAD_STATE_TERMS: Record<ThreadStates, string> = {
  50. [ThreadStates.RUNNABLE]: t(
  51. 'A thread executing in the Java virtual machine is in this state.'
  52. ),
  53. [ThreadStates.WAITING]: t(
  54. 'A thread that is waiting indefinitely for another thread to perform a particular action is in this state.'
  55. ),
  56. [ThreadStates.TIMED_WAITING]: t(
  57. 'A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.'
  58. ),
  59. [ThreadStates.BLOCKED]: t(
  60. 'A thread that is blocked waiting for a monitor lock is in this state.'
  61. ),
  62. [ThreadStates.NEW]: t('A thread that has not yet started is in this state.'),
  63. [ThreadStates.TERMINATED]: t('A thread that has exited is in this state.'),
  64. };
  65. export function getThreadStateHelpText(state: keyof typeof THREAD_STATE_TERMS): string {
  66. if (!THREAD_STATE_TERMS.hasOwnProperty(state)) {
  67. return '';
  68. }
  69. return THREAD_STATE_TERMS[state];
  70. }
  71. export function getMappedThreadState(
  72. state: string | undefined | null
  73. ): ThreadStates | undefined {
  74. if (defined(state)) {
  75. return javaThreadStatesMap[state];
  76. }
  77. return undefined;
  78. }