Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/diagnostics/node/diagnosticsService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as fs from 'fs';
7
import * as osLib from 'os';
8
import { Promises } from '../../../base/common/async.js';
9
import { getNodeType, parse, ParseError } from '../../../base/common/json.js';
10
import { Schemas } from '../../../base/common/network.js';
11
import { basename, join } from '../../../base/common/path.js';
12
import { isLinux, isWindows } from '../../../base/common/platform.js';
13
import { ProcessItem } from '../../../base/common/processes.js';
14
import { StopWatch } from '../../../base/common/stopwatch.js';
15
import { URI } from '../../../base/common/uri.js';
16
import { virtualMachineHint } from '../../../base/node/id.js';
17
import { IDirent, Promises as pfs } from '../../../base/node/pfs.js';
18
import { listProcesses } from '../../../base/node/ps.js';
19
import { IDiagnosticsService, IMachineInfo, IMainProcessDiagnostics, IRemoteDiagnosticError, IRemoteDiagnosticInfo, isRemoteDiagnosticError, IWorkspaceInformation, PerformanceInfo, SystemInfo, WorkspaceStatItem, WorkspaceStats } from '../common/diagnostics.js';
20
import { ByteSize } from '../../files/common/files.js';
21
import { IProductService } from '../../product/common/productService.js';
22
import { ITelemetryService } from '../../telemetry/common/telemetry.js';
23
import { IWorkspace } from '../../workspace/common/workspace.js';
24
25
interface ConfigFilePatterns {
26
tag: string;
27
filePattern: RegExp;
28
relativePathPattern?: RegExp;
29
}
30
31
const workspaceStatsCache = new Map<string, Promise<WorkspaceStats>>();
32
export async function collectWorkspaceStats(folder: string, filter: string[]): Promise<WorkspaceStats> {
33
const cacheKey = `${folder}::${filter.join(':')}`;
34
const cached = workspaceStatsCache.get(cacheKey);
35
if (cached) {
36
return cached;
37
}
38
39
const configFilePatterns: ConfigFilePatterns[] = [
40
{ tag: 'grunt.js', filePattern: /^gruntfile\.js$/i },
41
{ tag: 'gulp.js', filePattern: /^gulpfile\.js$/i },
42
{ tag: 'tsconfig.json', filePattern: /^tsconfig\.json$/i },
43
{ tag: 'package.json', filePattern: /^package\.json$/i },
44
{ tag: 'jsconfig.json', filePattern: /^jsconfig\.json$/i },
45
{ tag: 'tslint.json', filePattern: /^tslint\.json$/i },
46
{ tag: 'eslint.json', filePattern: /^eslint\.json$/i },
47
{ tag: 'tasks.json', filePattern: /^tasks\.json$/i },
48
{ tag: 'launch.json', filePattern: /^launch\.json$/i },
49
{ tag: 'mcp.json', filePattern: /^mcp\.json$/i },
50
{ tag: 'settings.json', filePattern: /^settings\.json$/i },
51
{ tag: 'webpack.config.js', filePattern: /^webpack\.config\.js$/i },
52
{ tag: 'project.json', filePattern: /^project\.json$/i },
53
{ tag: 'makefile', filePattern: /^makefile$/i },
54
{ tag: 'sln', filePattern: /^.+\.sln$/i },
55
{ tag: 'csproj', filePattern: /^.+\.csproj$/i },
56
{ tag: 'cmake', filePattern: /^.+\.cmake$/i },
57
{ tag: 'github-actions', filePattern: /^.+\.ya?ml$/i, relativePathPattern: /^\.github(?:\/|\\)workflows$/i },
58
{ tag: 'devcontainer.json', filePattern: /^devcontainer\.json$/i },
59
{ tag: 'dockerfile', filePattern: /^(dockerfile|docker\-compose\.ya?ml)$/i },
60
{ tag: 'cursorrules', filePattern: /^\.cursorrules$/i },
61
{ tag: 'cursorrules-dir', filePattern: /\.mdc$/i, relativePathPattern: /^\.cursor[\/\\]rules$/i },
62
{ tag: 'github-instructions-dir', filePattern: /\.instructions\.md$/i, relativePathPattern: /^\.github[\/\\]instructions$/i },
63
{ tag: 'github-prompts-dir', filePattern: /\.prompt\.md$/i, relativePathPattern: /^\.github[\/\\]prompts$/i },
64
{ tag: 'clinerules', filePattern: /^\.clinerules$/i },
65
{ tag: 'clinerules-dir', filePattern: /\.md$/i, relativePathPattern: /^\.clinerules$/i },
66
{ tag: 'agent.md', filePattern: /^agent\.md$/i },
67
{ tag: 'agents.md', filePattern: /^agents\.md$/i },
68
{ tag: 'claude.md', filePattern: /^claude\.md$/i },
69
{ tag: 'gemini.md', filePattern: /^gemini\.md$/i },
70
{ tag: 'copilot-instructions.md', filePattern: /^copilot\-instructions\.md$/i, relativePathPattern: /^\.github$/i },
71
];
72
73
const fileTypes = new Map<string, number>();
74
const configFiles = new Map<string, number>();
75
76
const MAX_FILES = 20000;
77
78
function collect(root: string, dir: string, filter: string[], token: { count: number; maxReached: boolean; readdirCount: number }): Promise<void> {
79
const relativePath = dir.substring(root.length + 1);
80
81
return Promises.withAsyncBody(async resolve => {
82
let files: IDirent[];
83
84
token.readdirCount++;
85
try {
86
files = await pfs.readdir(dir, { withFileTypes: true });
87
} catch (error) {
88
// Ignore folders that can't be read
89
resolve();
90
return;
91
}
92
93
if (token.count >= MAX_FILES) {
94
token.count += files.length;
95
token.maxReached = true;
96
resolve();
97
return;
98
}
99
100
let pending = files.length;
101
if (pending === 0) {
102
resolve();
103
return;
104
}
105
106
let filesToRead = files;
107
if (token.count + files.length > MAX_FILES) {
108
token.maxReached = true;
109
pending = MAX_FILES - token.count;
110
filesToRead = files.slice(0, pending);
111
}
112
113
token.count += files.length;
114
115
for (const file of filesToRead) {
116
if (file.isDirectory()) {
117
if (!filter.includes(file.name)) {
118
await collect(root, join(dir, file.name), filter, token);
119
}
120
121
if (--pending === 0) {
122
resolve();
123
return;
124
}
125
} else {
126
const index = file.name.lastIndexOf('.');
127
if (index >= 0) {
128
const fileType = file.name.substring(index + 1);
129
if (fileType) {
130
fileTypes.set(fileType, (fileTypes.get(fileType) ?? 0) + 1);
131
}
132
}
133
134
for (const configFile of configFilePatterns) {
135
if (configFile.relativePathPattern?.test(relativePath) !== false && configFile.filePattern.test(file.name)) {
136
configFiles.set(configFile.tag, (configFiles.get(configFile.tag) ?? 0) + 1);
137
}
138
}
139
140
if (--pending === 0) {
141
resolve();
142
return;
143
}
144
}
145
}
146
});
147
}
148
149
const statsPromise = Promises.withAsyncBody<WorkspaceStats>(async (resolve) => {
150
const token: { count: number; maxReached: boolean; readdirCount: number } = { count: 0, maxReached: false, readdirCount: 0 };
151
const sw = new StopWatch(true);
152
await collect(folder, folder, filter, token);
153
const launchConfigs = await collectLaunchConfigs(folder);
154
resolve({
155
configFiles: asSortedItems(configFiles),
156
fileTypes: asSortedItems(fileTypes),
157
fileCount: token.count,
158
maxFilesReached: token.maxReached,
159
launchConfigFiles: launchConfigs,
160
totalScanTime: sw.elapsed(),
161
totalReaddirCount: token.readdirCount
162
});
163
});
164
165
workspaceStatsCache.set(cacheKey, statsPromise);
166
return statsPromise;
167
}
168
169
function asSortedItems(items: Map<string, number>): WorkspaceStatItem[] {
170
return Array.from(items.entries(), ([name, count]) => ({ name: name, count: count }))
171
.sort((a, b) => b.count - a.count);
172
}
173
174
export function getMachineInfo(): IMachineInfo {
175
176
const machineInfo: IMachineInfo = {
177
os: `${osLib.type()} ${osLib.arch()} ${osLib.release()}`,
178
memory: `${(osLib.totalmem() / ByteSize.GB).toFixed(2)}GB (${(osLib.freemem() / ByteSize.GB).toFixed(2)}GB free)`,
179
vmHint: `${Math.round((virtualMachineHint.value() * 100))}%`,
180
};
181
182
const cpus = osLib.cpus();
183
if (cpus && cpus.length > 0) {
184
machineInfo.cpus = `${cpus[0].model} (${cpus.length} x ${cpus[0].speed})`;
185
}
186
187
return machineInfo;
188
}
189
190
export async function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> {
191
try {
192
const launchConfigs = new Map<string, number>();
193
const launchConfig = join(folder, '.vscode', 'launch.json');
194
195
const contents = await fs.promises.readFile(launchConfig);
196
197
const errors: ParseError[] = [];
198
const json = parse(contents.toString(), errors);
199
if (errors.length) {
200
console.log(`Unable to parse ${launchConfig}`);
201
return [];
202
}
203
204
if (getNodeType(json) === 'object' && json['configurations']) {
205
for (const each of json['configurations']) {
206
const type = each['type'];
207
if (type) {
208
if (launchConfigs.has(type)) {
209
launchConfigs.set(type, launchConfigs.get(type)! + 1);
210
} else {
211
launchConfigs.set(type, 1);
212
}
213
}
214
}
215
}
216
217
return asSortedItems(launchConfigs);
218
} catch (error) {
219
return [];
220
}
221
}
222
223
export class DiagnosticsService implements IDiagnosticsService {
224
225
declare readonly _serviceBrand: undefined;
226
227
constructor(
228
@ITelemetryService private readonly telemetryService: ITelemetryService,
229
@IProductService private readonly productService: IProductService
230
) { }
231
232
private formatMachineInfo(info: IMachineInfo): string {
233
const output: string[] = [];
234
output.push(`OS Version: ${info.os}`);
235
output.push(`CPUs: ${info.cpus}`);
236
output.push(`Memory (System): ${info.memory}`);
237
output.push(`VM: ${info.vmHint}`);
238
239
return output.join('\n');
240
}
241
242
private formatEnvironment(info: IMainProcessDiagnostics): string {
243
const output: string[] = [];
244
output.push(`Version: ${this.productService.nameShort} ${this.productService.version} (${this.productService.commit || 'Commit unknown'}, ${this.productService.date || 'Date unknown'})`);
245
output.push(`OS Version: ${osLib.type()} ${osLib.arch()} ${osLib.release()}`);
246
const cpus = osLib.cpus();
247
if (cpus && cpus.length > 0) {
248
output.push(`CPUs: ${cpus[0].model} (${cpus.length} x ${cpus[0].speed})`);
249
}
250
output.push(`Memory (System): ${(osLib.totalmem() / ByteSize.GB).toFixed(2)}GB (${(osLib.freemem() / ByteSize.GB).toFixed(2)}GB free)`);
251
if (!isWindows) {
252
output.push(`Load (avg): ${osLib.loadavg().map(l => Math.round(l)).join(', ')}`); // only provided on Linux/macOS
253
}
254
output.push(`VM: ${Math.round((virtualMachineHint.value() * 100))}%`);
255
output.push(`Screen Reader: ${info.screenReader ? 'yes' : 'no'}`);
256
output.push(`Process Argv: ${info.mainArguments.join(' ')}`);
257
output.push(`GPU Status: ${this.expandGPUFeatures(info.gpuFeatureStatus)}`);
258
259
return output.join('\n');
260
}
261
262
public async getPerformanceInfo(info: IMainProcessDiagnostics, remoteData: (IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]): Promise<PerformanceInfo> {
263
return Promise.all([listProcesses(info.mainPID), this.formatWorkspaceMetadata(info)]).then(async result => {
264
let [rootProcess, workspaceInfo] = result;
265
let processInfo = this.formatProcessList(info, rootProcess);
266
267
remoteData.forEach(diagnostics => {
268
if (isRemoteDiagnosticError(diagnostics)) {
269
processInfo += `\n${diagnostics.errorMessage}`;
270
workspaceInfo += `\n${diagnostics.errorMessage}`;
271
} else {
272
processInfo += `\n\nRemote: ${diagnostics.hostName}`;
273
if (diagnostics.processes) {
274
processInfo += `\n${this.formatProcessList(info, diagnostics.processes)}`;
275
}
276
277
if (diagnostics.workspaceMetadata) {
278
workspaceInfo += `\n| Remote: ${diagnostics.hostName}`;
279
for (const folder of Object.keys(diagnostics.workspaceMetadata)) {
280
const metadata = diagnostics.workspaceMetadata[folder];
281
282
let countMessage = `${metadata.fileCount} files`;
283
if (metadata.maxFilesReached) {
284
countMessage = `more than ${countMessage}`;
285
}
286
287
workspaceInfo += `| Folder (${folder}): ${countMessage}`;
288
workspaceInfo += this.formatWorkspaceStats(metadata);
289
}
290
}
291
}
292
});
293
294
return {
295
processInfo,
296
workspaceInfo
297
};
298
});
299
}
300
301
public async getSystemInfo(info: IMainProcessDiagnostics, remoteData: (IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]): Promise<SystemInfo> {
302
const { memory, vmHint, os, cpus } = getMachineInfo();
303
const systemInfo: SystemInfo = {
304
os,
305
memory,
306
cpus,
307
vmHint,
308
processArgs: `${info.mainArguments.join(' ')}`,
309
gpuStatus: info.gpuFeatureStatus,
310
screenReader: `${info.screenReader ? 'yes' : 'no'}`,
311
remoteData
312
};
313
314
if (!isWindows) {
315
systemInfo.load = `${osLib.loadavg().map(l => Math.round(l)).join(', ')}`;
316
}
317
318
if (isLinux) {
319
systemInfo.linuxEnv = {
320
desktopSession: process.env['DESKTOP_SESSION'],
321
xdgSessionDesktop: process.env['XDG_SESSION_DESKTOP'],
322
xdgCurrentDesktop: process.env['XDG_CURRENT_DESKTOP'],
323
xdgSessionType: process.env['XDG_SESSION_TYPE']
324
};
325
}
326
327
return Promise.resolve(systemInfo);
328
}
329
330
public async getDiagnostics(info: IMainProcessDiagnostics, remoteDiagnostics: (IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]): Promise<string> {
331
const output: string[] = [];
332
return listProcesses(info.mainPID).then(async rootProcess => {
333
334
// Environment Info
335
output.push('');
336
output.push(this.formatEnvironment(info));
337
338
// Process List
339
output.push('');
340
output.push(this.formatProcessList(info, rootProcess));
341
342
// Workspace Stats
343
if (info.windows.some(window => window.folderURIs && window.folderURIs.length > 0 && !window.remoteAuthority)) {
344
output.push('');
345
output.push('Workspace Stats: ');
346
output.push(await this.formatWorkspaceMetadata(info));
347
}
348
349
remoteDiagnostics.forEach(diagnostics => {
350
if (isRemoteDiagnosticError(diagnostics)) {
351
output.push(`\n${diagnostics.errorMessage}`);
352
} else {
353
output.push('\n\n');
354
output.push(`Remote: ${diagnostics.hostName}`);
355
output.push(this.formatMachineInfo(diagnostics.machineInfo));
356
357
if (diagnostics.processes) {
358
output.push(this.formatProcessList(info, diagnostics.processes));
359
}
360
361
if (diagnostics.workspaceMetadata) {
362
for (const folder of Object.keys(diagnostics.workspaceMetadata)) {
363
const metadata = diagnostics.workspaceMetadata[folder];
364
365
let countMessage = `${metadata.fileCount} files`;
366
if (metadata.maxFilesReached) {
367
countMessage = `more than ${countMessage}`;
368
}
369
370
output.push(`Folder (${folder}): ${countMessage}`);
371
output.push(this.formatWorkspaceStats(metadata));
372
}
373
}
374
}
375
});
376
377
output.push('');
378
output.push('');
379
380
return output.join('\n');
381
});
382
}
383
384
private formatWorkspaceStats(workspaceStats: WorkspaceStats): string {
385
const output: string[] = [];
386
const lineLength = 60;
387
let col = 0;
388
389
const appendAndWrap = (name: string, count: number) => {
390
const item = ` ${name}(${count})`;
391
392
if (col + item.length > lineLength) {
393
output.push(line);
394
line = '| ';
395
col = line.length;
396
}
397
else {
398
col += item.length;
399
}
400
line += item;
401
};
402
403
// File Types
404
let line = '| File types:';
405
const maxShown = 10;
406
const max = workspaceStats.fileTypes.length > maxShown ? maxShown : workspaceStats.fileTypes.length;
407
for (let i = 0; i < max; i++) {
408
const item = workspaceStats.fileTypes[i];
409
appendAndWrap(item.name, item.count);
410
}
411
output.push(line);
412
413
// Conf Files
414
if (workspaceStats.configFiles.length >= 0) {
415
line = '| Conf files:';
416
col = 0;
417
workspaceStats.configFiles.forEach((item) => {
418
appendAndWrap(item.name, item.count);
419
});
420
output.push(line);
421
}
422
423
if (workspaceStats.launchConfigFiles.length > 0) {
424
let line = '| Launch Configs:';
425
workspaceStats.launchConfigFiles.forEach(each => {
426
const item = each.count > 1 ? ` ${each.name}(${each.count})` : ` ${each.name}`;
427
line += item;
428
});
429
output.push(line);
430
}
431
return output.join('\n');
432
}
433
434
private expandGPUFeatures(gpuFeatures: any): string {
435
const longestFeatureName = Math.max(...Object.keys(gpuFeatures).map(feature => feature.length));
436
// Make columns aligned by adding spaces after feature name
437
return Object.keys(gpuFeatures).map(feature => `${feature}: ${' '.repeat(longestFeatureName - feature.length)} ${gpuFeatures[feature]}`).join('\n ');
438
}
439
440
private formatWorkspaceMetadata(info: IMainProcessDiagnostics): Promise<string> {
441
const output: string[] = [];
442
const workspaceStatPromises: Promise<void>[] = [];
443
444
info.windows.forEach(window => {
445
if (window.folderURIs.length === 0 || !!window.remoteAuthority) {
446
return;
447
}
448
449
output.push(`| Window (${window.title})`);
450
451
window.folderURIs.forEach(uriComponents => {
452
const folderUri = URI.revive(uriComponents);
453
if (folderUri.scheme === Schemas.file) {
454
const folder = folderUri.fsPath;
455
workspaceStatPromises.push(collectWorkspaceStats(folder, ['node_modules', '.git']).then(stats => {
456
let countMessage = `${stats.fileCount} files`;
457
if (stats.maxFilesReached) {
458
countMessage = `more than ${countMessage}`;
459
}
460
output.push(`| Folder (${basename(folder)}): ${countMessage}`);
461
output.push(this.formatWorkspaceStats(stats));
462
463
}).catch(error => {
464
output.push(`| Error: Unable to collect workspace stats for folder ${folder} (${error.toString()})`);
465
}));
466
} else {
467
output.push(`| Folder (${folderUri.toString()}): Workspace stats not available.`);
468
}
469
});
470
});
471
472
return Promise.all(workspaceStatPromises)
473
.then(_ => output.join('\n'))
474
.catch(e => `Unable to collect workspace stats: ${e}`);
475
}
476
477
private formatProcessList(info: IMainProcessDiagnostics, rootProcess: ProcessItem): string {
478
const mapProcessToName = new Map<number, string>();
479
info.windows.forEach(window => mapProcessToName.set(window.pid, `window [${window.id}] (${window.title})`));
480
info.pidToNames.forEach(({ pid, name }) => mapProcessToName.set(pid, name));
481
482
const output: string[] = [];
483
484
output.push('CPU %\tMem MB\t PID\tProcess');
485
486
if (rootProcess) {
487
this.formatProcessItem(info.mainPID, mapProcessToName, output, rootProcess, 0);
488
}
489
490
return output.join('\n');
491
}
492
493
private formatProcessItem(mainPid: number, mapProcessToName: Map<number, string>, output: string[], item: ProcessItem, indent: number): void {
494
const isRoot = (indent === 0);
495
496
// Format name with indent
497
let name: string;
498
if (isRoot) {
499
name = item.pid === mainPid ? this.productService.applicationName : 'remote-server';
500
} else {
501
if (mapProcessToName.has(item.pid)) {
502
name = mapProcessToName.get(item.pid)!;
503
} else {
504
name = `${' '.repeat(indent)} ${item.name}`;
505
}
506
}
507
508
const memory = process.platform === 'win32' ? item.mem : (osLib.totalmem() * (item.mem / 100));
509
output.push(`${item.load.toFixed(0).padStart(5, ' ')}\t${(memory / ByteSize.MB).toFixed(0).padStart(6, ' ')}\t${item.pid.toFixed(0).padStart(6, ' ')}\t${name}`);
510
511
// Recurse into children if any
512
if (Array.isArray(item.children)) {
513
item.children.forEach(child => this.formatProcessItem(mainPid, mapProcessToName, output, child, indent + 1));
514
}
515
}
516
517
public async getWorkspaceFileExtensions(workspace: IWorkspace): Promise<{ extensions: string[] }> {
518
const items = new Set<string>();
519
for (const { uri } of workspace.folders) {
520
const folderUri = URI.revive(uri);
521
if (folderUri.scheme !== Schemas.file) {
522
continue;
523
}
524
const folder = folderUri.fsPath;
525
try {
526
const stats = await collectWorkspaceStats(folder, ['node_modules', '.git']);
527
stats.fileTypes.forEach(item => items.add(item.name));
528
} catch { }
529
}
530
return { extensions: [...items] };
531
}
532
533
public async reportWorkspaceStats(workspace: IWorkspaceInformation): Promise<void> {
534
for (const { uri } of workspace.folders) {
535
const folderUri = URI.revive(uri);
536
if (folderUri.scheme !== Schemas.file) {
537
continue;
538
}
539
540
const folder = folderUri.fsPath;
541
try {
542
const stats = await collectWorkspaceStats(folder, ['node_modules', '.git']);
543
type WorkspaceStatsClassification = {
544
owner: 'lramos15';
545
comment: 'Metadata related to the workspace';
546
'workspace.id': { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A UUID given to a workspace to identify it.' };
547
rendererSessionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The ID of the session' };
548
};
549
type WorkspaceStatsEvent = {
550
'workspace.id': string | undefined;
551
rendererSessionId: string;
552
};
553
this.telemetryService.publicLog2<WorkspaceStatsEvent, WorkspaceStatsClassification>('workspace.stats', {
554
'workspace.id': workspace.telemetryId,
555
rendererSessionId: workspace.rendererSessionId
556
});
557
type WorkspaceStatsFileClassification = {
558
owner: 'lramos15';
559
comment: 'Helps us gain insights into what type of files are being used in a workspace';
560
rendererSessionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The ID of the session.' };
561
type: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The type of file' };
562
count: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'How many types of that file are present' };
563
};
564
type WorkspaceStatsFileEvent = {
565
rendererSessionId: string;
566
type: string;
567
count: number;
568
};
569
stats.fileTypes.forEach(e => {
570
this.telemetryService.publicLog2<WorkspaceStatsFileEvent, WorkspaceStatsFileClassification>('workspace.stats.file', {
571
rendererSessionId: workspace.rendererSessionId,
572
type: e.name,
573
count: e.count
574
});
575
});
576
stats.launchConfigFiles.forEach(e => {
577
this.telemetryService.publicLog2<WorkspaceStatsFileEvent, WorkspaceStatsFileClassification>('workspace.stats.launchConfigFile', {
578
rendererSessionId: workspace.rendererSessionId,
579
type: e.name,
580
count: e.count
581
});
582
});
583
stats.configFiles.forEach(e => {
584
this.telemetryService.publicLog2<WorkspaceStatsFileEvent, WorkspaceStatsFileClassification>('workspace.stats.configFiles', {
585
rendererSessionId: workspace.rendererSessionId,
586
type: e.name,
587
count: e.count
588
});
589
});
590
591
// Workspace stats metadata
592
type WorkspaceStatsMetadataClassification = {
593
owner: 'jrieken';
594
comment: 'Metadata about workspace metadata collection';
595
duration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'How did it take to make workspace stats' };
596
reachedLimit: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Did making workspace stats reach its limits' };
597
fileCount: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'How many files did workspace stats discover' };
598
readdirCount: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'How many readdir call were needed' };
599
};
600
type WorkspaceStatsMetadata = {
601
duration: number;
602
reachedLimit: boolean;
603
fileCount: number;
604
readdirCount: number;
605
};
606
this.telemetryService.publicLog2<WorkspaceStatsMetadata, WorkspaceStatsMetadataClassification>('workspace.stats.metadata', { duration: stats.totalScanTime, reachedLimit: stats.maxFilesReached, fileCount: stats.fileCount, readdirCount: stats.totalReaddirCount });
607
} catch {
608
// Report nothing if collecting metadata fails.
609
}
610
}
611
}
612
}
613
614