Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: fix wrong next start start duration #56512

Merged
merged 2 commits into from Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/src/bin/next.ts
@@ -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
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
@@ -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
14 changes: 11 additions & 3 deletions packages/next/src/server/lib/start-server.ts
@@ -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 @@ -297,11 +299,17 @@ export async function startServer({
upgradeHandler = initResult[1]

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

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

handlersReady()
logStartInfo({
Expand Down