Skip to content

Commit

Permalink
Don't hide sample showing tabs for allocation profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
krsh732 committed Feb 9, 2023
1 parent b69a16c commit 6e18590
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
13 changes: 9 additions & 4 deletions src/components/shared/StackSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type StateProps = {|
+invertCallstack: boolean,
+showUserTimings: boolean,
+currentSearchString: string,
+hasSamples: boolean,
+hasJsAllocations: boolean,
+hasNativeAllocations: boolean,
+canShowRetainedMemory: boolean,
Expand Down Expand Up @@ -135,6 +136,7 @@ class StackSettingsImpl extends PureComponent<Props> {
showUserTimings,
hideInvertCallstack,
currentSearchString,
hasSamples,
hasJsAllocations,
hasNativeAllocations,
canShowRetainedMemory,
Expand Down Expand Up @@ -172,10 +174,12 @@ class StackSettingsImpl extends PureComponent<Props> {
onChange={this._onCallTreeSummaryStrategyChange}
value={callTreeSummaryStrategy}
>
{this._renderCallTreeStrategyOption(
'StackSettings--call-tree-strategy-timing',
'timing'
)}
{hasSamples
? this._renderCallTreeStrategyOption(
'StackSettings--call-tree-strategy-timing',
'timing'
)
: null}
{hasJsAllocations
? this._renderCallTreeStrategyOption(
'StackSettings--call-tree-strategy-js-allocations',
Expand Down Expand Up @@ -272,6 +276,7 @@ export const StackSettings = explicitConnect<
showUserTimings: getShowUserTimings(state),
implementationFilter: getImplementationFilter(state),
currentSearchString: getCurrentSearchString(state),
hasSamples: selectedThreadSelectors.getHasSamples(state),
hasJsAllocations: selectedThreadSelectors.getHasJsAllocations(state),
hasNativeAllocations:
selectedThreadSelectors.getHasNativeAllocations(state),
Expand Down
51 changes: 29 additions & 22 deletions src/selectors/per-thread/composed.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ export function getComposedSelectorsPerThread(
threadSelectors.getIsNetworkChartEmptyInFullRange,
threadSelectors.getJsTracerTable,
(thread, isNetworkChartEmpty, jsTracerTable) => {
const {
processType,
samples,
stackTable,
stringTable,
frameTable,
funcTable,
} = thread;
const { processType, stackTable, stringTable, frameTable, funcTable } =
thread;
if (processType === 'comparison') {
// For a diffing tracks, we display only the calltree tab for now, because
// other views make no or not much sense.
Expand All @@ -87,30 +81,43 @@ export function getComposedSelectorsPerThread(
(tabSlug) => tabSlug !== 'network-chart'
);
}

if (!jsTracerTable) {
visibleTabs = visibleTabs.filter((tabSlug) => tabSlug !== 'js-tracer');
}
let hasSamples = samples.length > 0 && stackTable.length > 0;
if (hasSamples) {
const stackIndex = ensureExists(samples.stack[0]);
if (stackTable.prefix[stackIndex] === null) {
// There's only a single stack frame, check if it's '(root)'.
const frameIndex = stackTable.frame[stackIndex];
const funcIndex = frameTable.func[frameIndex];
const stringIndex = funcTable.name[funcIndex];
if (stringTable.getString(stringIndex) === '(root)') {
// If the first sample's stack is only the root, check if any other
// sample is different.
hasSamples = samples.stack.some((s) => s !== stackIndex);

const {
samples: timingSamples,
jsAllocations,
nativeAllocations,
} = thread;
const hasSamples =
stackTable.length > 0 &&
[timingSamples, jsAllocations, nativeAllocations].some((samples) => {
if (samples === undefined || samples.length === 0) {
return false;
}
}
}
const stackIndex = ensureExists(samples.stack[0]);
if (stackTable.prefix[stackIndex] === null) {
// There's only a single stack frame, check if it's '(root)'.
const frameIndex = stackTable.frame[stackIndex];
const funcIndex = frameTable.func[frameIndex];
const stringIndex = funcTable.name[funcIndex];
if (stringTable.getString(stringIndex) === '(root)') {
// If the first sample's stack is only the root, check if any other
// sample is different.
return samples.stack.some((s) => s !== stackIndex);
}
}
return true;
});

if (!hasSamples) {
visibleTabs = visibleTabs.filter(
(tabSlug) => !tabsShowingSampleData.includes(tabSlug)
);
}

return visibleTabs;
}
);
Expand Down
5 changes: 5 additions & 0 deletions src/selectors/per-thread/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ export function getThreadSelectorsPerThread(
ProfileSelectors.getProfileViewOptions(state).perThread[threadsKey] ||
defaultThreadViewOptions;

/** Check to see if there are any timing samples for this thread. */
const getHasSamples: Selector<boolean> = (state) =>
Boolean(getThread(state).samples.length);

/**
* Check to see if there are any JS allocations for this thread. This way we
* can display a custom thread.
Expand Down Expand Up @@ -488,6 +492,7 @@ export function getThreadSelectorsPerThread(
getJsTracerTable,
getExpensiveJsTracerTiming,
getExpensiveJsTracerLeafTiming,
getHasSamples,
getHasJsAllocations,
getHasNativeAllocations,
getCanShowRetainedMemory,
Expand Down

0 comments on commit 6e18590

Please sign in to comment.