Skip to content

Commit ec67bc0

Browse files
author
John Doe
committed
refactor: impl feedback
1 parent 878b939 commit ec67bc0

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

packages/utils/src/lib/clock-epoch.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ export function epochClock(init: EpochClockOptions = {}) {
4242
msToUs(timeOriginMs + perfMs);
4343

4444
const fromEntryStartTimeMs = fromPerfMs;
45-
const fromEntry = (entry: PerformanceEntry, useEndTime = false) =>
46-
defaultClock.fromPerfMs(
45+
const fromEntry = (
46+
entry: {
47+
startTime: Milliseconds;
48+
entryType: string;
49+
duration: Milliseconds;
50+
},
51+
useEndTime = false,
52+
) =>
53+
fromPerfMs(
4754
entry.startTime +
4855
(entry.entryType === 'measure' && useEndTime ? entry.duration : 0),
4956
);

packages/utils/src/lib/trace-file-utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import type {
88
EndEvent,
99
InstantEvent,
1010
InstantEventArgs,
11+
InstantEventTracingStartedInBrowser,
1112
SpanEvent,
1213
SpanEventArgs,
13-
StartTracingEvent,
1414
TraceEvent,
1515
TraceEventContainer,
1616
} from './trace-file.type.js';
1717

18-
/** Global counter for generating unique local IDs */
18+
/** Global counter for generating unique span IDs within a trace */
1919
// eslint-disable-next-line functional/no-let
2020
let id2Count = 0;
2121

2222
/**
23-
* Generates a unique local ID for span events, to link start and end with a id.
24-
* @returns Object with local ID string
23+
* Generates a unique ID for linking begin and end span events in Chrome traces.
24+
* @returns Object with local ID string for the id2 field
2525
*/
2626
export const nextId2 = () => ({ local: `0x${++id2Count}` });
2727

@@ -74,16 +74,16 @@ export const getInstantEvent = (opt: {
7474

7575
/**
7676
* Creates a start tracing event with frame information.
77-
* This event is needed to make events in general show up and also colores the track better.
77+
* This event is needed at the beginning of the traceEvents array to make tell the UI profiling has started, and it should visualize the data.
7878
* @param opt - Tracing configuration options
7979
* @returns StartTracingEvent object
8080
*/
81-
export const getStartTracing = (opt: {
81+
export const getInstantEventTracingStartedInBrowser = (opt: {
8282
url: string;
8383
ts?: number;
8484
pid?: number;
8585
tid?: number;
86-
}): StartTracingEvent => {
86+
}): InstantEventTracingStartedInBrowser => {
8787
const { pid, tid, ts } = defaults(opt);
8888
const id = frameTreeNodeId(pid, tid);
8989

packages/utils/src/lib/trace-file-utils.unit.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
frameTreeNodeId,
66
getCompleteEvent,
77
getInstantEvent,
8+
getInstantEventTracingStartedInBrowser,
89
getSpan,
910
getSpanEvent,
10-
getStartTracing,
1111
getTraceFile,
1212
markToInstantEvent,
1313
measureToSpanEvents,
@@ -103,9 +103,11 @@ describe('frameName', () => {
103103
});
104104
});
105105

106-
describe('getStartTracing', () => {
106+
describe('getInstantEventTracingStartedInBrowser', () => {
107107
it('should create start tracing event with required url', () => {
108-
expect(getStartTracing({ url: 'https://example.com' })).toStrictEqual({
108+
expect(
109+
getInstantEventTracingStartedInBrowser({ url: 'https://example.com' }),
110+
).toStrictEqual({
109111
cat: 'devtools.timeline',
110112
ph: 'i',
111113
name: 'TracingStartedInBrowser',
@@ -133,7 +135,7 @@ describe('getStartTracing', () => {
133135

134136
it('should use custom pid and tid', () => {
135137
expect(
136-
getStartTracing({
138+
getInstantEventTracingStartedInBrowser({
137139
url: 'https://test.com',
138140
pid: 777,
139141
tid: 888,

packages/utils/src/lib/trace-file.type.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getInstantEventTracingStartedInBrowser } from './trace-file-utils';
12
import type { UserTimingDetail } from './user-timing-extensibility-api.type';
23

34
/**
@@ -30,7 +31,7 @@ export type CompleteEventArgs = { detail?: Record<string, unknown> };
3031
* @property {Array} data.frames - Array of frame information
3132
* @property {boolean} data.persistentIds - Whether IDs are persistent
3233
*/
33-
export type StartTracingEventArgs = {
34+
export type InstantEventTracingStartedInBrowserArgs = {
3435
data: {
3536
frameTreeNodeId: number;
3637
frames: {
@@ -52,7 +53,7 @@ export type TraceArgs =
5253
| InstantEventArgs
5354
| SpanEventArgs
5455
| CompleteEventArgs
55-
| StartTracingEventArgs;
56+
| InstantEventTracingStartedInBrowserArgs;
5657

5758
/**
5859
* Base properties shared by all trace events.
@@ -75,11 +76,11 @@ export type BaseTraceEvent = {
7576
/**
7677
* Start tracing event for Chrome DevTools tracing.
7778
*/
78-
export type StartTracingEvent = BaseTraceEvent & {
79+
export type InstantEventTracingStartedInBrowser = BaseTraceEvent & {
7980
cat: 'devtools.timeline';
8081
ph: 'i';
8182
name: 'TracingStartedInBrowser';
82-
args: StartTracingEventArgs;
83+
args: InstantEventTracingStartedInBrowserArgs;
8384
};
8485

8586
/**
@@ -118,7 +119,7 @@ type SpanCore = Omit<BaseTraceEvent, 'args'> & {
118119
/**
119120
* Begin event for a span (paired with an end event).
120121
* @property {'b'} ph - Phase indicator for begin events
121-
* @property {'t'} s - Scope indicator (thread)
122+
* @property {'t'} s - Scope indicator ('t' is thread)
122123
* @property {never} [dur] - Duration is not applicable for begin events
123124
*/
124125
export type BeginEvent = SpanCore & {
@@ -145,7 +146,7 @@ export type TraceEvent =
145146
| InstantEvent
146147
| CompleteEvent
147148
| SpanEvent
148-
| StartTracingEvent;
149+
| InstantEventTracingStartedInBrowser;
149150

150151
/**
151152
* Raw arguments format for trace events before processing.

0 commit comments

Comments
 (0)