Skip to content

Commit 4f8c372

Browse files
committed
move gcprofiler code (now in serve-d)
1 parent 438b7fb commit 4f8c372

File tree

3 files changed

+25
-93
lines changed

3 files changed

+25
-93
lines changed

src/dmode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const DSCRIPT_MODE: vscode.DocumentFilter = { language: "dscript", scheme
66
export const SDL_MODE: vscode.DocumentFilter = { language: "sdl", scheme: "file" };
77
export const DUB_MODE: vscode.DocumentFilter = { pattern: "**/dub.{sdl,json}", scheme: "file" };
88
export const DSCANNER_INI_MODE: vscode.DocumentFilter = { pattern: "**/dscanner.ini", scheme: "file" };
9-
export const DIET_MODE: vscode.DocumentFilter = { language: "diet", scheme: "file" };
9+
export const DIET_MODE: vscode.DocumentFilter = { language: "diet", scheme: "file" };
10+
export const PROFILEGC_MODE: vscode.DocumentFilter = { pattern: "**/profilegc.log", scheme: "file" };

src/extension.ts

+7-19
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ function startClient(context: vscode.ExtensionContext) {
210210
};
211211
var outputChannel = vscode.window.createOutputChannel("code-d & serve-d");
212212
let clientOptions: LanguageClientOptions = {
213-
documentSelector: <DocumentFilter[]>[mode.D_MODE, mode.DUB_MODE, mode.DIET_MODE, mode.DML_MODE, mode.DSCANNER_INI_MODE],
213+
documentSelector: <DocumentFilter[]>[mode.D_MODE, mode.DUB_MODE, mode.DIET_MODE, mode.DML_MODE, mode.DSCANNER_INI_MODE, mode.PROFILEGC_MODE],
214214
synchronize: {
215215
configurationSection: ["d", "dfmt", "dscanner", "editor", "git"],
216216
fileEvents: [
217217
vscode.workspace.createFileSystemWatcher("**/*.d"),
218218
vscode.workspace.createFileSystemWatcher("**/dub.json"),
219-
vscode.workspace.createFileSystemWatcher("**/dub.sdl")
219+
vscode.workspace.createFileSystemWatcher("**/dub.sdl"),
220+
vscode.workspace.createFileSystemWatcher("**/profilegc.log")
220221
]
221222
},
222223
revealOutputChannelOn: RevealOutputChannelOn.Never,
@@ -412,24 +413,11 @@ export function activate(context: vscode.ExtensionContext): CodedAPI {
412413

413414
registerDebuggers(context);
414415

415-
if (vscode.workspace.workspaceFolders) {
416-
{
417-
let gcprofiler = new GCProfiler();
418-
vscode.languages.registerCodeLensProvider(mode.D_MODE, gcprofiler);
419-
420-
let watcher = vscode.workspace.createFileSystemWatcher("**/profilegc.log", false, false, false);
421-
422-
watcher.onDidCreate(gcprofiler.updateProfileCache, gcprofiler, context.subscriptions);
423-
watcher.onDidChange(gcprofiler.updateProfileCache, gcprofiler, context.subscriptions);
424-
watcher.onDidDelete(gcprofiler.clearProfileCache, gcprofiler, context.subscriptions);
425-
context.subscriptions.push(watcher);
426-
427-
let profileGCPath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "profilegc.log");
428-
if (fs.existsSync(profileGCPath))
429-
gcprofiler.updateProfileCache(vscode.Uri.file(profileGCPath));
416+
{
417+
context.subscriptions.push(vscode.commands.registerCommand("code-d.showGCCalls", GCProfiler.listProfileCache));
418+
}
430419

431-
context.subscriptions.push(vscode.commands.registerCommand("code-d.showGCCalls", gcprofiler.listProfileCache, gcprofiler));
432-
}
420+
if (vscode.workspace.workspaceFolders) {
433421
{
434422
let coverageanal = new CoverageAnalyzer();
435423
context.subscriptions.push(coverageanal);

src/gcprofiler.ts

+16-73
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,29 @@
11
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";
83

94
interface ProfileQuickPick extends vscode.QuickPickItem {
10-
profile: any;
5+
uri: string;
6+
line: number;
117
}
128

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");
6412

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+
}));
6821

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-
});
7922
vscode.window.showQuickPick(items).then(item => {
8023
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 => {
8225
vscode.window.showTextDocument(doc).then(editor => {
83-
let line = doc.lineAt(item.profile.line - 1);
26+
let line = doc.lineAt(item.line - 1);
8427
editor.revealRange(line.range, vscode.TextEditorRevealType.InCenterIfOutsideViewport);
8528
editor.selection = new vscode.Selection(line.range.start, line.range.start);
8629
});

0 commit comments

Comments
 (0)