@@ -4,7 +4,8 @@ import { decimal } from "vscode-languageclient";
44import { Settings } from "../../../../settings" ;
55import { WebViewUris } from "../../../webViewUtils" ;
66import { Duration } from "../CommonInsightObjects" ;
7- import { SpanDurationsInsight } from "../SpanInsight" ;
7+ import { CodeObjectId } from "../../../../services/codeObject" ;
8+ import { SpanDurationsInsight , ChildSpanDurationsInsight , ChildrenSpanDurationsInsight } from "../SpanInsight" ;
89import { InsightTemplateHtml } from "./insightTemplateHtml" ;
910
1011export class SpanItemHtmlRendering {
@@ -42,8 +43,9 @@ export class SpanItemHtmlRendering{
4243
4344 private findByPercentileAndPeriod ( insight : SpanDurationsInsight , percentile : number , period :string ) {
4445
45- return insight . periodicPercentiles . filter ( x => x . percentile === percentile && period === period ) . firstOrDefault ( ) ?. currentDuration . value ;
46+ return insight . periodicPercentiles ? .filter ( x => x . percentile === percentile && period === period ) . firstOrDefault ( ) ?. currentDuration . value ;
4647 }
48+
4749 public spanDurationItemHtml ( insight : SpanDurationsInsight ) : InsightTemplateHtml {
4850
4951 const percentileHtmls = [ ] ;
@@ -159,4 +161,74 @@ export class SpanItemHtmlRendering{
159161 } ) ;
160162 }
161163
162- }
164+ private getUniquePercentiles ( insight : ChildrenSpanDurationsInsight ) : Set < number > {
165+ const setOfNumbers : Set < number > = new Set ( ) ;
166+ setOfNumbers . add ( 0.50 ) ; // make sure at least one entry is there - P50
167+
168+ for ( const childInsight of insight . childInsights ) {
169+ for ( const pctl of childInsight . percentiles ) {
170+ setOfNumbers . add ( pctl . percentile ) ;
171+ }
172+ }
173+ const sortedArray = [ ...setOfNumbers ] . sort ( ( a , b ) => a - b ) ;
174+ const sortedSet = new Set ( sortedArray ) ;
175+
176+ return sortedSet ;
177+ }
178+
179+ private getValueOfPercentile ( insight : ChildSpanDurationsInsight , requestedPercentile : number ) : string {
180+ for ( const pctl of insight . percentiles ) {
181+ if ( pctl . percentile === requestedPercentile ) {
182+ return `${ pctl . currentDuration . value } ${ pctl . currentDuration . unit } ` ;
183+ }
184+ }
185+ return "" ;
186+ }
187+
188+ public childrenSpanDurationItemHtml ( insight : ChildrenSpanDurationsInsight ) : InsightTemplateHtml {
189+
190+ const htmlRecords : string [ ] = [ ] ;
191+
192+ const percentilesSet = this . getUniquePercentiles ( insight ) ;
193+
194+ for ( const childInsight of insight . childInsights ) {
195+ const spanName = CodeObjectId . getSpanName ( childInsight . codeObjectId ) ;
196+ const pctlHtmlColumns : string [ ] = [ ] ;
197+ for ( const pctl of percentilesSet ) {
198+ const pctlValue = this . getValueOfPercentile ( childInsight , pctl ) ;
199+ pctlHtmlColumns . push ( /*html*/ `<td>${ pctlValue } </td>` ) ;
200+ }
201+ const htmlRecord : string = /*html*/ `
202+ <tr>
203+ <td>${ spanName } </td>
204+ ${ pctlHtmlColumns . join ( '' ) }
205+ </tr>` ;
206+
207+ htmlRecords . push ( htmlRecord ) ;
208+ }
209+
210+ const tableHeaders : string [ ] = [ ] ;
211+ for ( const percentile of percentilesSet ) {
212+ tableHeaders . push ( /*html*/ `<th>P${ percentile * 100 } </th>` ) ;
213+ }
214+
215+ const body = /*html*/ `
216+ <div class="span-durations-insight-body">
217+ <table>
218+ <tr>
219+ <th>Child Span</th>
220+ ${ tableHeaders . join ( '' ) }
221+ </tr>
222+ ${ htmlRecords . join ( '' ) }
223+ </table>
224+ </div>` ;
225+
226+ return new InsightTemplateHtml ( {
227+ title : "Durations of children" ,
228+ body : body ,
229+ icon : this . _viewUris . image ( "duration.svg" ) ,
230+ buttons : [ ]
231+ } ) ;
232+ }
233+
234+ }
0 commit comments