Skip to content

Commit

Permalink
[analysis_server] Record execution/timing of "pub upgrade" for plugin…
Browse files Browse the repository at this point in the history
…s 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 <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
  • Loading branch information
DanTup authored and Commit Queue committed May 7, 2024
1 parent e5cd02c commit 953e407
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions pkg/analysis_server/lib/src/plugin/plugin_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io' show Platform, Process;
import 'dart:io' show Platform, Process, ProcessResult;

import 'package:analysis_server/src/analytics/percentile_calculator.dart';
import 'package:analysis_server/src/plugin/notification_manager.dart';
import 'package:analyzer/dart/analysis/context_root.dart' as analyzer;
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
Expand Down Expand Up @@ -492,7 +491,7 @@ class PluginManager {
try {
plugin.stop();
} catch (e, st) {
AnalysisEngine.instance.instrumentationService
instrumentationService
.logException(SilentException('Issue stopping a plugin', e, st));
}
}
Expand Down Expand Up @@ -594,7 +593,7 @@ class PluginManager {
try {
await info.stop();
} catch (e, st) {
AnalysisEngine.instance.instrumentationService.logException(e, st);
instrumentationService.logException(e, st);
}
}));
}
Expand All @@ -616,12 +615,7 @@ class PluginManager {
.getChildAssumingFolder(file_paths.dotDartTool)
.getChildAssumingFile(file_paths.packageConfigJson);
if (pubCommand != null) {
var result = Process.runSync(
Platform.executable, <String>['pub', pubCommand],
stderrEncoding: utf8,
stdoutEncoding: utf8,
workingDirectory: pluginFolder.path,
environment: {_pubEnvironmentKey: _getPubEnvironmentValue()});
var result = _runPubCommand(pubCommand, pluginFolder);
if (result.exitCode != 0) {
var buffer = StringBuffer();
buffer.writeln('Failed to run pub $pubCommand');
Expand Down Expand Up @@ -762,6 +756,31 @@ class PluginManager {
return const <String>[];
}

/// Runs (and records timing to the instrumentation log) a Pub command
/// [pubCommand] in [folder].
ProcessResult _runPubCommand(String pubCommand, Folder folder) {
instrumentationService.logInfo(
'Running "pub $pubCommand" in "${folder.path}"',
);

var stopwatch = Stopwatch()..start();
var result = Process.runSync(
Platform.executable,
<String>['pub', pubCommand],
stderrEncoding: utf8,
stdoutEncoding: utf8,
workingDirectory: folder.path,
environment: {_pubEnvironmentKey: _getPubEnvironmentValue()},
);
stopwatch.stop();

instrumentationService.logInfo(
'Running "pub $pubCommand" took ${stopwatch.elapsed}',
);

return result;
}

/// Return a hex-encoded MD5 signature of the given file [path].
String _uniqueDirectoryName(String path) {
var bytes = md5.convert(path.codeUnits).bytes;
Expand Down

0 comments on commit 953e407

Please sign in to comment.