Skip to content

Commit f661196

Browse files
committed
Startup profiling
1 parent 71fd250 commit f661196

File tree

15 files changed

+917
-186
lines changed

15 files changed

+917
-186
lines changed

.changeset/rich-pots-mate.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add `--outfile` to `wrangler deploy` for generating a worker bundle.
6+
7+
This is an advanced feature that most users won't need to use. When set, Wrangler will output your built Worker bundle in a Cloudflare specific format that captures all information needed to deploy a Worker using the [Worker Upload API](https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/)

.changeset/startup-profiling.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add a `wrangler check startup` command to generate a CPU profile of your Worker's startup phase.
6+
7+
This can be imported into Chrome DevTools or opened directly in VSCode to view a flamegraph of your Worker's startup phase. Additionally, when a Worker deployment fails with a startup time error Wrangler will automatically generate a CPU profile for easy investigation.
8+
9+
Advanced usage:
10+
11+
- `--deploy-args`: to customise the way `wrangler check startup` builds your Worker for analysis, provide the exact arguments you use when deploying your Worker with `wrangler deploy`. For instance, if you deploy your Worker with `wrangler deploy --no-bundle`, you should use `wrangler check startup --deploy-args="--no-bundle"` to profile the startup phase.
12+
- `--worker-bundle`: if you don't use Wrangler to deploy your Worker, you can use this argument to provide a Worker bundle to analyse. This should be a file path to a serialised multipart upload, with the exact same format as the API expects: https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/

packages/miniflare/src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -767,17 +767,17 @@ export class Miniflare {
767767
});
768768
// Add custom headers included in response to WebSocket upgrade requests
769769
this.#webSocketExtraHeaders = new WeakMap();
770-
this.#webSocketServer.on("headers", (headers, req) => {
771-
const extra = this.#webSocketExtraHeaders.get(req);
772-
this.#webSocketExtraHeaders.delete(req);
773-
if (extra) {
774-
for (const [key, value] of extra) {
775-
if (!restrictedWebSocketUpgradeHeaders.includes(key.toLowerCase())) {
776-
headers.push(`${key}: ${value}`);
777-
}
778-
}
779-
}
780-
});
770+
// this.#webSocketServer.on("headers", (headers, req) => {
771+
// const extra = this.#webSocketExtraHeaders.get(req);
772+
// this.#webSocketExtraHeaders.delete(req);
773+
// if (extra) {
774+
// for (const [key, value] of extra) {
775+
// if (!restrictedWebSocketUpgradeHeaders.includes(key.toLowerCase())) {
776+
// headers.push(`${key}: ${value}`);
777+
// }
778+
// }
779+
// }
780+
// });
781781

782782
// Build path for temporary directory. We don't actually want to create this
783783
// unless it's needed (i.e. we have Durable Objects enabled). This means we
@@ -1046,7 +1046,7 @@ export class Miniflare {
10461046
http.createServer(this.#handleLoopback),
10471047
/* grace */ 0
10481048
);
1049-
server.on("upgrade", this.#handleLoopbackUpgrade);
1049+
// server.on("upgrade", this.#handleLoopbackUpgrade);
10501050
server.listen(0, hostname, () => resolve(server));
10511051
});
10521052
}

0 commit comments

Comments
 (0)