-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathmemory.ts
More file actions
36 lines (31 loc) · 950 Bytes
/
memory.ts
File metadata and controls
36 lines (31 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {zod} from '../third_party/index.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';
export const takeMemorySnapshot = defineTool({
name: 'take_memory_snapshot',
description: `Capture a memory heapsnapshot of the currently selected page to memory leak debugging`,
annotations: {
category: ToolCategory.PERFORMANCE,
readOnlyHint: true,
},
schema: {
filePath: zod
.string()
.describe('A path to a .heapsnapshot file to save the heapsnapshot to.')
.endsWith('.heapsnapshot'),
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();
await page.captureHeapSnapshot({
path: request.params.filePath,
});
response.appendResponseLine(
`Heap snapshot saved to ${request.params.filePath}`,
);
},
});