|
1 | 1 | import * as vscode from "vscode";
|
2 |
| -import * as fs from "fs"; |
3 |
| -import * as path from "path"; |
4 |
| -import { config } from "./extension"; |
5 |
| - |
6 |
| -var spaces = /[^\S\n]+/g; |
7 |
| -var filelineRegex = /(\S+):(\d+)$/; |
| 2 | +import { served } from "./extension"; |
8 | 3 |
|
9 | 4 | interface ProfileQuickPick extends vscode.QuickPickItem {
|
10 |
| - profile: any; |
| 5 | + uri: string; |
| 6 | + line: number; |
11 | 7 | }
|
12 | 8 |
|
13 |
| -export class GCProfiler implements vscode.CodeLensProvider { |
14 |
| - provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] { |
15 |
| - if (!config(document.uri).get("enableGCProfilerDecorations", true)) |
16 |
| - return []; |
17 |
| - |
18 |
| - var lenses: vscode.CodeLens[] = []; |
19 |
| - this.profiles.forEach(profile => { |
20 |
| - if (document.uri.fsPath == vscode.Uri.parse(profile.file).fsPath) { |
21 |
| - var lens = new vscode.CodeLens(document.lineAt(profile.line - 1).range); |
22 |
| - lens.command = { |
23 |
| - arguments: [], |
24 |
| - command: "", |
25 |
| - title: profile.bytesAllocated + " bytes allocated / " + profile.allocationCount + " allocations" |
26 |
| - }; |
27 |
| - lenses.push(lens); |
28 |
| - } |
29 |
| - }); |
30 |
| - return lenses; |
31 |
| - } |
32 |
| - |
33 |
| - updateProfileCache(uri: vscode.Uri) { |
34 |
| - var root = "."; |
35 |
| - var workspace = vscode.workspace.getWorkspaceFolder(uri); |
36 |
| - if (workspace) |
37 |
| - root = workspace.uri.path; |
38 |
| - fs.readFile(uri.fsPath, (err, data) => { |
39 |
| - this.profiles = []; |
40 |
| - var lines = data.toString("utf8").split("\n"); |
41 |
| - for (var i = 1; i < lines.length; i++) { |
42 |
| - var cols = lines[i].trim().split(spaces); |
43 |
| - if (cols.length < 5) |
44 |
| - continue; |
45 |
| - var fileLine = cols.slice(4, cols.length).join(""); |
46 |
| - var match = filelineRegex.exec(lines[i]); |
47 |
| - if (match) { |
48 |
| - var file = match[1]; |
49 |
| - var displayFile = file; |
50 |
| - if (!path.isAbsolute(file)) |
51 |
| - file = path.join(root, file); |
52 |
| - this.profiles.push({ |
53 |
| - bytesAllocated: cols[0], |
54 |
| - allocationCount: cols[1], |
55 |
| - type: cols[2], |
56 |
| - file: file, |
57 |
| - displayFile: displayFile, |
58 |
| - line: parseInt(match[2]) |
59 |
| - }); |
60 |
| - } |
61 |
| - } |
62 |
| - }); |
63 |
| - } |
| 9 | +export class GCProfiler { |
| 10 | + static listProfileCache() { |
| 11 | + let entriesPromise = served.client.sendRequest<any[]>("served/getProfileGCEntries"); |
64 | 12 |
|
65 |
| - clearProfileCache() { |
66 |
| - this.profiles = []; |
67 |
| - } |
| 13 | + let items: Thenable<ProfileQuickPick[]> = entriesPromise.then(gcEntries => |
| 14 | + gcEntries.map(entry => <ProfileQuickPick>{ |
| 15 | + description: entry.type, |
| 16 | + detail: entry.bytesAllocated + " bytes allocated / " + entry.allocationCount + " allocations", |
| 17 | + label: entry.displayFile + ":" + entry.line, |
| 18 | + uri: entry.uri, |
| 19 | + line: entry.line |
| 20 | + })); |
68 | 21 |
|
69 |
| - listProfileCache() { |
70 |
| - let items: ProfileQuickPick[] = []; |
71 |
| - this.profiles.forEach(profile => { |
72 |
| - items.push({ |
73 |
| - description: profile.type, |
74 |
| - detail: profile.bytesAllocated + " bytes allocated / " + profile.allocationCount + " allocations", |
75 |
| - label: profile.displayFile + ":" + profile.line, |
76 |
| - profile: profile |
77 |
| - }); |
78 |
| - }); |
79 | 22 | vscode.window.showQuickPick(items).then(item => {
|
80 | 23 | if (item)
|
81 |
| - vscode.workspace.openTextDocument(vscode.Uri.file(item.profile.file)).then(doc => { |
| 24 | + vscode.workspace.openTextDocument(vscode.Uri.parse(item.uri)).then(doc => { |
82 | 25 | vscode.window.showTextDocument(doc).then(editor => {
|
83 |
| - let line = doc.lineAt(item.profile.line - 1); |
| 26 | + let line = doc.lineAt(item.line - 1); |
84 | 27 | editor.revealRange(line.range, vscode.TextEditorRevealType.InCenterIfOutsideViewport);
|
85 | 28 | editor.selection = new vscode.Selection(line.range.start, line.range.start);
|
86 | 29 | });
|
|
0 commit comments