generated from fresh-app/fresh-remix-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf measurement & query facility (#104)
- Loading branch information
Showing
11 changed files
with
344 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'contentsgarten': minor | ||
--- | ||
|
||
The `view` method now returns a `perf` array which contains the performance logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'contentsgarten': minor | ||
--- | ||
|
||
Add ability to query page data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const PageRefRegex = /^[A-Z][A-Za-z0-9_/-]*$/ | ||
export const LaxPageRefRegex = /^[A-Za-z0-9_/-]+$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PerfContext, PerfEntry } from './RequestContext' | ||
|
||
export class PerfContextImpl implements PerfContext { | ||
private begin = performance.now() | ||
private beginTime = new Date() | ||
private data: { start: number; finish?: number; text: string }[] = [] | ||
async measure<T>( | ||
name: string, | ||
fn: (entry: PerfEntry) => PromiseLike<T>, | ||
): Promise<T> { | ||
const entry: (typeof this.data)[number] = { | ||
start: performance.now(), | ||
text: name, | ||
} | ||
this.data.push(entry) | ||
try { | ||
return await fn({ | ||
addInfo: (info) => { | ||
entry.text += ` (${info})` | ||
}, | ||
}) | ||
} finally { | ||
entry.finish = performance.now() | ||
} | ||
} | ||
log(name: string): void { | ||
this.data.push({ start: performance.now(), text: name }) | ||
} | ||
toMessageArray() { | ||
const out: string[] = [] | ||
out.push(`start: ${this.beginTime.toISOString()}`) | ||
const begin = this.begin | ||
const fmt = (d: number) => `${(d / 1000).toFixed(3)}s` | ||
const t = (ts: number) => fmt(ts - begin) | ||
for (const { start, finish, text } of this.data) { | ||
if (finish) { | ||
out.push( | ||
`${t(start)} ~ ${t(finish)} | ${text} (took ${fmt(finish - start)})`, | ||
) | ||
} else { | ||
out.push(`${t(start)} | ${text}`) | ||
} | ||
} | ||
const finish = performance.now() | ||
out.push(`${t(finish)} | finish (total ${fmt(finish - begin)}))`) | ||
return out | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.