-
Notifications
You must be signed in to change notification settings - Fork 9
Add the resource timings pane #5
Changes from 19 commits
3ff6143
3e02d36
fd40cdc
eba0aa3
ab78238
607a334
0f3476f
fd4ed71
4fe607e
988e988
d14c60b
461ebd1
f0f4ff4
dd6c766
ff81f86
71ee9ad
2c2f5e7
68841ea
8f42ece
4931c28
57bd900
b6fb06c
3a1bc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ dist/ | |
*.js | ||
*.js.map | ||
*.d.ts | ||
!injectDemoToolbar.user.js | ||
!injectDemoToolbar.user.js | ||
!commontypes.d.ts | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,42 +2,53 @@ | |
<html> | ||
<head> | ||
<title>Demo for WebPerfToolbar</title> | ||
<style> | ||
body { background-color: lightgray; } | ||
</style> | ||
<style> | ||
/** TODO: These need to be moved into JS (for ease of usage in an app). They're inline in the demo for ease of development. */ | ||
|
||
#PTB_buttons { | ||
position:fixed; | ||
bottom: 0; | ||
left: 50px; | ||
border:1px solid black; | ||
border-bottom: none; | ||
|
||
list-style:none; | ||
padding:0; | ||
margin:0; | ||
|
||
z-index: 2147483647; /* we're on top */ | ||
} | ||
#PTB_buttons li { | ||
display:inline-block; | ||
line-height:1.6em; | ||
margin-left:0.5em; | ||
padding:0.2em; | ||
cursor:pointer; | ||
|
||
border:1px solid black; | ||
border-bottom: none; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: some styles have a space after the colon; some don't. #WontFix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't fix because this is getting moved to JavaScript soon. I'll standardize then. In reply to: 161152446 [](ancestors = 161152446) |
||
} | ||
#PTB_buttons li:first-child { | ||
margin-left:0; | ||
} | ||
|
||
#PTB_frame { | ||
position:fixed; | ||
width:30%; | ||
min-width:300px; | ||
right:0; | ||
left:0; | ||
top:0; | ||
|
||
width:100%; | ||
height:100%; | ||
border-left:1px solid black; | ||
overflow:auto; | ||
|
||
padding:0.5em; | ||
background:rgba(255, 255, 255, 0.95); | ||
z-index:2147483646; /* we're one layer below the top */ | ||
} | ||
|
||
#PTB_frame table { | ||
margin-top:0.5em; | ||
border-collapse: collapse; | ||
border-spacing: 0; | ||
border: 1px solid black; | ||
|
@@ -50,6 +61,10 @@ | |
border: 1px solid black; | ||
padding:0.2em; | ||
} | ||
|
||
#PTB_frame .numeric { | ||
text-align: right; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
@@ -67,11 +82,15 @@ | |
(new PerfToolbar.Toolbar([ | ||
/** Configure this to include the panels you need */ | ||
{ | ||
panel: PerfToolbar.NavigationTimingsPanel, | ||
panelConstructor: PerfToolbar.NavigationTimingsPanel, | ||
config: { | ||
goalMs: 25 | ||
} | ||
}, | ||
{ | ||
panelConstructor: PerfToolbar.ResourceTimingsPanel, | ||
config: {} | ||
} | ||
/** End configuration */ | ||
])).render(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// begin types from https://github.com/Microsoft/TypeScript/issues/15012 | ||
|
||
type Required<T> = { | ||
[P in Purify<keyof T>]: NonNullable<T[P]>; | ||
}; | ||
type Purify<T extends string> = {[P in T]: T; }[T]; | ||
type NonNullable<T> = T & {}; | ||
|
||
// end types from https://github.com/Microsoft/TypeScript/issues/15012 | ||
|
||
/** | ||
* The types we expect from entry.initiatorType. | ||
* Values from https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-initiatortype | ||
*/ | ||
type InitiatorType = "link" | "script" | "img" | "iframe" | "css" | "navigation" | "xmlhttprequest" | "fetch" | "beacon" | "other"; | ||
|
||
/** | ||
* Finish the typings for a file gotten by `performance.getEntriesByType("resource")` | ||
*/ | ||
interface IResourcePerformanceEntry extends PerformanceEntry, PerformanceResourceTiming { | ||
decodedBodySize: number; | ||
encodedBodySize: number; | ||
initiatorType: InitiatorType; | ||
transferSize: number; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/** The level of precision we want to see for numbers */ | ||
export const DECIMAL_PLACES: number = 2; | ||
|
||
/** The maximum length of a file name */ | ||
export const MAX_FILE_NAME_LENGTH: number = 60; | ||
|
||
/** | ||
* Formats a duration for output. Makes sure the numbers are valid and only returns a certain number of decimal places. | ||
* Invalid input returns a dash. | ||
|
@@ -9,10 +12,71 @@ export const DECIMAL_PLACES: number = 2; | |
* @param decimalPlaces The number of decimal places to show. | ||
*/ | ||
export const duration: (end: number, start: number, decimalPlaces?: number) => string = | ||
(end: number, start: number, decimalPlaces: number = DECIMAL_PLACES): string => { | ||
if (isNaN(end) || isNaN(start)) { | ||
(end, start, decimalPlaces = DECIMAL_PLACES) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in person: it's driving me crazy that you have duplicate type declarations here (one explicit, one implicit). Instead of: export const duration: (end: number, start: number, decimalPlaces?: number) => string =
(end, start, decimalPlaces = DECIMAL_PLACES) => { /* ... */ }; ...it would be simpler to write: export const duration = (end: number, start: number, decimalPlaces?: number): string => { /* ... */ };
``` #Resolved |
||
if (isNaN(end) || | ||
isNaN(start) || | ||
(end - start < 0) || | ||
(end === 0 && start === 0)) { | ||
return "-"; | ||
} | ||
|
||
return (end - start).toFixed(decimalPlaces); | ||
return (end - start).toLocaleString(undefined, { | ||
minimumFractionDigits: decimalPlaces, | ||
maximumFractionDigits: decimalPlaces, | ||
}); | ||
}; | ||
|
||
/** | ||
* Formats a path into a filename. | ||
* @param path The file name to be formatted. | ||
* @param maxLength The maximum length of the returned file name, plus three characters for periods. | ||
*/ | ||
export const pathToFilename: (path: string, maxLength?: number) => string = | ||
(path, maxLength = MAX_FILE_NAME_LENGTH) => { | ||
let trimmed: string = path.substring(path.lastIndexOf("/") + 1); | ||
|
||
if (trimmed.length > maxLength) { | ||
trimmed = `${trimmed.substring(0, maxLength)}...`; | ||
} | ||
|
||
return trimmed; | ||
}; | ||
|
||
enum FileSizeUnits { | ||
b, | ||
Kb, | ||
Mb, | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enum #Closed |
||
/** | ||
* Simple object for passing to toLocaleString to configure the number of decimal places to display. | ||
*/ | ||
const LOCALE_STRING_DECIMAL_PLACES: { maximumFractionDigits: number; minimumFractionDigits: number } = { | ||
minimumFractionDigits: DECIMAL_PLACES, | ||
maximumFractionDigits: DECIMAL_PLACES, | ||
}; | ||
|
||
/** | ||
* Converts a size in bytes to another size, with a unit. | ||
* @param bytes The size in bytes. | ||
* @param unit The desired unit to conver to. | ||
*/ | ||
export const sizeToString: (bytes: number, unit?: keyof typeof FileSizeUnits) => string = | ||
(bytes, unit = "Kb"): string => { | ||
const twoExpTen: number = 1024; | ||
|
||
if (bytes === 0) { | ||
return "-"; | ||
} | ||
|
||
switch (unit) { | ||
case "b": | ||
return `${bytes.toLocaleString(undefined, LOCALE_STRING_DECIMAL_PLACES)} b`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case FileSizeUnits[FileSizeUnits.b] |
||
case "Kb": | ||
return `${(bytes / twoExpTen).toLocaleString(undefined, LOCALE_STRING_DECIMAL_PLACES)} Kb`; | ||
case "Mb": | ||
return `${(bytes / (twoExpTen * twoExpTen)).toLocaleString(undefined, LOCALE_STRING_DECIMAL_PLACES)} Mb`; | ||
default: | ||
throw new Error("unknown unit"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like you should turn off the TSLint rule or find/make a config that allows for exhaustive switches. This code should never be hit, and is just wasted bytes. #ByDesign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By Design, since the value can be passed in from JS code that wouldn't know the type limitations. In reply to: 161152748 [](ancestors = 161152748) |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Toolbar } from "./toolbar"; | ||
export { Button } from "./button"; | ||
export { NavigationTimingsPanel } from "./panels/navigation-timing"; | ||
export { ResourceTimingsPanel } from "./panels/resource-timing"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of your source, so it shouldn't be gitignored. #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if you're doing something fancy about not changing the API, document it) #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence the ! in front. :-)
In reply to: 161152364 [](ancestors = 161152364)