11import * as vscode from 'vscode' ;
22import { DocumentInfoProvider , LineInfo } from '../../../services/documentInfoProvider' ;
33import { WorkspaceState } from '../../../state' ;
4+ import { SpanDurationsInsight } from '../InsightListView/SpanInsight' ;
45
56export class PerformanceDecorator implements vscode . Disposable
67{
@@ -13,7 +14,9 @@ export class PerformanceDecorator implements vscode.Disposable
1314 private _textDecorationType : vscode . TextEditorDecorationType ;
1415 private _disposables : vscode . Disposable [ ] = [ ] ;
1516
16- constructor ( private _documentInfoProvider : DocumentInfoProvider )
17+ constructor ( private _documentInfoProvider : DocumentInfoProvider ,
18+ private _workspaceState : WorkspaceState
19+ )
1720 {
1821 this . _iconDecorationType = vscode . window . createTextEditorDecorationType ( {
1922 after :{
@@ -34,11 +37,9 @@ export class PerformanceDecorator implements vscode.Disposable
3437 this . _disposables . push ( vscode . commands . registerCommand ( PerformanceDecorator . Commands . Hide , this . onHide . bind ( this ) ) ) ;
3538 }
3639
37- private async onShow ( codeObjectId ?: string )
40+ private async onShow ( )
3841 {
39- if ( ! codeObjectId )
40- return ;
41-
42+
4243 const editor = vscode . window . activeTextEditor ;
4344 if ( ! editor )
4445 return ;
@@ -47,35 +48,67 @@ export class PerformanceDecorator implements vscode.Disposable
4748 if ( ! docInfo )
4849 return ;
4950
50- const method = docInfo . methods . firstOrDefault ( m => m . symbol . id == codeObjectId ) ;
51- if ( ! method )
52- return ;
53-
54- const lines = docInfo . lines . getAllByCurrentEnv ( ) . filter ( l => method . range . contains ( l . range . start ) ) ;
55- if ( ! lines )
56- return ;
51+ let decorators : vscode . DecorationOptions [ ] = [ ] ;
52+
53+ for ( const method of docInfo . methods ) {
54+
55+ const insights = docInfo . insights . forMethod ( method , this . _workspaceState . environment )
56+ . filter ( x => x . name == "Performance Stats" ) ;
57+
58+ const percentileInfo = insights . map ( x => x as SpanDurationsInsight )
59+ . flatMap ( x => x . percentiles ) . filter ( x => x . currentDuration ) ;
60+
61+ const totalDuration = percentileInfo . filter ( x => x . percentile == 0.5 ) . map ( x => x . currentDuration . raw )
62+ . reduce ( ( acc , val ) => acc + val , 0 ) ;
5763
58- const textDecorationOptions : vscode . DecorationOptions [ ] = lines
59- . map ( lineInfo => {
60- return < vscode . DecorationOptions > {
61- hoverMessage : this . getTooltip ( lineInfo ) ,
64+ const lines = docInfo . lines . getAllByCurrentEnv ( ) . filter ( l => method . range . contains ( l . range . start ) ) ;
65+ for ( const lineInfo of lines ) {
66+ decorators . push ( {
67+ hoverMessage : "" ,
6268 range : new vscode . Range ( lineInfo . range . end , lineInfo . range . end ) ,
6369 renderOptions : {
6470 after :{
65- contentText : [ ... new Set ( lineInfo . exceptions . map ( e => e . type ) ) ] . join ( '\xB7' )
71+ contentText : `Duration: ${ totalDuration } `
6672 }
6773 }
68- }
69- } ) ;
70- const iconDecorationOptions = lines
71- . map ( lineInfo => {
72- return < vscode . DecorationOptions > {
73- range : new vscode . Range ( lineInfo . range . end , lineInfo . range . end ) ,
74- }
75- } ) ;
74+
75+ } )
76+ }
77+
78+
79+
80+ // hoverMessage: this.getTooltip(lineInfo),
81+ // range: new vscode.Range(lineInfo.range.end, lineInfo.range.end),
82+ // renderOptions: {
83+ // after:{
84+ // contentText: [...new Set( lineInfo.exceptions.map(e => e.type))].join('\xB7')
85+ // }
86+ // }
87+ // }
88+
89+ }
90+
91+ // const textDecorationOptions: vscode.DecorationOptions[] = lines
92+ // .map(lineInfo => {
93+ // return <vscode.DecorationOptions>{
94+ // hoverMessage: this.getTooltip(lineInfo),
95+ // range: new vscode.Range(lineInfo.range.end, lineInfo.range.end),
96+ // renderOptions: {
97+ // after:{
98+ // contentText: [...new Set( lineInfo.exceptions.map(e => e.type))].join('\xB7')
99+ // }
100+ // }
101+ // }
102+ // });
103+ // const iconDecorationOptions = lines
104+ // .map(lineInfo => {
105+ // return <vscode.DecorationOptions>{
106+ // range: new vscode.Range(lineInfo.range.end, lineInfo.range.end),
107+ // }
108+ // });
76109
77- editor . setDecorations ( this . _iconDecorationType , iconDecorationOptions ) ;
78- editor . setDecorations ( this . _textDecorationType , textDecorationOptions ) ;
110+ editor . setDecorations ( this . _iconDecorationType , decorators ) ;
111+ // editor.setDecorations(this._textDecorationType, textDecorationOptions);
79112 }
80113
81114 private async onHide ( )
0 commit comments