diff --git a/packages/next/src/bin/next.ts b/packages/next/src/bin/next.ts index 80d6a0fe6fde..2bde7eb71a91 100755 --- a/packages/next/src/bin/next.ts +++ b/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' diff --git a/packages/next/src/build/utils.ts b/packages/next/src/build/utils.ts index 824d86b9845e..5742f6da9b34 100644 --- a/packages/next/src/build/utils.ts +++ b/packages/next/src/build/utils.ts @@ -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) diff --git a/packages/next/src/cli/next-start.ts b/packages/next/src/cli/next-start.ts index 06cddaed5a86..312ddf8ebc2c 100755 --- a/packages/next/src/cli/next-start.ts +++ b/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' diff --git a/packages/next/src/server/lib/start-server.ts b/packages/next/src/server/lib/start-server.ts index 9300fe5f69bf..6b8eee596318 100644 --- a/packages/next/src/server/lib/start-server.ts +++ b/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' @@ -130,7 +133,6 @@ export async function startServer({ envInfo, expFeatureInfo, }: StartServerOptions): Promise { - const startServerProcessStartTime = Date.now() let handlersReady = () => {} let handlersError = () => {} @@ -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({