Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

build/

# Mono auto generated files
mono_crash.*

Expand Down
25 changes: 21 additions & 4 deletions dotnetInsights/src/DotnetInsightsRuntimeLoadEventsEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { JitMethodInfo, ProcessInfo, GcListener } from "./GcListener";

import { DotnetInsightsGcDocument } from "./DotnetInsightsGcEditor";

export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomReadonlyEditorProvider {
export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomEditorProvider {
public static register(context: vscode.ExtensionContext, insights: DotnetInsights): vscode.Disposable {
const provider = new DotnetInsightsRuntimeLoadEventsEditor(context, insights, null, insights.listener!);
const providerRegistration = vscode.window.registerCustomEditorProvider(DotnetInsightsRuntimeLoadEventsEditor.viewType, provider);
Expand All @@ -34,6 +34,23 @@ export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomReado
this.processName = "";
}

onDidChangeCustomDocument() : any {

}

saveCustomDocument(document: vscode.CustomDocument, cancellation: vscode.CancellationToken): Thenable<void> {
throw new Error("Method not implemented.");
}
saveCustomDocumentAs(document: vscode.CustomDocument, destination: vscode.Uri, cancellation: vscode.CancellationToken): Thenable<void> {
throw new Error("Method not implemented.");
}
revertCustomDocument(document: vscode.CustomDocument, cancellation: vscode.CancellationToken): Thenable<void> {
throw new Error("Method not implemented.");
}
backupCustomDocument(document: vscode.CustomDocument, context: vscode.CustomDocumentBackupContext, cancellation: vscode.CancellationToken): Thenable<vscode.CustomDocumentBackup> {
throw new Error("Method not implemented.");
}

openCustomDocument(uri: vscode.Uri, openContext: vscode.CustomDocumentOpenContext, token: vscode.CancellationToken): vscode.CustomDocument | Thenable<vscode.CustomDocument> {
var filename = path.basename(uri.path);
var endofLine = os.platform() === "win32" ? vscode.EndOfLine.CRLF : vscode.EndOfLine.LF;
Expand Down Expand Up @@ -639,7 +656,7 @@ export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomReado

var evenOdd = index % 2 == 0 ? "even" : "odd";

data += `<tr class=${evenOdd}><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
data += `<tr class=${evenOdd}><td>${dataAtIndex.methodId}</td><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
}

data += `</table>`;
Expand Down Expand Up @@ -669,7 +686,7 @@ export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomReado
var dataAtIndex : JitMethodInfo = tierZeroLoadTimes[index];
var evenOdd = index % 2 == 0 ? "even" : "odd";

data += `<tr class=${evenOdd}><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
data += `<tr class=${evenOdd}><td>${dataAtIndex.methodId}</td><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
}

data += `</table>`;
Expand Down Expand Up @@ -699,7 +716,7 @@ export class DotnetInsightsRuntimeLoadEventsEditor implements vscode.CustomReado
var dataAtIndex : JitMethodInfo = tierOneLoadTimes[index];
var evenOdd = index % 2 == 0 ? "even" : "odd";

data += `<tr class=${evenOdd}><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
data += `<tr class=${evenOdd}><td>${dataAtIndex.methodId}</td><td class="left-align">${dataAtIndex.methodName}</td><td>${dataAtIndex.loadDuration}</td>`;
}

data += `</table>`;
Expand Down
17 changes: 17 additions & 0 deletions dotnetInsights/src/GcListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DotnetInsightsGcTreeDataProvider } from "./dotnetInsightsGc";
import { createServer } from "http";
import { IncomingMessage, ServerResponse } from 'http';
import { DotnetInsightsJitTreeDataProvider } from "./dotnetInsightsJit";
import { Profiler } from "./Profiler";

export class GcData {
public data: any;
Expand Down Expand Up @@ -178,6 +179,8 @@ export class GcListener {

public sendShutdown: boolean;

public profiler: Profiler | undefined;

public requests: number;
public secondTimer: any;

Expand All @@ -194,6 +197,8 @@ export class GcListener {
console.log(`Requests per second: ${this.requests}`);
this.requests = 0;
}, 1000);

this.profiler = Profiler.getInstance(10);
}

start() {
Expand All @@ -218,6 +223,7 @@ export class GcListener {
}
catch(e) {
response.end("eol");
return;
}

if (jsonData == undefined) {
Expand All @@ -228,6 +234,17 @@ export class GcListener {
console.log(request.url);
const isAllocData = request.url == "/gcAllocation";
const isJitEvent = request.url == "/jitEvent";
const isProfilerEvent = request.url == "/profiler";

if (isProfilerEvent) {
const profilerData = jsonData;
console.assert(this.profiler != undefined);

this.profiler?.addData(profilerData);

response.end("eol");
return;
}

var processById: ProcessInfo | undefined = this.processes.get(jsonData["ProcessID"]);

Expand Down
88 changes: 88 additions & 0 deletions dotnetInsights/src/Profiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
////////////////////////////////////////////////////////////////////////////////
// Module: Profiler.ts
////////////////////////////////////////////////////////////////////////////////

import { time } from "console";

export class ProfilerEvent {
////////////////////////////////////////////////////////////////////////////
// Member variables
////////////////////////////////////////////////////////////////////////////

private methodName: string;
private methodId: number;
private timeInMethod: number;
private timestamp: number;

////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////

constructor(methodName: string, methodId: number, timeInMethod: number) {
this.methodName = methodName;
this.methodId = methodId;
this.timeInMethod = timeInMethod;
this.timestamp = Date.now();
}
}

export class Profiler {
////////////////////////////////////////////////////////////////////////////
// Member variables
////////////////////////////////////////////////////////////////////////////

private static instance: Profiler | undefined | null;
private pid: number;
private data: ProfilerEvent[];

private methodMap: Map<string, Map<number, number>>;

////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////

private constructor(pid: number) {
this.data = [] as ProfilerEvent[];
this.methodMap = new Map<string, Map<number, number>>();

this.pid = pid;
}

////////////////////////////////////////////////////////////////////////////
// Member methods
////////////////////////////////////////////////////////////////////////////

public addData(jsonData: any) {
const methodName = jsonData["methodName"];
const methodId = jsonData["id"];
const timeInMethod = jsonData["time"];

const profilerEvent = new ProfilerEvent(methodName, methodId, timeInMethod);
this.data.push(profilerEvent);

var methodByProfilerFunctionId: Map<number, number> | undefined = undefined;
if (this.methodMap.has(methodName))
{
methodByProfilerFunctionId = this.methodMap.get(methodName);
}
else {
methodByProfilerFunctionId = new Map<number, number>();
}

if (methodByProfilerFunctionId?.has(methodId)) {
const previousValue = methodByProfilerFunctionId.get(methodId);
methodByProfilerFunctionId.set(methodId, previousValue + timeInMethod);
}
else {
methodByProfilerFunctionId?.set(methodId, timeInMethod);
}
}

public static getInstance(pid: number): Profiler {
if (Profiler.instance == null || Profiler.instance == undefined || Profiler.instance.pid !== pid) {
Profiler.instance = new Profiler(pid);
}

return Profiler.instance;
}
}
82 changes: 82 additions & 0 deletions profiler/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "native_profiler",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}\\..\\..\\runtime\\artifacts\\tests\\coreclr\\windows.x64.Debug\\Tests\\Core_Root\\CoreRun.exe",
"args": [
"${workspaceRoot}\\tests\\bringup\\jit_compilation\\bin\\Debug\\net6.0\\jit_compilation.dll"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [
{
"name": "CORECLR_PROFILER_PATH",
"value": "${workspaceRoot}\\native\\build\\Debug\\ev31_profiler.dll"
},
{
"name": "CORECLR_PROFILER",
"value": "{cf0d821e-299b-5307-a3d8-b283c03916dd}"
},
{
"name": "CORECLR_ENABLE_PROFILING",
"value": "1"
}
],
"console": "internalConsole"
},
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/Users/jashoo/Library/Application Support/Code/User/globalStorage/jashoo.dotnetinsights/coreRoot/net5.0/Core_Root/corerun",
"args": [
"/Users/jashoo/projects/temp/bin/Release/net5.0/temp.dll"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [
{
"name": "CORECLR_PROFILER_PATH",
"value": "/Users/jashoo/projects/vscode-dotnet-insights/profiler/native/build/libev31_profiler.dylib"
},
{
"name": "CORECLR_PROFILER",
"value": "{cf0d821e-299b-5307-a3d8-b283c03916dd}"
},
{
"name": "CORECLR_ENABLE_PROFILING",
"value": "1"
}
],
"externalConsole": false,
"MIMode": "lldb"
},
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/managed/bin/Debug/net5.0/profiler.dll",
"args": [
"-pid",
"88850"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
75 changes: 75 additions & 0 deletions profiler/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"cmake.sourceDirectory": "${workspaceFolder}/native",
"files.associations": {
"atomic": "cpp",
"algorithm": "cpp",
"array": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"format": "cpp",
"forward_list": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"functional": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"mutex": "cpp",
"stop_token": "cpp",
"thread": "cpp"
}
}
Loading