Skip to content

Commit b54a13e

Browse files
committedAug 16, 2022
feat: show transform time
1 parent c663f39 commit b54a13e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎packages/vite-node/src/server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class ViteNodeServer {
1818
private transformPromiseMap = new Map<string, Promise<TransformResult | null | undefined>>()
1919

2020
fetchCache = new Map<string, {
21+
duration?: number
2122
timestamp: number
2223
result: FetchResult
2324
}>()
@@ -125,16 +126,20 @@ export class ViteNodeServer {
125126
return cache.result
126127

127128
const externalize = await this.shouldExternalize(filePath)
129+
let duration: number | undefined
128130
if (externalize) {
129131
result = { externalize }
130132
this.debugger?.recordExternalize(id, externalize)
131133
}
132134
else {
135+
const start = performance.now()
133136
const r = await this._transformRequest(id)
137+
duration = performance.now() - start
134138
result = { code: r?.code, map: r?.map as unknown as RawSourceMap }
135139
}
136140

137141
this.fetchCache.set(filePath, {
142+
duration,
138143
timestamp,
139144
result,
140145
})

‎packages/vitest/src/node/reporters/base.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export abstract class BaseReporter implements Reporter {
218218
const collectTime = files.reduce((acc, test) => acc + Math.max(0, test.collectDuration || 0), 0)
219219
const setupTime = files.reduce((acc, test) => acc + Math.max(0, test.setupDuration || 0), 0)
220220
const testsTime = files.reduce((acc, test) => acc + Math.max(0, test.result?.duration || 0), 0)
221+
const transformTime = Array.from(this.ctx.vitenode.fetchCache.values()).reduce((a, b) => a + (b?.duration || 0), 0)
221222
const threadTime = collectTime + testsTime + setupTime
222223

223224
const padTitle = (str: string) => c.dim(`${str.padStart(10)} `)
@@ -227,6 +228,14 @@ export abstract class BaseReporter implements Reporter {
227228
return `${Math.round(time)}ms`
228229
}
229230

231+
// show top 10 costly transform module
232+
// console.log(Array.from(this.ctx.vitenode.fetchCache.entries()).filter(i => i[1].duration)
233+
// .sort((a, b) => b[1].duration! - a[1].duration!)
234+
// .map(i => `${time(i[1].duration!)} ${i[0]}`)
235+
// .slice(0, 10)
236+
// .join('\n'),
237+
// )
238+
230239
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary)
231240
if (snapshotOutput.length) {
232241
logger.log(snapshotOutput.map((t, i) => i === 0
@@ -243,7 +252,7 @@ export abstract class BaseReporter implements Reporter {
243252
if (this.watchFilters)
244253
logger.log(padTitle('Duration'), time(threadTime))
245254
else
246-
logger.log(padTitle('Duration'), time(executionTime) + c.gray(` (setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`))
255+
logger.log(padTitle('Duration'), time(executionTime) + c.dim(` (transform ${time(transformTime)}, setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`))
247256

248257
logger.log()
249258
}

0 commit comments

Comments
 (0)
Please sign in to comment.