@@ -25,19 +25,21 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
25
25
import { ILogService } from 'vs/platform/log/common/log' ;
26
26
import { INotificationService } from 'vs/platform/notification/common/notification' ;
27
27
import { IProgressService , ProgressLocation } from 'vs/platform/progress/common/progress' ;
28
+ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
28
29
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
29
30
import { ExtensionMessageCollector , IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry' ;
30
31
import { ITextMateTokenizationService } from 'vs/workbench/services/textMate/browser/textMateTokenizationFeature' ;
31
32
import { TextMateTokenizationSupport } from 'vs/workbench/services/textMate/browser/tokenizationSupport/textMateTokenizationSupport' ;
32
33
import { TokenizationSupportWithLineLimit } from 'vs/workbench/services/textMate/browser/tokenizationSupport/tokenizationSupportWithLineLimit' ;
33
34
import { TextMateWorkerHost } from 'vs/workbench/services/textMate/browser/workerHost/textMateWorkerHost' ;
34
- import { missingTMGrammarErrorMessage , TMGrammarFactory } from 'vs/workbench/services/textMate/common/TMGrammarFactory' ;
35
- import { grammarsExtPoint , ITMSyntaxExtensionPoint } from 'vs/workbench/services/textMate/common/TMGrammars' ;
35
+ import { TMGrammarFactory , missingTMGrammarErrorMessage } from 'vs/workbench/services/textMate/common/TMGrammarFactory' ;
36
+ import { ITMSyntaxExtensionPoint , grammarsExtPoint } from 'vs/workbench/services/textMate/common/TMGrammars' ;
36
37
import { IValidEmbeddedLanguagesMap , IValidGrammarDefinition , IValidTokenTypeMap } from 'vs/workbench/services/textMate/common/TMScopeRegistry' ;
37
38
import { ITextMateThemingRule , IWorkbenchColorTheme , IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService' ;
38
39
import type { IGrammar , IOnigLib , IRawTheme } from 'vscode-textmate' ;
39
40
40
41
export class TextMateTokenizationFeature extends Disposable implements ITextMateTokenizationService {
42
+ private static reportTokenizationTimeCounter = 0 ;
41
43
public _serviceBrand : undefined ;
42
44
43
45
private readonly _styleElement : HTMLStyleElement ;
@@ -52,7 +54,10 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
52
54
private readonly _tokenizersRegistrations = new DisposableStore ( ) ;
53
55
private _currentTheme : IRawTheme | null = null ;
54
56
private _currentTokenColorMap : string [ ] | null = null ;
55
- private readonly _workerHost = this . _instantiationService . createInstance ( TextMateWorkerHost ) ;
57
+ private readonly _workerHost = this . _instantiationService . createInstance (
58
+ TextMateWorkerHost ,
59
+ ( timeMs , languageId , sourceExtensionId , lineLength ) => this . reportTokenizationTime ( timeMs , languageId , sourceExtensionId , lineLength , true )
60
+ ) ;
56
61
57
62
constructor (
58
63
@ILanguageService private readonly _languageService : ILanguageService ,
@@ -64,6 +69,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
64
69
@IProgressService private readonly _progressService : IProgressService ,
65
70
@IWorkbenchEnvironmentService private readonly _environmentService : IWorkbenchEnvironmentService ,
66
71
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
72
+ @ITelemetryService private readonly _telemetryService : ITelemetryService ,
67
73
) {
68
74
super ( ) ;
69
75
@@ -179,6 +185,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
179
185
injectTo : grammar . injectTo ,
180
186
balancedBracketSelectors : asStringArray ( grammar . balancedBracketScopes , [ '*' ] ) ,
181
187
unbalancedBracketSelectors : asStringArray ( grammar . unbalancedBracketScopes , [ ] ) ,
188
+ sourceExtensionId : extension . description . id ,
182
189
} ;
183
190
}
184
191
@@ -283,6 +290,9 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
283
290
r . containsEmbeddedLanguages ,
284
291
( textModel , tokenStore ) => this . _workerHost . createBackgroundTokenizer ( textModel , tokenStore , maxTokenizationLineLength ) ,
285
292
( ) => this . _configurationService . getValue < boolean > ( 'editor.experimental.asyncTokenizationVerification' ) ,
293
+ ( timeMs , lineLength ) => {
294
+ this . reportTokenizationTime ( timeMs , languageId , r . sourceExtensionId , lineLength , false ) ;
295
+ }
286
296
) ;
287
297
tokenization . onDidEncounterLanguage ( ( encodedLanguageId ) => {
288
298
if ( ! this . _encounteredLanguages [ encodedLanguageId ] ) {
@@ -365,6 +375,44 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
365
375
return response ;
366
376
}
367
377
}
378
+
379
+ public reportTokenizationTime ( timeMs : number , languageId : string , sourceExtensionId : string | undefined , lineLength : number , fromWorker : boolean ) : void {
380
+ // 50 events per hour (one event has a low probability)
381
+ if ( TextMateTokenizationFeature . reportTokenizationTimeCounter > 50 ) {
382
+ // Don't flood telemetry with too many events
383
+ return ;
384
+ }
385
+ if ( TextMateTokenizationFeature . reportTokenizationTimeCounter === 0 ) {
386
+ setTimeout ( ( ) => {
387
+ TextMateTokenizationFeature . reportTokenizationTimeCounter = 0 ;
388
+ } , 1000 * 60 * 60 ) ;
389
+ }
390
+ TextMateTokenizationFeature . reportTokenizationTimeCounter ++ ;
391
+
392
+ this . _telemetryService . publicLog2 < {
393
+ timeMs : number ;
394
+ languageId : string ;
395
+ lineLength : number ;
396
+ fromWorker : boolean ;
397
+ sourceExtensionId : string | undefined ;
398
+ } , {
399
+ owner : 'hediet' ;
400
+
401
+ timeMs : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; isMeasurement : true ; comment : 'To understand how long it took to tokenize a random line' } ;
402
+ languageId : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; isMeasurement : true ; comment : 'To relate the performance to the language' } ;
403
+ lineLength : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; isMeasurement : true ; comment : 'To relate the performance to the line length' } ;
404
+ fromWorker : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; isMeasurement : true ; comment : 'To figure out if this line was tokenized sync or async' } ;
405
+ sourceExtensionId : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; isMeasurement : true ; comment : 'To figure out which extension contributed the grammar' } ;
406
+
407
+ comment : 'This event gives insight about the performance certain grammars.' ;
408
+ } > ( 'editor.tokenizedLine' , {
409
+ timeMs,
410
+ languageId,
411
+ lineLength,
412
+ fromWorker,
413
+ sourceExtensionId,
414
+ } ) ;
415
+ }
368
416
}
369
417
370
418
function toColorMap ( colorMap : string [ ] ) : Color [ ] {
0 commit comments