Skip to content

Commit 79c646d

Browse files
authored
profiling: trigger fallback to main tid (#87220)
Fallback to main tid if the tid we receive as query param points to a non existent profile
1 parent f1e5f35 commit 79c646d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

static/app/components/profiling/flamegraph/flamegraphToolbar/flamegraphThreadSelector.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {useCallback, useMemo} from 'react';
22
import styled from '@emotion/styled';
3+
import * as Sentry from '@sentry/react';
34

45
import type {SelectOption} from 'sentry/components/compactSelect';
56
import {CompactSelect} from 'sentry/components/compactSelect';
@@ -29,10 +30,32 @@ function FlamegraphThreadSelector({
2930
] = useMemo(() => {
3031
const profiles: Array<SelectOption<number>> = [];
3132
const emptyProfiles: Array<SelectOption<number>> = [];
33+
3234
const activeThreadId =
3335
typeof profileGroup.activeProfileIndex === 'number'
3436
? profileGroup.profiles[profileGroup.activeProfileIndex]?.threadId
3537
: undefined;
38+
39+
// Sanity check and redirect to the correct thread id if the tid that was set
40+
// is not present in the profile group and/or points to a non existing thread.
41+
if (profileGroup.profiles.length > 0 && typeof threadId === 'number') {
42+
const profileWithThreadId = profileGroup.profiles.find(
43+
profile => profile.threadId === threadId
44+
);
45+
46+
if (!profileWithThreadId) {
47+
const fallbackThreadId =
48+
profileGroup.profiles[profileGroup.activeProfileIndex]?.threadId ?? 0;
49+
50+
if (fallbackThreadId !== threadId) {
51+
onThreadIdChange(fallbackThreadId);
52+
Sentry.captureMessage(
53+
`Thread id ${threadId} not found in profile group, redirecting to ${fallbackThreadId}`
54+
);
55+
}
56+
}
57+
}
58+
3659
const sortedProfiles = [...profileGroup.profiles].sort(
3760
compareProfiles(activeThreadId)
3861
);
@@ -60,7 +83,7 @@ function FlamegraphThreadSelector({
6083
});
6184

6285
return [profiles, emptyProfiles];
63-
}, [profileGroup]);
86+
}, [profileGroup, threadId, onThreadIdChange]);
6487

6588
const handleChange: (opt: SelectOption<any>) => void = useCallback(
6689
opt => {

0 commit comments

Comments
 (0)