Skip to content

Commit 759b8b9

Browse files
authored
Aggregate the perf traces (#1154)
Signed-off-by: Sheng Chen <[email protected]>
1 parent be8b201 commit 759b8b9

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/daemon/clientLog/logWatcher.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class ClientLogWatcher {
1313
private logProcessedTimestamp: number = Date.now();
1414
private interestedLspRequests: string[] = ["textDocument\\/completion"];
1515
private lspTracePatterns: Map<string, RegExp> = new Map();
16+
// statistics of the interested lsp requests.
17+
private perfTraces: Map<string, {time: number; count: number}> = new Map();
1618

1719
constructor(daemon: LSDaemon) {
1820
this.context = daemon.context;
@@ -76,16 +78,28 @@ export class ClientLogWatcher {
7678
const regexp: RegExp = this.lspTracePatterns.get(key)!;
7779
const match = log.message?.match(regexp);
7880
if (match?.length === 2) {
79-
sendInfo("", {
80-
name: "perf-trace",
81-
kind: escapeLspRequestName(key),
82-
time: match[1],
83-
});
81+
const time = parseInt(match[1]);
82+
if (Number.isNaN(time)) {
83+
continue;
84+
}
85+
let statistics: { time: number; count: number; } | undefined = this.perfTraces.get(key);
86+
if (!statistics) {
87+
statistics = {
88+
time,
89+
count: 1,
90+
};
91+
} else {
92+
statistics.time += time;
93+
statistics.count++;
94+
}
95+
this.perfTraces.set(key, statistics);
8496
}
8597
}
8698
}
8799
}
88100
}
101+
102+
this.sendPerfStatistics();
89103
}
90104

91105
public async getLogs() {
@@ -117,6 +131,17 @@ export class ClientLogWatcher {
117131
}
118132
return undefined;
119133
}
134+
135+
private sendPerfStatistics() {
136+
for (let [key, value] of this.perfTraces) {
137+
sendInfo("", {
138+
name: "perf-trace",
139+
kind: escapeLspRequestName(key),
140+
time: value.time,
141+
count: value.count,
142+
});
143+
}
144+
}
120145
}
121146
/**
122147
* filename: client.log.yyyy-mm-dd.r

0 commit comments

Comments
 (0)