diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-07 12:00:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-07 12:00:04 +0100 |
commit | 73e972a173523fd37224c1b6649e0690d2fcdbec (patch) | |
tree | 563aa911598649e4c4a1f5719b5fe63a863f14a8 /editors | |
parent | 0719f2824c01839c19fee944e9f15d15409d74d4 (diff) | |
parent | f44c4b61e131284287b24dea6da6324cbe9cb252 (diff) |
Merge #5244
5244: Add a command to compute memory usage statistics r=matklad a=jonas-schievink
This allows inspecting memory usage on a live rust-analyzer instance after it has been used interactively.
This will only work with `--features jemalloc`, so maybe it should print something more useful when that's not available? Right now it will just print 0 Bytes for every query.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 10 | ||||
-rw-r--r-- | editors/code/src/commands.ts | 32 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 1 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 |
4 files changed, 44 insertions, 0 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 4b47fc9d3..743a2290c 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -61,6 +61,7 @@ | |||
61 | "activationEvents": [ | 61 | "activationEvents": [ |
62 | "onLanguage:rust", | 62 | "onLanguage:rust", |
63 | "onCommand:rust-analyzer.analyzerStatus", | 63 | "onCommand:rust-analyzer.analyzerStatus", |
64 | "onCommand:rust-analyzer.memoryUsage", | ||
64 | "onCommand:rust-analyzer.reloadWorkspace", | 65 | "onCommand:rust-analyzer.reloadWorkspace", |
65 | "workspaceContains:**/Cargo.toml" | 66 | "workspaceContains:**/Cargo.toml" |
66 | ], | 67 | ], |
@@ -143,6 +144,11 @@ | |||
143 | "category": "Rust Analyzer" | 144 | "category": "Rust Analyzer" |
144 | }, | 145 | }, |
145 | { | 146 | { |
147 | "command": "rust-analyzer.memoryUsage", | ||
148 | "title": "Memory Usage (Clears Database)", | ||
149 | "category": "Rust Analyzer" | ||
150 | }, | ||
151 | { | ||
146 | "command": "rust-analyzer.reloadWorkspace", | 152 | "command": "rust-analyzer.reloadWorkspace", |
147 | "title": "Reload workspace", | 153 | "title": "Reload workspace", |
148 | "category": "Rust Analyzer" | 154 | "category": "Rust Analyzer" |
@@ -844,6 +850,10 @@ | |||
844 | "when": "inRustProject" | 850 | "when": "inRustProject" |
845 | }, | 851 | }, |
846 | { | 852 | { |
853 | "command": "rust-analyzer.memoryUsage", | ||
854 | "when": "inRustProject" | ||
855 | }, | ||
856 | { | ||
847 | "command": "rust-analyzer.reloadWorkspace", | 857 | "command": "rust-analyzer.reloadWorkspace", |
848 | "when": "inRustProject" | 858 | "when": "inRustProject" |
849 | }, | 859 | }, |
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 19a9c2a0d..1f3a7cf7e 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -55,6 +55,38 @@ export function analyzerStatus(ctx: Ctx): Cmd { | |||
55 | }; | 55 | }; |
56 | } | 56 | } |
57 | 57 | ||
58 | export function memoryUsage(ctx: Ctx): Cmd { | ||
59 | const tdcp = new class implements vscode.TextDocumentContentProvider { | ||
60 | readonly uri = vscode.Uri.parse('rust-analyzer-memory://memory'); | ||
61 | readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); | ||
62 | |||
63 | provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> { | ||
64 | if (!vscode.window.activeTextEditor) return ''; | ||
65 | |||
66 | return ctx.client.sendRequest(ra.memoryUsage, null).then((mem) => { | ||
67 | return 'Per-query memory usage:\n' + mem + '\n(note: database has been cleared)'; | ||
68 | }); | ||
69 | } | ||
70 | |||
71 | get onDidChange(): vscode.Event<vscode.Uri> { | ||
72 | return this.eventEmitter.event; | ||
73 | } | ||
74 | }(); | ||
75 | |||
76 | ctx.pushCleanup( | ||
77 | vscode.workspace.registerTextDocumentContentProvider( | ||
78 | 'rust-analyzer-memory', | ||
79 | tdcp, | ||
80 | ), | ||
81 | ); | ||
82 | |||
83 | return async () => { | ||
84 | tdcp.eventEmitter.fire(tdcp.uri); | ||
85 | const document = await vscode.workspace.openTextDocument(tdcp.uri); | ||
86 | return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true); | ||
87 | }; | ||
88 | } | ||
89 | |||
58 | export function matchingBrace(ctx: Ctx): Cmd { | 90 | export function matchingBrace(ctx: Ctx): Cmd { |
59 | return async () => { | 91 | return async () => { |
60 | const editor = ctx.activeRustEditor; | 92 | const editor = ctx.activeRustEditor; |
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index bf4703239..5f32cb40e 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts | |||
@@ -5,6 +5,7 @@ | |||
5 | import * as lc from "vscode-languageclient"; | 5 | import * as lc from "vscode-languageclient"; |
6 | 6 | ||
7 | export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); | 7 | export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); |
8 | export const memoryUsage = new lc.RequestType<null, string, void>("rust-analyzer/memoryUsage"); | ||
8 | 9 | ||
9 | export type Status = "loading" | "ready" | "invalid" | "needsReload"; | 10 | export type Status = "loading" | "ready" | "invalid" | "needsReload"; |
10 | export const status = new lc.NotificationType<Status>("rust-analyzer/status"); | 11 | export const status = new lc.NotificationType<Status>("rust-analyzer/status"); |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 4b990afa1..eda95ae5c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -96,6 +96,7 @@ async function tryActivate(context: vscode.ExtensionContext) { | |||
96 | }); | 96 | }); |
97 | 97 | ||
98 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 98 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
99 | ctx.registerCommand('memoryUsage', commands.memoryUsage); | ||
99 | ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace); | 100 | ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace); |
100 | ctx.registerCommand('matchingBrace', commands.matchingBrace); | 101 | ctx.registerCommand('matchingBrace', commands.matchingBrace); |
101 | ctx.registerCommand('joinLines', commands.joinLines); | 102 | ctx.registerCommand('joinLines', commands.joinLines); |