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