Skip to content

Commit 953e407

Browse files
DanTupCommit Queue
authored and
Commit Queue
committed
[analysis_server] Record execution/timing of "pub upgrade" for plugins in instrumentation log
This will help identify issues like #55621 in future from the logs without needing to repro. Before, there was just a gap in the logs that wasn't obvious. A sample log looks like: ``` 1715080652096:Req:{"jsonrpc"::"2.0","id"::2,"result"::null,"clientRequestTime"::1715080652091} 1715080652253:Info:Running "pub upgrade" in "C::\Users\danny\AppData\Local\.dartServer\.plugin_manager\723cb7b2bec3011e09cd16421250ff7a\analyzer_plugin" 1715080653311:Info:Running "pub upgrade" took 0::00::01.057950 1715080653393:Res:{"id"::3,"jsonrpc"::"2.0","method"::"window/workDoneProgress/create","params"::{"token"::"ANALYZING"}} ``` (This was the only instance of `Process.runSync` in the server) Change-Id: I2ccc5a7c538ae7a236a76df020c59014982a2e19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365602 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
1 parent e5cd02c commit 953e407

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

pkg/analysis_server/lib/src/plugin/plugin_manager.dart

+29-10
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import 'dart:async';
66
import 'dart:collection';
77
import 'dart:convert';
8-
import 'dart:io' show Platform, Process;
8+
import 'dart:io' show Platform, Process, ProcessResult;
99

1010
import 'package:analysis_server/src/analytics/percentile_calculator.dart';
1111
import 'package:analysis_server/src/plugin/notification_manager.dart';
1212
import 'package:analyzer/dart/analysis/context_root.dart' as analyzer;
1313
import 'package:analyzer/exception/exception.dart';
1414
import 'package:analyzer/file_system/file_system.dart';
1515
import 'package:analyzer/instrumentation/instrumentation.dart';
16-
import 'package:analyzer/src/generated/engine.dart';
1716
import 'package:analyzer/src/generated/source.dart';
1817
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
1918
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
@@ -492,7 +491,7 @@ class PluginManager {
492491
try {
493492
plugin.stop();
494493
} catch (e, st) {
495-
AnalysisEngine.instance.instrumentationService
494+
instrumentationService
496495
.logException(SilentException('Issue stopping a plugin', e, st));
497496
}
498497
}
@@ -594,7 +593,7 @@ class PluginManager {
594593
try {
595594
await info.stop();
596595
} catch (e, st) {
597-
AnalysisEngine.instance.instrumentationService.logException(e, st);
596+
instrumentationService.logException(e, st);
598597
}
599598
}));
600599
}
@@ -616,12 +615,7 @@ class PluginManager {
616615
.getChildAssumingFolder(file_paths.dotDartTool)
617616
.getChildAssumingFile(file_paths.packageConfigJson);
618617
if (pubCommand != null) {
619-
var result = Process.runSync(
620-
Platform.executable, <String>['pub', pubCommand],
621-
stderrEncoding: utf8,
622-
stdoutEncoding: utf8,
623-
workingDirectory: pluginFolder.path,
624-
environment: {_pubEnvironmentKey: _getPubEnvironmentValue()});
618+
var result = _runPubCommand(pubCommand, pluginFolder);
625619
if (result.exitCode != 0) {
626620
var buffer = StringBuffer();
627621
buffer.writeln('Failed to run pub $pubCommand');
@@ -762,6 +756,31 @@ class PluginManager {
762756
return const <String>[];
763757
}
764758

759+
/// Runs (and records timing to the instrumentation log) a Pub command
760+
/// [pubCommand] in [folder].
761+
ProcessResult _runPubCommand(String pubCommand, Folder folder) {
762+
instrumentationService.logInfo(
763+
'Running "pub $pubCommand" in "${folder.path}"',
764+
);
765+
766+
var stopwatch = Stopwatch()..start();
767+
var result = Process.runSync(
768+
Platform.executable,
769+
<String>['pub', pubCommand],
770+
stderrEncoding: utf8,
771+
stdoutEncoding: utf8,
772+
workingDirectory: folder.path,
773+
environment: {_pubEnvironmentKey: _getPubEnvironmentValue()},
774+
);
775+
stopwatch.stop();
776+
777+
instrumentationService.logInfo(
778+
'Running "pub $pubCommand" took ${stopwatch.elapsed}',
779+
);
780+
781+
return result;
782+
}
783+
765784
/// Return a hex-encoded MD5 signature of the given file [path].
766785
String _uniqueDirectoryName(String path) {
767786
var bytes = md5.convert(path.codeUnits).bytes;

0 commit comments

Comments
 (0)