123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import {resolveJSSelfProfilingStack} from 'sentry/utils/profiling/jsSelfProfiling';
- import {createFrameIndex} from 'sentry/utils/profiling/profile/utils';
- const toStackNames = (stack: ReadonlyArray<JSSelfProfiling.Frame>): string[] => {
- return stack.map(f => f.name);
- };
- describe('jsSelfProfiling', () => {
- describe('resolveJSSelfProfilingStack', () => {
- it('when thread is idle and sample has no associated stackId', () => {
- const trace: JSSelfProfiling.Trace = {
- frames: [],
- resources: [],
- samples: [{stackId: undefined, timestamp: 0}],
- stacks: [],
- };
- expect(resolveJSSelfProfilingStack(trace, undefined, {})).toEqual([]);
- });
- it('when stackId is set', () => {
- const trace: JSSelfProfiling.Trace = {
- frames: [
- {name: 'foo', line: 0, column: 0},
- {name: 'bar', line: 0, column: 0},
- {name: 'baz', line: 0, column: 0},
- {name: 'foobar', line: 0, column: 0},
- {name: 'foobarbaz', line: 0, column: 0},
- {name: 'foobarbazfoo', line: 0, column: 0},
- ],
- resources: [],
- samples: [{stackId: 5, timestamp: 0}],
- stacks: [
- {frameId: 0, parentId: undefined},
- {frameId: 1, parentId: undefined},
- {frameId: 2, parentId: undefined},
- {frameId: 3, parentId: 2},
- {frameId: 4, parentId: 3},
- {frameId: 5, parentId: 4},
- ],
- };
- expect(
- toStackNames(
- resolveJSSelfProfilingStack(trace, 5, createFrameIndex('web', trace.frames))
- )
- ).toEqual(['baz', 'foobar', 'foobarbaz', 'foobarbazfoo']);
- });
- it('when marker is present on the stack', () => {
- const trace: JSSelfProfiling.Trace = {
- frames: [
- {name: 'foo', line: 0, column: 0},
- {name: 'bar', line: 0, column: 0},
- {name: 'baz', line: 0, column: 0},
- {name: 'foobar', line: 0, column: 0},
- {name: 'foobarbaz', line: 0, column: 0},
- {name: 'foobarbazfoo', line: 0, column: 0},
- ],
- resources: [],
- samples: [{stackId: 5, timestamp: 0, marker: 'gc'}],
- stacks: [
- {frameId: 0, parentId: undefined},
- {frameId: 1, parentId: undefined},
- {frameId: 2, parentId: undefined},
- {frameId: 3, parentId: 2},
- {frameId: 4, parentId: 3},
- {frameId: 5, parentId: 4},
- ],
- };
- // I'm not sure I like passing the marker, the reason it's like this is that we usually loop through the samples and have the marker as
- // we execute resolveJSSelfProfilingStack, but I'm not sure we should do that and instead augment the resolved stack outside of the loop.
- // The nice thing about it is that it centralizes the stack logic and makes it easier to test.
- expect(
- toStackNames(
- resolveJSSelfProfilingStack(
- trace,
- 5,
- createFrameIndex('web', trace.frames),
- 'gc'
- )
- )
- ).toEqual(['baz', 'foobar', 'foobarbaz', 'foobarbazfoo', 'Garbage Collection']);
- });
- it('when stack is empty, but browser was performing other operations', () => {
- const trace: JSSelfProfiling.Trace = {
- frames: [],
- resources: [],
- samples: [{stackId: 0, timestamp: 0, marker: 'paint'}],
- stacks: [{frameId: 0, parentId: undefined}],
- };
- expect(
- toStackNames(
- resolveJSSelfProfilingStack(
- trace,
- 0,
- createFrameIndex('web', trace.frames),
- 'paint'
- )
- )
- ).toEqual(['Paint']);
- });
- });
- });
|