|
1 | | -import { nextTick } from 'process'; |
2 | 1 | import * as vscode from 'vscode'; |
3 | 2 | import { CodeInspector } from '../../../services/codeInspector'; |
4 | 3 | import { DocumentInfo, DocumentInfoProvider, LineInfo, MethodInfo } from '../../../services/documentInfoProvider'; |
@@ -42,7 +41,7 @@ export class PerformanceDecorator implements vscode.Disposable |
42 | 41 | this._disposables.push(vscode.commands.registerCommand(PerformanceDecorator.Commands.Hide, this.onHide.bind(this))); |
43 | 42 | } |
44 | 43 |
|
45 | | - private getDisplayDuration(totalDuration : number):string{ |
| 44 | +private getDisplayDuration(totalDuration : number):string{ |
46 | 45 |
|
47 | 46 | let rawValue = (totalDuration / 1000000); |
48 | 47 | let unit = "ms"; |
@@ -71,16 +70,35 @@ private getTotalDurationFromInsights(docInfo:DocumentInfo, method:MethodInfo) : |
71 | 70 | return; |
72 | 71 | } |
73 | 72 |
|
74 | | - const totalDuration = percentileInfo.filter(x=>x.percentile==0.5).map(x=>x.currentDuration.raw) |
| 73 | + const p50 = percentileInfo.filter(x=>x.percentile==0.5).map(x=>x.currentDuration.raw) |
75 | 74 | .reduce((acc, val)=>acc + val,0); |
76 | 75 |
|
77 | | - if (totalDuration===0){ |
| 76 | + if (p50===0){ |
78 | 77 | return; |
79 | 78 | } |
80 | 79 |
|
81 | | - return totalDuration; |
| 80 | + return p50; |
82 | 81 | } |
83 | 82 |
|
| 83 | + private getPerformanceIssues(docInfo:DocumentInfo, method:MethodInfo) : string{ |
| 84 | + |
| 85 | + const insights = docInfo.insights.forMethod(method,this._workspaceState.environment); |
| 86 | + |
| 87 | + if (insights.length==0){ |
| 88 | + return ""; |
| 89 | + } |
| 90 | + const criticcalInsights = insights.filter(x=>x.importance<4) |
| 91 | + .flatMap(x=>x.decorators).map(x=>x.title).join(" | "); |
| 92 | + |
| 93 | + if (!criticcalInsights){ |
| 94 | + return ""; |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | + return criticcalInsights; |
| 99 | + } |
| 100 | + |
| 101 | + |
84 | 102 | private async discoverIndirectDurationRecursive( document: vscode.TextDocument, |
85 | 103 | docInfo:DocumentInfo, |
86 | 104 | methodInfo: MethodInfo, |
@@ -152,6 +170,8 @@ private getTotalDurationFromInsights(docInfo:DocumentInfo, method:MethodInfo) : |
152 | 170 |
|
153 | 171 | let totalDuration : undefined | number = undefined; |
154 | 172 |
|
| 173 | + let issues: string = ""; |
| 174 | + |
155 | 175 | if (func.text === methodInfo.name && func.range === methodInfo.nameRange){ |
156 | 176 | totalDuration= this.getTotalDurationFromInsights(documentInfo,methodInfo); |
157 | 177 | } |
@@ -182,6 +202,7 @@ private getTotalDurationFromInsights(docInfo:DocumentInfo, method:MethodInfo) : |
182 | 202 | continue; |
183 | 203 | } |
184 | 204 | totalDuration = this.getTotalDurationFromInsights(remoteDoc, remoteMethodInfo); |
| 205 | + issues = this.getPerformanceIssues(remoteDoc, remoteMethodInfo); |
185 | 206 |
|
186 | 207 | if (!totalDuration){ |
187 | 208 |
|
@@ -214,7 +235,9 @@ private getTotalDurationFromInsights(docInfo:DocumentInfo, method:MethodInfo) : |
214 | 235 |
|
215 | 236 | const textLine = document.lineAt(func.range.start.line); |
216 | 237 |
|
217 | | - this.addPerformanceDecorator(totalDuration, decorators, new vscode.Range(textLine.range.end, textLine.range.end)); |
| 238 | + issues |
| 239 | + |
| 240 | + this.addPerformanceDecorator(totalDuration, decorators, new vscode.Range(textLine.range.end, textLine.range.end),issues); |
218 | 241 |
|
219 | 242 | } |
220 | 243 |
|
@@ -268,14 +291,21 @@ private getTotalDurationFromInsights(docInfo:DocumentInfo, method:MethodInfo) : |
268 | 291 | //editor.setDecorations(this._textDecorationType, textDecorationOptions); |
269 | 292 | } |
270 | 293 |
|
271 | | - private addPerformanceDecorator(totalDuration: number | undefined, decorators: vscode.DecorationOptions[], range: vscode.Range) { |
| 294 | + private addPerformanceDecorator(totalDuration: number | undefined, decorators: vscode.DecorationOptions[], range: vscode.Range,issues:string) { |
272 | 295 | if (totalDuration) { |
| 296 | + let color = 'gray'; |
| 297 | + if (issues){ |
| 298 | + |
| 299 | + color='orange'; |
| 300 | + } |
| 301 | + const duration = this.getDisplayDuration(totalDuration); |
273 | 302 | decorators.push({ |
274 | 303 | hoverMessage: "", |
275 | 304 | range: range, |
276 | 305 | renderOptions: { |
277 | 306 | after: { |
278 | | - contentText: this.getDisplayDuration(totalDuration) |
| 307 | + contentText: `${issues} ${duration}`, |
| 308 | + color: color |
279 | 309 | } |
280 | 310 | } |
281 | 311 | }); |
|
0 commit comments