Skip to content

Commit

Permalink
fix wrong start duration
Browse files Browse the repository at this point in the history
  • Loading branch information
feedthejim committed Oct 6, 2023
1 parent 2af1e78 commit d37fa9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/next/src/bin/next.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
performance.mark('next-start')
import '../server/require-hook'
import * as log from '../build/output/log'
import arg from 'next/dist/compiled/arg/index.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,8 @@ export async function copyTracedFiles(
serverOutputPath,
`${
moduleType
? `import path from 'path'
? `performance.mark('next-start');
import path from 'path'
import { fileURLToPath } from 'url'
import module from 'module'
const require = module.createRequire(import.meta.url)
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/cli/next-start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node

import '../server/lib/cpu-profile'
import { startServer } from '../server/lib/start-server'
import { getPort, printAndExit } from '../server/lib/utils'
Expand Down
16 changes: 13 additions & 3 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if (performance.getEntriesByName('next-start').length === 0) {
performance.mark('next-start')
}
import '../next'
import '../node-polyfill-fetch'
import '../require-hook'
Expand Down Expand Up @@ -130,7 +133,6 @@ export async function startServer({
envInfo,
expFeatureInfo,
}: StartServerOptions): Promise<void> {
const startServerProcessStartTime = Date.now()
let handlersReady = () => {}
let handlersError = () => {}

Expand Down Expand Up @@ -296,8 +298,16 @@ export async function startServer({
requestHandler = initResult[0]
upgradeHandler = initResult[1]

const startServerProcessDuration =
Date.now() - startServerProcessStartTime
let startServerProcessDuration =
performance.mark('next-start-end') &&
performance.measure(
'next-start-duration',
'next-start',
'next-start-end'
).duration

startServerProcessDuration = Math.round(startServerProcessDuration)

const formatDurationText =
startServerProcessDuration > 2000
? `${Math.round(startServerProcessDuration / 100) / 10}s`
Expand Down

0 comments on commit d37fa9a

Please sign in to comment.