Skip to content

Commit 0c3d473

Browse files
authored
Added SpanDurationsInsight (#104)
1 parent 3cbe364 commit 0c3d473

File tree

4 files changed

+85
-11
lines changed

4 files changed

+85
-11
lines changed

src/services/languages/python/spanExtractor.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ export class PythonSpanExtractor implements ISpanExtractor {
7777
const tracerName = match[1];
7878

7979
let instLibraryOptions = []
80-
if (tracerName === '__name__' && mainDeclared ){
81-
instLibraryOptions.push('__main__');
82-
83-
let fileName = await this.extractNameTypeTrace(tracerDefinition.document.fileName);
80+
if (tracerName === '__name__'){
81+
if (mainDeclared)
82+
instLibraryOptions.push('__main__');
83+
84+
let fileName = await this.extractNameTypeTrace(tracerDefinition.document.uri.fsPath);
8485
instLibraryOptions.push(fileName );
8586
if (fileName.includes(".")){
8687
let unrootedForm = fileName.split(".").slice(1).join(".");
@@ -112,7 +113,7 @@ export class PythonSpanExtractor implements ISpanExtractor {
112113
const pythonFileSuffix = ".py";
113114
const specialFolders = ["venv","site-packages"];
114115

115-
let folder = vscode.workspace.workspaceFolders?.filter(f=>filePath.startsWith(f.uri.path))
116+
let folder = vscode.workspace.workspaceFolders?.filter(f=> filePath.startsWith(f.uri.fsPath))
116117
.map(f=>f.uri.path).firstOrDefault();
117118

118119
if (!folder){

src/views-ui/codeAnalytics/main.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ vscode-panel-view {
401401
}
402402
}
403403
}
404+
.span-durations-insight{
405+
.percentiles-grid{
406+
display: grid;
407+
justify-content: start;
408+
grid-template-columns: auto auto auto;
409+
column-gap: 10px;
410+
row-gap: 5px;
411+
}
412+
.bad-change{
413+
color: #f95959;
414+
}
415+
}
404416
.endpoint-bottleneck-insight{
405417
margin-top: 5px;
406418

src/views/codeAnalytics/InsightListView/SpanInsight.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { IListViewItem, IListViewItemBase, ListViewGroupItem } from "../../ListView/IListViewItem";
22
import { CodeObjectInfo } from "../codeAnalyticsView";
3+
import { Duration } from "./EndpointInsight";
34
import { CodeObjectInsight, IInsightListViewItemsCreator } from "./IInsightListViewItemsCreator";
45

5-
export interface SpanInsight extends CodeObjectInsight
6+
export interface SpanUsagesInsight extends CodeObjectInsight
67
{
78
span: string,
89
flows:{
@@ -19,9 +20,9 @@ export interface SpanInsight extends CodeObjectInsight
1920
lastServiceSpan: string | undefined
2021
}[]
2122
}
22-
export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
23+
export class SpanUsagesListViewItemsCreator implements IInsightListViewItemsCreator
2324
{
24-
public async create(scope: CodeObjectInfo, codeObjectsInsight: SpanInsight []): Promise<IListViewItemBase []>
25+
public async create(scope: CodeObjectInfo, codeObjectsInsight: SpanUsagesInsight []): Promise<IListViewItemBase []>
2526
{
2627
const groupedBySpan = codeObjectsInsight.groupBy(o => o.span);
2728
const listViewItems: IListViewItem [] = [];
@@ -36,7 +37,7 @@ export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
3637
return listViewItems;
3738
}
3839

39-
public createListViewItem(insight: SpanInsight) : IListViewItem
40+
public createListViewItem(insight: SpanUsagesInsight) : IListViewItem
4041
{
4142
// <span class="codicon codicon-server-process" style="margin-right: 3px;"></span>
4243
const usages = insight.flows.map(flow => {
@@ -94,6 +95,65 @@ export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
9495
}
9596
}
9697

98+
export interface SpanDurationsInsight extends CodeObjectInsight{
99+
span: string,
100+
percentiles: {
101+
percentile: number,
102+
change: number,
103+
latestDuration: Duration
104+
}[]
105+
}
106+
export class SpanDurationsListViewItemsCreator implements IInsightListViewItemsCreator{
107+
public async create(scope: CodeObjectInfo, codeObjectsInsight: SpanDurationsInsight[]): Promise<IListViewItemBase []>
108+
{
109+
const groupedBySpan = codeObjectsInsight.groupBy(o => o.span);
110+
const listViewItems: IListViewItem [] = [];
111+
for(let route in groupedBySpan)
112+
{
113+
const group = new SpanListViewGroupItem(route);
114+
group.sortIndex = 10;
115+
const items = groupedBySpan[route].map(o=>this.createListViewItem(o));
116+
group.addItems(...items);
117+
listViewItems.push(group);
118+
}
119+
return listViewItems;
120+
}
121+
122+
public createListViewItem(insight: SpanDurationsInsight) : IListViewItem
123+
{
124+
const percentileHtmls = []
125+
for(const item of insight.percentiles){
126+
const changeHtml = Math.abs(item.change*100).toFixed(0);
127+
128+
percentileHtmls.push(/*html*/ `<span>P${item.percentile}</span>`);
129+
percentileHtmls.push(/*html*/ `<span>${item.latestDuration.value} ${item.latestDuration.unit}</span>`);
130+
131+
if (item.change > 0.1)
132+
percentileHtmls.push(/*html*/ `<span class="bad-change">increased by ${changeHtml}%</span>`);
133+
else if (item.change < -0.1)
134+
percentileHtmls.push(/*html*/ `<span class="good-change">decreased by ${changeHtml}%</span>`);
135+
else
136+
percentileHtmls.push(/*html*/ `<span></span>`);
137+
}
138+
139+
const html = /*html*/ `
140+
<div class="list-item span-durations-insight">
141+
<div class="list-item-content-area">
142+
<div class="list-item-header"><strong>Duration</strong></div>
143+
<div class="percentiles-grid">
144+
${percentileHtmls.join('')}
145+
</div>
146+
</div>
147+
</div>`;
148+
149+
return {
150+
getHtml: ()=> html,
151+
sortIndex: 0,
152+
groupId: undefined
153+
};
154+
}
155+
}
156+
97157
export class SpanListViewGroupItem extends ListViewGroupItem
98158
{
99159
constructor(private span: string)

src/views/codeAnalytics/codeAnalyticsView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AnalyticsProvider } from "../../services/analyticsProvider";
1313
import { HotspotListViewItemsCreator } from "./InsightListView/HotspotInsight";
1414
import { ErrorsListViewItemsCreator } from "./InsightListView/ErrorsInsight";
1515
import { InsightListViewItemsCreator } from "./InsightListView/IInsightListViewItemsCreator";
16-
import { SpanListViewItemsCreator } from "./InsightListView/SpanInsight";
16+
import { SpanDurationsListViewItemsCreator, SpanUsagesListViewItemsCreator } from "./InsightListView/SpanInsight";
1717
import { HighUsageListViewItemsCreator, LowUsageListViewItemsCreator, NormalUsageListViewItemsCreator, SlowEndpointListViewItemsCreator, SlowestSpansListViewItemsCreator, UsageViewItemsTemplate } from "./InsightListView/EndpointInsight";
1818
import { Logger } from "../../services/logger";
1919

@@ -123,7 +123,8 @@ class CodeAnalyticsViewProvider implements vscode.WebviewViewProvider,vscode.Dis
123123
const listViewItemsCreator = new InsightListViewItemsCreator();
124124
listViewItemsCreator.add("HotSpot", new HotspotListViewItemsCreator(this._webViewUris));
125125
listViewItemsCreator.add("Errors", new ErrorsListViewItemsCreator());
126-
listViewItemsCreator.add("SpanUsages", new SpanListViewItemsCreator());
126+
listViewItemsCreator.add("SpanUsages", new SpanUsagesListViewItemsCreator());
127+
listViewItemsCreator.add("SpanDurations", new SpanDurationsListViewItemsCreator());
127128
listViewItemsCreator.add("SlowestSpans", new SlowestSpansListViewItemsCreator(this._webViewUris, editorHelper,_documentInfoProvider,this._channel));
128129
const usageTemplate = new UsageViewItemsTemplate(this._webViewUris);
129130
listViewItemsCreator.add("LowUsage", new LowUsageListViewItemsCreator(usageTemplate));

0 commit comments

Comments
 (0)