Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(857)

Unified Diff: pkg/analysis_server/lib/src/domain_diagnostic.dart

Issue 1509033003: Promote `diagnostic.getDiagnostics()` (#25061). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/domain_diagnostic.dart
diff --git a/pkg/analysis_server/lib/src/domain_diagnostic.dart b/pkg/analysis_server/lib/src/domain_diagnostic.dart
index 0acddff69ec87c3f39c31554481855b95695f97e..e9bd0c3b1af263f461cc82dfe2ceba17704384ce 100644
--- a/pkg/analysis_server/lib/src/domain_diagnostic.dart
+++ b/pkg/analysis_server/lib/src/domain_diagnostic.dart
@@ -4,13 +4,11 @@
library analysis_server.src.domain_diagnostic;
-import 'dart:async';
import 'dart:collection';
import 'dart:core' hide Resource;
import 'package:analysis_server/plugin/protocol/protocol.dart';
import 'package:analysis_server/src/analysis_server.dart';
-import 'package:analysis_server/src/utilities/average.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/context/context.dart';
@@ -35,20 +33,12 @@ class DiagnosticDomainHandler implements RequestHandler {
/// The analysis server that is using this handler to process requests.
final AnalysisServer server;
- /// The sampler tracking rolling work queue length averages.
- Sampler sampler;
-
/// Initialize a newly created handler to handle requests for the given
/// [server].
DiagnosticDomainHandler(this.server);
/// Answer the `diagnostic.diagnostics` request.
Response computeDiagnostics(Request request) {
- // Initialize sampler if needed.
- if (sampler == null) {
- sampler = new Sampler(server);
- }
-
List<ContextData> infos = <ContextData>[];
server.folderMap.forEach((Folder folder, AnalysisContext context) {
infos.add(extractData(folder, context));
@@ -62,11 +52,9 @@ class DiagnosticDomainHandler implements RequestHandler {
int explicitFiles = 0;
int implicitFiles = 0;
int workItems = 0;
- String workItemAverage = '-1';
Set<String> exceptions = new HashSet<String>();
if (context is AnalysisContextImpl) {
workItems = _workItemCount(context);
- workItemAverage = sampler.getAverage(folder)?.toString() ?? '-1';
var cache = context.analysisCache;
if (cache is AnalysisCache) {
Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>();
@@ -91,7 +79,7 @@ class DiagnosticDomainHandler implements RequestHandler {
}
}
return new ContextData(context.name, explicitFiles, implicitFiles,
- workItems, workItemAverage, exceptions.toList());
+ workItems, exceptions.toList());
}
@override
@@ -107,83 +95,3 @@ class DiagnosticDomainHandler implements RequestHandler {
return null;
}
}
-
-/// Keeps track of a moving average of work item queue lengths mapped to
-/// contexts.
-///
-/// Sampling terminates after [maxSampleCount], if no one expresses interest
-/// by calling [resetTimerCountdown].
-class Sampler {
- /// Timer interval.
- static const Duration duration = const Duration(seconds: 1);
-
- /// Maximum number of samples taken between calls to [reset].
- static const int maxSampleCount = 30;
-
- /// Current sample count.
- int sampleCount = 0;
-
- /// The shared timer.
- Timer timer;
-
- /// Map of contexts (tracked as folders to avoid leaks) to averages.
- /// TOOD(pq): consider adding GC to remove mappings for deleted folders
- Map<Folder, Average> averages = new HashMap<Folder, Average>();
-
- final AnalysisServer server;
- Sampler(this.server) {
- start();
- _sample();
- }
-
- /// Get the average for the context associated with the given [folder].
- num getAverage(Folder folder) {
- resetTimerCountdown();
- return averages[folder].value;
- }
-
- /// Check if we're currently sampling.
- bool isSampling() => timer?.isActive ?? false;
-
- /// Reset counter.
- void resetTimerCountdown() {
- sampleCount = 0;
- }
-
- /// Start sampling.
- void start() {
- // No need to (re)start if already sampling.
- if (isSampling()) {
- return;
- }
- timer = new Timer.periodic(duration, (Timer timer) {
- _sample();
- if (sampleCount++ >= maxSampleCount) {
- timer.cancel();
- }
- });
- }
-
- /// Stop sampling.
- void stop() {
- timer.cancel();
- }
-
- /// Take a sample.
- void _sample() {
- try {
- server.folderMap.forEach((Folder folder, AnalysisContext context) {
- if (context is AnalysisContextImpl) {
- Average average = averages[folder];
- if (average == null) {
- average = new Average();
- averages[folder] = average;
- }
- average.addSample(_workItemCount(context));
- }
- });
- } on Exception {
- stop();
- }
- }
-}
« no previous file with comments | « pkg/analysis_server/lib/plugin/protocol/generated_protocol.dart ('k') | pkg/analysis_server/test/domain_diagnostic_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698