Skip to content

Commit b402fac

Browse files
bwilkersonCommit Queue
authored andcommitted
Adds library cycle data to the analytics.
The two pieces of information we're tracking are - the number of libraries in each library cycle - the number of lines of code in each library cycle The data is reported in terms of percentage. This doesn't give us any way to correlate the two values. Knowing that there is a library cycle with M libraries and a cycle with N lines of code, doesn't tell us whether it's the same library cycle in both cases. Still, I think it will help us understand the nature of the code that we need to be able to analyze quickly. Change-Id: I36a8bf11c4c6fdced6c524225be7a633062351ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437126 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 873a88b commit b402fac

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import 'package:analyzer/src/dart/analysis/file_byte_store.dart'
6969
show EvictingFileByteStore;
7070
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
7171
import 'package:analyzer/src/dart/analysis/info_declaration_store.dart';
72+
import 'package:analyzer/src/dart/analysis/library_graph.dart';
7273
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
7374
import 'package:analyzer/src/dart/analysis/results.dart';
7475
import 'package:analyzer/src/dart/analysis/session.dart';
@@ -943,6 +944,7 @@ abstract class AnalysisServer {
943944
var transitiveFileLineCount = 0;
944945
var transitiveFilePaths = <String>{};
945946
var transitiveFileUniqueLineCount = 0;
947+
var libraryCycles = <LibraryCycle>{};
946948
var driverMap = contextManager.driverMap;
947949
for (var entry in driverMap.entries) {
948950
var rootPath = entry.key.path;
@@ -952,11 +954,18 @@ abstract class AnalysisServer {
952954
packagesFileMap[rootPath] = contextRoot.packagesFile;
953955
}
954956
var fileSystemState = driver.fsState;
955-
for (var fileState in fileSystemState.knownFiles) {
957+
// Capture the known files before the loop to prevent a concurrent
958+
// modification exception. The reason for the exception is unknown.
959+
var knownFiles = fileSystemState.knownFiles.toList();
960+
for (var fileState in knownFiles) {
956961
var isImmediate = fileState.path.startsWith(rootPath);
957962
if (isImmediate) {
958963
immediateFileCount++;
959964
immediateFileLineCount += fileState.lineInfo.lineCount;
965+
var libraryKind = fileState.kind.library;
966+
if (libraryKind != null) {
967+
libraryCycles.add(libraryKind.libraryCycle);
968+
}
960969
} else {
961970
var lineCount = fileState.lineInfo.lineCount;
962971
transitiveFileCount++;
@@ -969,8 +978,19 @@ abstract class AnalysisServer {
969978
}
970979
var transitiveFileUniqueCount = transitiveFilePaths.length;
971980

972-
var rootPaths = packagesFileMap.keys.toList();
973-
rootPaths.sort((first, second) => first.length.compareTo(second.length));
981+
var libraryCycleLibraryCounts = <int>[];
982+
var libraryCycleLineCounts = <int>[];
983+
for (var libraryCycle in libraryCycles) {
984+
var libraries = libraryCycle.libraries;
985+
var lineCount = 0;
986+
for (var library in libraries) {
987+
for (var file in library.files) {
988+
lineCount += file.lineInfo.lineCount;
989+
}
990+
}
991+
libraryCycleLibraryCounts.add(libraries.length);
992+
libraryCycleLineCounts.add(lineCount);
993+
}
974994

975995
analyticsManager.analysisComplete(
976996
numberOfContexts: driverMap.length,
@@ -980,6 +1000,8 @@ abstract class AnalysisServer {
9801000
transitiveFileLineCount: transitiveFileLineCount,
9811001
transitiveFileUniqueCount: transitiveFileUniqueCount,
9821002
transitiveFileUniqueLineCount: transitiveFileUniqueLineCount,
1003+
libraryCycleLibraryCounts: libraryCycleLibraryCounts,
1004+
libraryCycleLineCounts: libraryCycleLineCounts,
9831005
);
9841006
}
9851007

pkg/analysis_server/lib/src/analytics/analytics_manager.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ class AnalyticsManager {
9898
}
9999

100100
/// Record information about the number of files and the number of lines of
101-
/// code in those files, for both immediate files, transitive files, and the
102-
/// number of unique transitive files.
101+
/// code in those files, for both immediate files, transitive files, the
102+
/// number of unique transitive files, and the number and sizes of library
103+
/// cycles.
103104
void analysisComplete({
104105
required int numberOfContexts,
105106
required int immediateFileCount,
@@ -108,6 +109,8 @@ class AnalyticsManager {
108109
required int transitiveFileLineCount,
109110
required int transitiveFileUniqueCount,
110111
required int transitiveFileUniqueLineCount,
112+
required List<int> libraryCycleLibraryCounts,
113+
required List<int> libraryCycleLineCounts,
111114
}) {
112115
// This is currently keeping the first report of completed analysis, but we
113116
// might want to consider alternatives, such as keeping the "largest"
@@ -120,6 +123,8 @@ class AnalyticsManager {
120123
transitiveFileLineCount: transitiveFileLineCount,
121124
transitiveFileUniqueCount: transitiveFileUniqueCount,
122125
transitiveFileUniqueLineCount: transitiveFileUniqueLineCount,
126+
libraryCycleLibraryCounts: libraryCycleLibraryCounts,
127+
libraryCycleLineCounts: libraryCycleLineCounts,
123128
);
124129
}
125130

@@ -461,6 +466,12 @@ class AnalyticsManager {
461466
li(
462467
'transitiveFileUniqueLineCount: ${json.encode(analysisData.transitiveFileUniqueLineCount)}',
463468
);
469+
li(
470+
'libraryCycleLibraryCounts: ${analysisData.libraryCycleLibraryCounts.toAnalyticsString()}',
471+
);
472+
li(
473+
'libraryCycleLineCounts: ${analysisData.libraryCycleLineCounts.toAnalyticsString()}',
474+
);
464475
buffer.writeln('</ul>');
465476
}
466477

@@ -505,6 +516,10 @@ class AnalyticsManager {
505516
transitiveFileUniqueCount: contextStructure.transitiveFileUniqueCount,
506517
transitiveFileUniqueLineCount:
507518
contextStructure.transitiveFileUniqueLineCount,
519+
libraryCycleLibraryCounts:
520+
contextStructure.libraryCycleLibraryCounts.toAnalyticsString(),
521+
libraryCycleLineCounts:
522+
contextStructure.libraryCycleLineCounts.toAnalyticsString(),
508523
),
509524
);
510525
}

pkg/analysis_server/lib/src/analytics/context_structure.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analysis_server/src/analytics/percentile_calculator.dart';
6+
57
/// Data about the structure of the contexts being analyzed.
68
///
79
/// The descriptions of the fields below depend on the following terms.
@@ -45,6 +47,9 @@ class ContextStructure {
4547
/// [transitiveFileUniqueCount].
4648
final int transitiveFileUniqueLineCount;
4749

50+
final PercentileCalculator libraryCycleLibraryCounts;
51+
final PercentileCalculator libraryCycleLineCounts;
52+
4853
/// Initialize a newly created data holder.
4954
ContextStructure({
5055
required this.numberOfContexts,
@@ -54,5 +59,12 @@ class ContextStructure {
5459
required this.transitiveFileLineCount,
5560
required this.transitiveFileUniqueCount,
5661
required this.transitiveFileUniqueLineCount,
57-
});
62+
required List<int> libraryCycleLibraryCounts,
63+
required List<int> libraryCycleLineCounts,
64+
}) : libraryCycleLibraryCounts = PercentileCalculator.from(
65+
libraryCycleLibraryCounts,
66+
),
67+
libraryCycleLineCounts = PercentileCalculator.from(
68+
libraryCycleLineCounts,
69+
);
5870
}

pkg/analysis_server/lib/src/analytics/percentile_calculator.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class PercentileCalculator {
1717
/// Initialize a newly created percentile calculator.
1818
PercentileCalculator();
1919

20+
factory PercentileCalculator.from(List<int> values) {
21+
var calculator = PercentileCalculator();
22+
for (var value in values) {
23+
calculator.addValue(value);
24+
}
25+
return calculator;
26+
}
27+
2028
/// The number of values recorded.
2129
int get valueCount => _valueCount;
2230

0 commit comments

Comments
 (0)