Skip to content

Commit 108e0f9

Browse files
committed
refactor: core and table
1 parent f2f6b5b commit 108e0f9

31 files changed

+414
-364
lines changed
File renamed without changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import { Protocol as Cdp } from 'devtools-protocol';
6+
import { ISourceLocation } from '../location-mapping';
7+
8+
/**
9+
* Category of call frames. Grouped into system, modules, and user code.
10+
*/
11+
export const enum Category {
12+
System,
13+
User,
14+
Module,
15+
Deemphasized,
16+
}
17+
18+
export interface INode {
19+
id: number;
20+
category: Category;
21+
callFrame: Cdp.Runtime.CallFrame;
22+
}
23+
24+
export interface IGraphNode extends INode {
25+
children: { [id: number]: IGraphNode };
26+
childrenSize: number;
27+
parent?: IGraphNode;
28+
}
29+
30+
/**
31+
* Categorizes the given call frame.
32+
*/
33+
export const categorize = (callFrame: Cdp.Runtime.CallFrame, src: ISourceLocation | undefined) => {
34+
callFrame.functionName = callFrame.functionName || '(anonymous)';
35+
if (callFrame.lineNumber < 0) {
36+
return Category.System;
37+
}
38+
39+
if (callFrame.url.includes('node_modules') || !src) {
40+
return Category.Module;
41+
}
42+
43+
return Category.User;
44+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import { Protocol as Cdp } from 'devtools-protocol';
6+
import { ISourceLocation } from '../location-mapping';
7+
8+
/**
9+
* Request from the webview to open a document
10+
*/
11+
export interface IOpenDocumentMessage {
12+
type: 'openDocument';
13+
location?: ISourceLocation;
14+
callFrame?: Cdp.Runtime.CallFrame;
15+
toSide: boolean;
16+
}
17+
18+
/**
19+
* Reopens the current document with the given editor, optionally only if
20+
* the given extension is installed.
21+
*/
22+
export interface IReopenWithEditor {
23+
type: 'reopenWith';
24+
viewType: string;
25+
requireExtension?: string;
26+
}
27+
28+
export type Message = IOpenDocumentMessage | IReopenWithEditor;

packages/vscode-js-profile-core/src/cpu/bottomUpGraph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5-
import { ILocation, IProfileModel, IComputedNode, IGraphNode, Category } from './model';
5+
import { Category } from '../common/model';
6+
import { IComputedNode, IGraphNode, ILocation, IProfileModel } from './model';
67

78
export class BottomUpNode implements IGraphNode {
89
public static root() {

packages/vscode-js-profile-core/src/cpu/editorProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
import * as vscode from 'vscode';
66
import { bundlePage } from '../bundlePage';
7+
import { Message } from '../common/types';
78
import { openLocation } from '../open-location';
89
import { ProfileAnnotations } from '../profileAnnotations';
910
import { ProfileCodeLensProvider } from '../profileCodeLensProvider';
1011
import { ReadonlyCustomDocument } from '../readonly-custom-document';
1112
import { reopenWithEditor } from '../reopenWithEditor';
1213
import { buildModel, IProfileModel } from './model';
13-
import { ICpuProfileRaw, Message } from './types';
14+
import { ICpuProfileRaw } from './types';
1415

1516
export class CpuProfileEditorProvider
16-
implements vscode.CustomEditorProvider<ReadonlyCustomDocument<IProfileModel>> {
17+
implements vscode.CustomEditorProvider<ReadonlyCustomDocument<IProfileModel>>
18+
{
1719
public readonly onDidChangeCustomDocument = new vscode.EventEmitter<never>().event;
1820

1921
constructor(

packages/vscode-js-profile-core/src/cpu/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import { ComponentType, Fragment, FunctionComponent, h } from 'preact';
55
import { useMemo, useState } from 'preact/hooks';
66
import { richFilter, RichFilterComponent } from '../client/rich-filter';
7+
import styles from '../common/layout.css';
78
import { IDataSource, IQueryResults } from '../ql';
8-
import styles from './layout.css';
99

1010
export interface IBodyProps<T> {
1111
data: IQueryResults<T>;

packages/vscode-js-profile-core/src/cpu/model.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,10 @@
33
*--------------------------------------------------------*/
44

55
import { Protocol as Cdp } from 'devtools-protocol';
6-
import { ICpuProfileRaw, IAnnotationLocation } from './types';
6+
import { categorize, INode } from '../common/model';
7+
import { addRelativeDiskPath, ISourceLocation } from '../location-mapping';
78
import { maybeFileUrlToPath } from '../path';
8-
import { ISourceLocation, addRelativeDiskPath } from '../location-mapping';
9-
10-
/**
11-
* Category of call frames. Grouped into system, modules, and user code.
12-
*/
13-
export const enum Category {
14-
System,
15-
User,
16-
Module,
17-
Deemphasized,
18-
}
9+
import { IAnnotationLocation, ICpuProfileRaw } from './types';
1910

2011
/**
2112
* One measured node in the call stack. Contains the time it spent in itself,
@@ -34,13 +25,10 @@ export interface IComputedNode {
3425
/**
3526
* One location in the source. Multiple nodes can reference a single location.
3627
*/
37-
export interface ILocation {
38-
id: number;
28+
export interface ILocation extends INode {
3929
selfTime: number;
4030
aggregateTime: number;
4131
ticks: number;
42-
category: Category;
43-
callFrame: Cdp.Runtime.CallFrame;
4432
src?: ISourceLocation;
4533
}
4634

@@ -102,22 +90,6 @@ const getBestLocation = (
10290
return candidates[0];
10391
};
10492

105-
/**
106-
* Categorizes the given call frame.
107-
*/
108-
const categorize = (callFrame: Cdp.Runtime.CallFrame, src: ISourceLocation | undefined) => {
109-
callFrame.functionName = callFrame.functionName || '(anonymous)';
110-
if (callFrame.lineNumber < 0) {
111-
return Category.System;
112-
}
113-
114-
if (callFrame.url.includes('node_modules') || !src) {
115-
return Category.Module;
116-
}
117-
118-
return Category.User;
119-
};
120-
12193
/**
12294
* Ensures that all profile nodes have a location ID, setting them if they
12395
* aren't provided by default.

packages/vscode-js-profile-core/src/cpu/types.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,3 @@ export interface ICpuProfileRaw extends Cdp.Profiler.Profile {
4949
$vscode?: IJsDebugAnnotations;
5050
nodes: IProfileNode[];
5151
}
52-
53-
/**
54-
* Request from the webview to open a document
55-
*/
56-
export interface IOpenDocumentMessage {
57-
type: 'openDocument';
58-
location?: ISourceLocation;
59-
callFrame?: Cdp.Runtime.CallFrame;
60-
toSide: boolean;
61-
}
62-
63-
/**
64-
* Reopens the current document with the given editor, optionally only if
65-
* the given extension is installed.
66-
*/
67-
export interface IReopenWithEditor {
68-
type: 'reopenWith';
69-
viewType: string;
70-
requireExtension?: string;
71-
}
72-
73-
export type Message = IOpenDocumentMessage | IReopenWithEditor;

packages/vscode-js-profile-core/src/heap/display.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { ITreeNode } from './model';
66

77
/**
8-
* Gets the human-readable label for the given location.
8+
* Gets the human-readable label for the given node.
99
*/
1010
export const getNodeText = (node: ITreeNode) => {
1111
if (!node.callFrame.url) {

packages/vscode-js-profile-core/src/heap/editorProvider.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
import * as vscode from 'vscode';
66
import { bundlePage } from '../bundlePage';
7-
import { ProfileAnnotations } from '../profileAnnotations';
7+
import { Message } from '../common/types';
8+
import { openLocation } from '../open-location';
89
import { ProfileCodeLensProvider } from '../profileCodeLensProvider';
910
import { ReadonlyCustomDocument } from '../readonly-custom-document';
1011
import { reopenWithEditor } from '../reopenWithEditor';
1112
import { buildModel, IProfileModel } from './model';
12-
import { IHeapProfileRaw, Message } from './types';
13+
import { IHeapProfileRaw } from './types';
1314

1415
export class HeapProfileEditorProvider
1516
implements vscode.CustomEditorProvider<ReadonlyCustomDocument<IProfileModel>>
@@ -30,7 +31,8 @@ export class HeapProfileEditorProvider
3031
const raw: IHeapProfileRaw = JSON.parse(new TextDecoder().decode(content));
3132
const document = new ReadonlyCustomDocument(uri, buildModel(raw));
3233

33-
const annotations = new ProfileAnnotations();
34+
// TODO: annotations
35+
// const annotations = new ProfileAnnotations();
3436
// const rootPath = document.userData.rootPath;
3537
// for (const location of document.userData.locations) {
3638
// annotations.add(rootPath, location);
@@ -50,12 +52,12 @@ export class HeapProfileEditorProvider
5052
webviewPanel.webview.onDidReceiveMessage((message: Message) => {
5153
switch (message.type) {
5254
case 'openDocument':
53-
// openLocation({
54-
// rootPath: document.userData?.rootPath,
55-
// viewColumn: message.toSide ? vscode.ViewColumn.Beside : vscode.ViewColumn.Active,
56-
// callFrame: message.callFrame,
57-
// location: message.location,
58-
// });
55+
openLocation({
56+
rootPath: undefined,
57+
viewColumn: message.toSide ? vscode.ViewColumn.Beside : vscode.ViewColumn.Active,
58+
callFrame: message.callFrame,
59+
location: message.location,
60+
});
5961
return;
6062
case 'reopenWith':
6163
reopenWithEditor(document.uri, message.viewType, message.requireExtension);

0 commit comments

Comments
 (0)