Skip to content

Commit 816a75e

Browse files
committed
Add isSampleWithNonEmptyStack and remove now-unused getFuncNamesAndOriginsForPath.
1 parent 15edb72 commit 816a75e

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

src/components/shared/SampleTooltipContents.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { Backtrace } from './Backtrace';
99
import { TooltipDetailSeparator } from '../tooltip/TooltipDetails';
1010
import {
1111
getCategoryPairLabel,
12-
getFuncNamesAndOriginsForPath,
13-
convertStackToCallNodeAndCategoryPath,
12+
isSampleWithNonEmptyStack,
1413
} from 'firefox-profiler/profile-logic/profile-data';
1514
import { getFormattedTimelineValue } from 'firefox-profiler/profile-logic/committed-ranges';
1615
import {
@@ -26,7 +25,6 @@ import type {
2625
Milliseconds,
2726
} from 'firefox-profiler/types';
2827
import type { CpuRatioInTimeRange } from './thread/ActivityGraphFills';
29-
import { ensureExists } from '../../utils/flow';
3028

3129
type CPUProps = CpuRatioInTimeRange;
3230

@@ -134,21 +132,10 @@ export class SampleTooltipContents extends React.PureComponent<Props> {
134132
let hasStack = false;
135133
let formattedSampleTime = null;
136134
if (sampleIndex !== null) {
137-
const { samples, stackTable } = rangeFilteredThread;
135+
const { samples } = rangeFilteredThread;
138136
const sampleTime = samples.time[sampleIndex];
139-
const stackIndex = samples.stack[sampleIndex];
140-
const hasSamples = samples.length > 0 && stackTable.length > 1;
141-
142-
if (hasSamples) {
143-
const stack = getFuncNamesAndOriginsForPath(
144-
convertStackToCallNodeAndCategoryPath(
145-
rangeFilteredThread,
146-
ensureExists(stackIndex)
147-
),
148-
rangeFilteredThread
149-
);
150-
hasStack = stack.length > 1 || stack[0].funcName !== '(root)';
151-
}
137+
138+
hasStack = isSampleWithNonEmptyStack(sampleIndex, rangeFilteredThread);
152139

153140
formattedSampleTime = getFormattedTimelineValue(
154141
sampleTime - zeroAt,

src/profile-logic/profile-data.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,34 +2883,32 @@ export function reserveFunctionsInThread(
28832883
}
28842884
28852885
/**
2886-
* From a valid call node path, this function returns a list of information
2887-
* about each function in this path: their names and their origins.
2886+
* Returns whether the given sample has a stack which is non-null and not just
2887+
* a single function with the name '(root)'.
28882888
*/
2889-
export function getFuncNamesAndOriginsForPath(
2890-
path: CallNodeAndCategoryPath,
2889+
export function isSampleWithNonEmptyStack(
2890+
sampleIndex: IndexIntoSamplesTable,
28912891
thread: Thread
2892-
): Array<{
2893-
funcName: string,
2894-
category: IndexIntoCategoryList,
2895-
isFrameLabel: boolean,
2896-
origin: string,
2897-
}> {
2898-
const { funcTable, stringTable, resourceTable } = thread;
2892+
): boolean {
2893+
const { samples, stackTable, frameTable, funcTable, stringTable } = thread;
28992894
2900-
return path.map((frame) => {
2901-
const { category, func } = frame;
2902-
return {
2903-
funcName: stringTable.getString(funcTable.name[func]),
2904-
category: category,
2905-
isFrameLabel: funcTable.resource[func] === -1,
2906-
origin: getOriginAnnotationForFunc(
2907-
func,
2908-
funcTable,
2909-
resourceTable,
2910-
stringTable
2911-
),
2912-
};
2913-
});
2895+
const stackIndex = samples.stack[sampleIndex];
2896+
if (stackIndex === null) {
2897+
return false;
2898+
}
2899+
2900+
if (stackTable.prefix[stackIndex] !== null) {
2901+
// Stack contains at least two frames.
2902+
return true;
2903+
}
2904+
2905+
// Stack is only a single frame. Is it the '(root)' frame that Firefox puts
2906+
// in its profiles?
2907+
const frameIndex = stackTable.frame[stackIndex];
2908+
const funcIndex = frameTable.func[frameIndex];
2909+
const funcNameStringIndex = funcTable.name[funcIndex];
2910+
const funcName = stringTable.getString(funcNameStringIndex);
2911+
return funcName !== '(root)';
29142912
}
29152913
29162914
/**

0 commit comments

Comments
 (0)