Skip to content

Commit 33754cb

Browse files
committed
Add Duration/Size columns to the header of view-event list.
1 parent 0eaff10 commit 33754cb

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

src/components/view/http/http-performance-card.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { get } from 'typesafe-get';
55

66
import { styled } from '../../../styles';
77
import {
8-
Omit,
98
HttpExchange,
109
TimingEvents,
1110
ExchangeMessage
@@ -14,7 +13,7 @@ import { asHeaderArray, joinAnd } from '../../../util';
1413
import { Icon, WarningIcon, SuggestionIcon } from '../../../icons';
1514

1615
import { AccountStore } from '../../../model/account/account-store';
17-
import { getReadableSize, testEncodings } from '../../../model/events/bodies';
16+
import {getReadableDuration, getReadableSize, testEncodings} from '../../../model/events/bodies';
1817
import {
1918
explainCacheability,
2019
explainCacheLifetime,
@@ -41,23 +40,14 @@ interface HttpPerformanceCardProps extends CollapsibleCardProps {
4140
accountStore?: AccountStore;
4241
}
4342

44-
function sigFig(num: number, figs: number): number {
45-
return parseFloat(num.toFixed(figs));
46-
}
47-
4843
const TimingPill = observer((p: { className?: string, timingEvents: TimingEvents }) => {
4944
// We can't show timing info if the request is still going
5045
const doneTimestamp = p.timingEvents.responseSentTimestamp || p.timingEvents.abortedTimestamp;
5146
if (!doneTimestamp) return null;
5247

5348
const durationMs = doneTimestamp - p.timingEvents.startTimestamp;
5449

55-
return <Pill className={p.className}>{
56-
durationMs < 100 ? sigFig(durationMs, 2) + 'ms' : // 22.34ms
57-
durationMs < 1000 ? sigFig(durationMs, 1) + 'ms' : // 999.5ms
58-
durationMs < 10000 ? sigFig(durationMs / 1000, 3) + ' seconds' : // 3.045 seconds
59-
sigFig(durationMs / 1000, 1) + ' seconds' // 11.2 seconds
60-
}</Pill>;
50+
return <Pill className={p.className}>{getReadableDuration(durationMs)}</Pill>;
6151
});
6252

6353
export const HttpPerformanceCard = inject('accountStore')(observer((props: HttpPerformanceCardProps) => {
@@ -342,4 +332,4 @@ const CachingPerformance = observer((p: { exchange: HttpExchange }) => {
342332
</CollapsibleSection>
343333
) }
344334
</>;
345-
});
335+
});

src/components/view/view-event-list.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import {
2323
} from '../../model/events/categorization';
2424

2525
import { UnreachableCheck } from '../../util/error';
26-
import { getReadableSize } from '../../model/events/bodies';
26+
import {
27+
getReadableSize,
28+
getReadableDuration
29+
} from '../../model/events/bodies';
30+
2731
import { filterProps } from '../component-utils';
2832

2933
import { EmptyState } from '../common/empty-state';
@@ -166,6 +170,18 @@ const PathAndQuery = styled(Column)`
166170
flex-basis: 1000px;
167171
`;
168172

173+
const Duration = styled(Column)`
174+
flex-basis: 80px;
175+
flex-shrink: 0;
176+
flex-grow: 0;
177+
`;
178+
179+
const Size = styled(Column)`
180+
flex-basis: 80px;
181+
flex-shrink: 0;
182+
flex-grow: 0;
183+
`;
184+
169185
// Match Method + Status, but shrink right margin slightly so that
170186
// spinner + "WebRTC Media" fits OK.
171187
const EventTypeColumn = styled(Column)`
@@ -372,6 +388,10 @@ const ExchangeRow = observer(({
372388
category
373389
} = exchange;
374390

391+
let durationMs = ('startTime' in exchange.timingEvents) ? (
392+
(exchange.timingEvents.responseSentTimestamp || exchange.timingEvents.abortedTimestamp || 0) - exchange.timingEvents.startTimestamp
393+
) : 0;
394+
375395
return <TrafficEventListRow
376396
role="row"
377397
aria-label='row'
@@ -420,6 +440,12 @@ const ExchangeRow = observer(({
420440
<PathAndQuery title={ request.parsedUrl.pathname + request.parsedUrl.search }>
421441
{ request.parsedUrl.pathname + request.parsedUrl.search }
422442
</PathAndQuery>
443+
<Duration>
444+
{durationMs > 0 ? getReadableDuration(durationMs) : ''}
445+
</Duration>
446+
<Size>
447+
{ exchange.isSuccessfulExchange() ? getReadableSize(exchange.response.body.encoded.byteLength) : ''}
448+
</Size>
423449
</TrafficEventListRow>;
424450
});
425451

@@ -666,6 +692,8 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
666692
<Source>Source</Source>
667693
<Host>Host</Host>
668694
<PathAndQuery>Path and query</PathAndQuery>
695+
<Duration>Duration</Duration>
696+
<Size>Size</Size>
669697
</TableHeader>
670698

671699
{
@@ -869,4 +897,4 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
869897

870898
event.preventDefault();
871899
}
872-
}
900+
}

src/model/events/bodies.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ export function getReadableSize(bytes: number, siUnits = true) {
1818
return (bytes / Math.pow(thresh, unitIndex)).toFixed(1).replace(/\.0$/, '') + ' ' + unitName;
1919
}
2020

21+
function sigFig(num: number, figs: number): number {
22+
return parseFloat(num.toFixed(figs));
23+
}
24+
25+
export function getReadableDuration(durationMs: number): string {
26+
return (durationMs < 100) ? (sigFig(durationMs, 2) + 'ms') // 22.34ms
27+
: (durationMs < 1000 ? sigFig(durationMs, 1) + 'ms' // 999.5ms
28+
: (durationMs < 10000 ? sigFig(durationMs / 1000, 3) + ' s' // 3.045 seconds
29+
: sigFig(durationMs / 1000, 1) + ' s')) // 11.2 seconds
30+
}
31+
2132
const EncodedSizesCacheKey = Symbol('encoded-body-test');
2233
type EncodedBodySizes = { [encoding: string]: number };
2334
type EncodedSizesCache = Map<typeof EncodedSizesCacheKey,
@@ -45,4 +56,4 @@ export function testEncodings(message: ExchangeMessage): EncodedBodySizes | unde
4556
// Will be undefined, but ensures we're subscribed to the observable
4657
return sizesObservable.get();
4758
}
48-
}
59+
}

0 commit comments

Comments
 (0)