@@ -25,19 +25,21 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2525import { ILogService } from 'vs/platform/log/common/log' ;
2626import { INotificationService } from 'vs/platform/notification/common/notification' ;
2727import { IProgressService , ProgressLocation } from 'vs/platform/progress/common/progress' ;
28+ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
2829import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
2930import { ExtensionMessageCollector , IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry' ;
3031import { ITextMateTokenizationService } from 'vs/workbench/services/textMate/browser/textMateTokenizationFeature' ;
3132import { TextMateTokenizationSupport } from 'vs/workbench/services/textMate/browser/tokenizationSupport/textMateTokenizationSupport' ;
3233import { TokenizationSupportWithLineLimit } from 'vs/workbench/services/textMate/browser/tokenizationSupport/tokenizationSupportWithLineLimit' ;
3334import { 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' ;
3637import { IValidEmbeddedLanguagesMap , IValidGrammarDefinition , IValidTokenTypeMap } from 'vs/workbench/services/textMate/common/TMScopeRegistry' ;
3738import { ITextMateThemingRule , IWorkbenchColorTheme , IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService' ;
3839import type { IGrammar , IOnigLib , IRawTheme } from 'vscode-textmate' ;
3940
4041export class TextMateTokenizationFeature extends Disposable implements ITextMateTokenizationService {
42+ private static reportTokenizationTimeCounter = 0 ;
4143 public _serviceBrand : undefined ;
4244
4345 private readonly _styleElement : HTMLStyleElement ;
@@ -52,7 +54,10 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
5254 private readonly _tokenizersRegistrations = new DisposableStore ( ) ;
5355 private _currentTheme : IRawTheme | null = null ;
5456 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+ ) ;
5661
5762 constructor (
5863 @ILanguageService private readonly _languageService : ILanguageService ,
@@ -64,6 +69,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
6469 @IProgressService private readonly _progressService : IProgressService ,
6570 @IWorkbenchEnvironmentService private readonly _environmentService : IWorkbenchEnvironmentService ,
6671 @IInstantiationService private readonly _instantiationService : IInstantiationService ,
72+ @ITelemetryService private readonly _telemetryService : ITelemetryService ,
6773 ) {
6874 super ( ) ;
6975
@@ -179,6 +185,7 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
179185 injectTo : grammar . injectTo ,
180186 balancedBracketSelectors : asStringArray ( grammar . balancedBracketScopes , [ '*' ] ) ,
181187 unbalancedBracketSelectors : asStringArray ( grammar . unbalancedBracketScopes , [ ] ) ,
188+ sourceExtensionId : extension . description . id ,
182189 } ;
183190 }
184191
@@ -283,6 +290,9 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
283290 r . containsEmbeddedLanguages ,
284291 ( textModel , tokenStore ) => this . _workerHost . createBackgroundTokenizer ( textModel , tokenStore , maxTokenizationLineLength ) ,
285292 ( ) => this . _configurationService . getValue < boolean > ( 'editor.experimental.asyncTokenizationVerification' ) ,
293+ ( timeMs , lineLength ) => {
294+ this . reportTokenizationTime ( timeMs , languageId , r . sourceExtensionId , lineLength , false ) ;
295+ }
286296 ) ;
287297 tokenization . onDidEncounterLanguage ( ( encodedLanguageId ) => {
288298 if ( ! this . _encounteredLanguages [ encodedLanguageId ] ) {
@@ -365,6 +375,44 @@ export class TextMateTokenizationFeature extends Disposable implements ITextMate
365375 return response ;
366376 }
367377 }
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+ }
368416}
369417
370418function toColorMap ( colorMap : string [ ] ) : Color [ ] {
0 commit comments