-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(threads): Display closest lock reason as a thread tag (#50472)
- Loading branch information
Showing
4 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
static/app/components/events/interfaces/threads/threadSelector/lockReason.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Lock, LockType} from 'sentry/types'; | ||
import {defined} from 'sentry/utils'; | ||
|
||
export function getLockReason( | ||
heldLocks?: Record<string, Lock> | null | ||
): string | undefined { | ||
if (!defined(heldLocks)) { | ||
return undefined; | ||
} | ||
|
||
const values = Object.values(heldLocks); | ||
if (values.length === 0) { | ||
return undefined; | ||
} | ||
|
||
const firstLock = values[0] as Lock; | ||
if (!defined(firstLock)) { | ||
return undefined; | ||
} | ||
|
||
const address = firstLock?.address ?? 'unknown object'; | ||
const tid = firstLock?.thread_id; | ||
let reason: string | undefined; | ||
|
||
switch (firstLock.type) { | ||
case LockType.LOCKED: | ||
reason = `locked <${address}>`; | ||
break; | ||
case LockType.WAITING: | ||
reason = `waiting on <${address}>`; | ||
break; | ||
case LockType.SLEEPING: | ||
reason = `sleeping on <${address}>`; | ||
break; | ||
case LockType.BLOCKED: | ||
reason = | ||
`waiting to lock <${address}>` + (defined(tid) ? ` held by thread ${tid}` : ''); | ||
break; | ||
default: | ||
reason = undefined; | ||
} | ||
return reason; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters