@@ -37,6 +37,7 @@ import 'package:analyzer/src/summary/api_signature.dart';
37
37
import 'package:analyzer/src/summary/package_bundle_reader.dart' ;
38
38
import 'package:analyzer/src/summary2/informative_data.dart' ;
39
39
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
40
+ import 'package:analyzer/src/util/performance/operation_performance.dart' ;
40
41
import 'package:analyzer/src/util/uri.dart' ;
41
42
import 'package:analyzer/src/utilities/extensions/collection.dart' ;
42
43
import 'package:analyzer/src/utilities/uri_cache.dart' ;
@@ -495,10 +496,16 @@ class FileState {
495
496
}
496
497
497
498
/// Return a new parsed unresolved [CompilationUnit] .
498
- CompilationUnitImpl parse ([AnalysisErrorListener ? errorListener]) {
499
+ CompilationUnitImpl parse ({
500
+ AnalysisErrorListener ? errorListener,
501
+ required OperationPerformanceImpl performance,
502
+ }) {
499
503
errorListener ?? = AnalysisErrorListener .NULL_LISTENER ;
500
504
try {
501
- return _parse (errorListener);
505
+ return _parse (
506
+ errorListener,
507
+ performance: performance,
508
+ );
502
509
} catch (exception, stackTrace) {
503
510
throw CaughtExceptionWithFiles (
504
511
exception,
@@ -512,42 +519,50 @@ class FileState {
512
519
CompilationUnitImpl parseCode ({
513
520
required String code,
514
521
required AnalysisErrorListener errorListener,
522
+ required OperationPerformanceImpl performance,
515
523
}) {
516
- CharSequenceReader reader = CharSequenceReader (code);
517
- Scanner scanner = Scanner (source, reader, errorListener)
518
- ..configureFeatures (
519
- featureSetForOverriding: featureSet,
520
- featureSet: featureSet.restrictToVersion (
521
- packageLanguageVersion,
522
- ),
524
+ return performance.run ('parseCode' , (performance) {
525
+ performance.getDataInt ('length' ).add (code.length);
526
+
527
+ CharSequenceReader reader = CharSequenceReader (code);
528
+ Scanner scanner = Scanner (source, reader, errorListener)
529
+ ..configureFeatures (
530
+ featureSetForOverriding: featureSet,
531
+ featureSet: featureSet.restrictToVersion (
532
+ packageLanguageVersion,
533
+ ),
534
+ );
535
+ Token token = scanner.tokenize (reportScannerErrors: false );
536
+ LineInfo lineInfo = LineInfo (scanner.lineStarts);
537
+
538
+ Parser parser = Parser (
539
+ source,
540
+ errorListener,
541
+ featureSet: scanner.featureSet,
542
+ lineInfo: lineInfo,
523
543
);
524
- Token token = scanner.tokenize (reportScannerErrors: false );
525
- LineInfo lineInfo = LineInfo (scanner.lineStarts);
526
-
527
- Parser parser = Parser (
528
- source,
529
- errorListener,
530
- featureSet: scanner.featureSet,
531
- lineInfo: lineInfo,
532
- );
533
544
534
- var unit = parser.parseCompilationUnit (token);
535
- unit.languageVersion = LibraryLanguageVersion (
536
- package: packageLanguageVersion,
537
- override: scanner.overrideVersion,
538
- );
545
+ var unit = parser.parseCompilationUnit (token);
546
+ unit.languageVersion = LibraryLanguageVersion (
547
+ package: packageLanguageVersion,
548
+ override: scanner.overrideVersion,
549
+ );
539
550
540
- // Ensure the string canonicalization cache size is reasonable.
541
- pruneStringCanonicalizationCache ();
551
+ // Ensure the string canonicalization cache size is reasonable.
552
+ pruneStringCanonicalizationCache ();
542
553
543
- return unit;
554
+ return unit;
555
+ });
544
556
}
545
557
546
558
/// Read the file content and ensure that all of the file properties are
547
559
/// consistent with the read content, including API signature.
548
560
///
549
561
/// Return how the file changed since the last refresh.
550
- FileStateRefreshResult refresh () {
562
+ FileStateRefreshResult refresh ({
563
+ OperationPerformanceImpl ? performance,
564
+ }) {
565
+ performance ?? = OperationPerformanceImpl ('<root>' );
551
566
_invalidateCurrentUnresolvedData ();
552
567
553
568
FileContent rawFileState;
@@ -578,7 +593,12 @@ class FileState {
578
593
}
579
594
580
595
// Prepare the unlinked unit.
581
- _driverUnlinkedUnit = _getUnlinkedUnit (previousUnlinkedKey);
596
+ performance.run ('getUnlinkedUnit' , (performance) {
597
+ _driverUnlinkedUnit = _getUnlinkedUnit (
598
+ previousUnlinkedKey,
599
+ performance: performance,
600
+ );
601
+ });
582
602
_unlinked2 = _driverUnlinkedUnit! .unit;
583
603
_lineInfo = LineInfo (_unlinked2! .lineStarts);
584
604
@@ -699,7 +719,10 @@ class FileState {
699
719
700
720
/// Return the unlinked unit, freshly deserialized from bytes,
701
721
/// previously deserialized from bytes, or new.
702
- AnalysisDriverUnlinkedUnit _getUnlinkedUnit (String ? previousUnlinkedKey) {
722
+ AnalysisDriverUnlinkedUnit _getUnlinkedUnit (
723
+ String ? previousUnlinkedKey, {
724
+ required OperationPerformanceImpl performance,
725
+ }) {
703
726
if (previousUnlinkedKey != null ) {
704
727
if (previousUnlinkedKey != _unlinkedKey) {
705
728
_fsState.unlinkedUnitStore.release (previousUnlinkedKey);
@@ -723,7 +746,10 @@ class FileState {
723
746
return result;
724
747
}
725
748
726
- var unit = parse ();
749
+ var unit = parse (
750
+ performance: performance,
751
+ );
752
+
727
753
return _fsState._logger.run ('Create unlinked for $path ' , () {
728
754
var unlinkedUnit = serializeAstUnlinked2 (
729
755
unit,
@@ -759,10 +785,14 @@ class FileState {
759
785
}
760
786
}
761
787
762
- CompilationUnitImpl _parse (AnalysisErrorListener errorListener) {
788
+ CompilationUnitImpl _parse (
789
+ AnalysisErrorListener errorListener, {
790
+ required OperationPerformanceImpl performance,
791
+ }) {
763
792
return parseCode (
764
793
code: content,
765
794
errorListener: errorListener,
795
+ performance: performance,
766
796
);
767
797
}
768
798
@@ -1316,7 +1346,10 @@ class FileSystemState {
1316
1346
/// to a file, for example because it is invalid (e.g. a `package:` URI
1317
1347
/// without a package name), or we don't know this package. The returned
1318
1348
/// file has the last known state since if was last refreshed.
1319
- UriResolution ? getFileForUri (Uri uri) {
1349
+ UriResolution ? getFileForUri (
1350
+ Uri uri, {
1351
+ OperationPerformanceImpl ? performance,
1352
+ }) {
1320
1353
var uriSource = _sourceFactory.forUri2 (uri);
1321
1354
1322
1355
// If the external store has this URI, create a stub file for it.
@@ -1349,7 +1382,12 @@ class FileSystemState {
1349
1382
return null ;
1350
1383
}
1351
1384
1352
- file = _newFile (resource, path, rewrittenUri);
1385
+ file = _newFile (
1386
+ resource,
1387
+ path,
1388
+ rewrittenUri,
1389
+ performance: performance,
1390
+ );
1353
1391
}
1354
1392
return UriResolutionFile (file);
1355
1393
}
@@ -1494,7 +1532,12 @@ class FileSystemState {
1494
1532
nonPackageLanguageVersion: analysisOptions.nonPackageLanguageVersion);
1495
1533
}
1496
1534
1497
- FileState _newFile (File resource, String path, Uri uri) {
1535
+ FileState _newFile (
1536
+ File resource,
1537
+ String path,
1538
+ Uri uri, {
1539
+ OperationPerformanceImpl ? performance,
1540
+ }) {
1498
1541
FileSource uriSource = FileSource (resource, uri);
1499
1542
WorkspacePackage ? workspacePackage = _workspace? .findPackageFor (path);
1500
1543
AnalysisOptionsImpl analysisOptions = _getAnalysisOptions (resource);
@@ -1509,7 +1552,14 @@ class FileSystemState {
1509
1552
knownFilePaths.add (path);
1510
1553
knownFiles.add (file);
1511
1554
fileStamp++ ;
1512
- file.refresh ();
1555
+
1556
+ performance ?? = OperationPerformanceImpl ('<root>' );
1557
+ performance.run ('fileState.refresh' , (performance) {
1558
+ file.refresh (
1559
+ performance: performance,
1560
+ );
1561
+ });
1562
+
1513
1563
onNewFile (file);
1514
1564
return file;
1515
1565
}
@@ -1843,6 +1893,7 @@ class LibraryFileKind extends LibraryOrAugmentationFileKind {
1843
1893
AugmentationImportWithFile addMacroAugmentation (
1844
1894
String code, {
1845
1895
required int ? partialIndex,
1896
+ required OperationPerformanceImpl performance,
1846
1897
}) {
1847
1898
var pathContext = file._fsState.pathContext;
1848
1899
var libraryFileName = pathContext.basename (file.path);
@@ -1869,7 +1920,15 @@ class LibraryFileKind extends LibraryOrAugmentationFileKind {
1869
1920
// Or this happens during the explicit `refresh()`, more below.
1870
1921
file._fsState._macroFileContent = fileContent;
1871
1922
1872
- var macroFileResolution = file._fsState.getFileForUri (macroUri);
1923
+ var macroFileResolution = performance.run (
1924
+ 'getFileForUri' ,
1925
+ (performance) {
1926
+ return file._fsState.getFileForUri (
1927
+ macroUri,
1928
+ performance: performance,
1929
+ );
1930
+ },
1931
+ );
1873
1932
macroFileResolution as UriResolutionFile ;
1874
1933
var macroFile = macroFileResolution.file;
1875
1934
0 commit comments