@@ -12,6 +12,7 @@ import {
1212 updateThreadStacks ,
1313 updateThreadStacksByGeneratingNewStackColumns ,
1414 getMapStackUpdater ,
15+ getOriginAnnotationForFunc ,
1516} from './profile-data' ;
1617import { timeCode } from '../utils/time-code' ;
1718import { assertExhaustiveCheck , convertToTransformType } from '../utils/flow' ;
@@ -32,7 +33,6 @@ import type {
3233 IndexIntoStackTable ,
3334 IndexIntoResourceTable ,
3435 CallNodePath ,
35- CallNodeAndCategoryPath ,
3636 CallNodeTable ,
3737 StackType ,
3838 ImplementationFilter ,
@@ -1563,15 +1563,72 @@ export function filterCallNodePathByImplementation(
15631563 ) ;
15641564}
15651565
1566- export function filterCallNodeAndCategoryPathByImplementation (
1567- thread : Thread ,
1566+ // User-facing properties about a stack frame.
1567+ export type BacktraceItem = { |
1568+ // The function name of the stack frame.
1569+ funcName : string ,
1570+ // The frame category of the stack frame.
1571+ category : IndexIntoCategoryList ,
1572+ // Whether this frame is a label frame.
1573+ isFrameLabel : boolean ,
1574+ // A string which is usually displayed after the function name, and which
1575+ // describes, in some way, where this function or frame came from.
1576+ // If known, this contains the file name of the function, and the line and
1577+ // column number of the frame, i.e. the spot within the function that was
1578+ // being executed.
1579+ // If the source file name is not known, this might be the name of a native
1580+ // library instead.
1581+ // May also be empty.
1582+ origin : string ,
1583+ | } ;
1584+
1585+ /**
1586+ * Convert the stack into an array of "backtrace items" for each stack frame.
1587+ * The returned array is ordered from callee-most to caller-most, i.e. the root
1588+ * caller is at the end.
1589+ */
1590+ export function getBacktraceItemsForStack (
1591+ stack : IndexIntoStackTable ,
15681592 implementationFilter : ImplementationFilter ,
1569- path : CallNodeAndCategoryPath
1570- ) : CallNodeAndCategoryPath {
1593+ thread : Thread
1594+ ) : BacktraceItem [ ] {
1595+ const { funcTable, stringTable, resourceTable } = thread ;
1596+
1597+ const { stackTable, frameTable } = thread ;
1598+ const unfilteredPath = [ ] ;
1599+ for (
1600+ let stackIndex = stack ;
1601+ stackIndex !== null ;
1602+ stackIndex = stackTable . prefix [ stackIndex ]
1603+ ) {
1604+ const frameIndex = stackTable . frame [ stackIndex ] ;
1605+ unfilteredPath . push ( {
1606+ category : stackTable . category [ stackIndex ] ,
1607+ funcIndex : frameTable . func [ frameIndex ] ,
1608+ frameLine : frameTable . line [ frameIndex ] ,
1609+ frameColumn : frameTable . column [ frameIndex ] ,
1610+ } ) ;
1611+ }
1612+
15711613 const funcMatchesImplementation = FUNC_MATCHES [ implementationFilter ] ;
1572- return path . filter ( ( funcIndex ) =>
1573- funcMatchesImplementation ( thread , funcIndex . func )
1614+ const path = unfilteredPath . filter ( ( { funcIndex } ) =>
1615+ funcMatchesImplementation ( thread , funcIndex )
15741616 ) ;
1617+ return path . map ( ( { category, funcIndex, frameLine, frameColumn } ) => {
1618+ return {
1619+ funcName : stringTable . getString ( funcTable . name [ funcIndex ] ) ,
1620+ category : category ,
1621+ isFrameLabel : funcTable . resource [ funcIndex ] === - 1 ,
1622+ origin : getOriginAnnotationForFunc (
1623+ funcIndex ,
1624+ funcTable ,
1625+ resourceTable ,
1626+ stringTable ,
1627+ frameLine ,
1628+ frameColumn
1629+ ) ,
1630+ } ;
1631+ } ) ;
15751632}
15761633
15771634/**
0 commit comments