[analyzer] Support --verbose for LSP benchmarks

Change-Id: Ibad5b798e7f7a069bd5e1ce9758cfbbcaa8e3001
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182511
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2021-02-03 19:34:57 +00:00 committed by commit-bot@chromium.org
parent 12c0ca85df
commit e8dce3a6f0
2 changed files with 44 additions and 6 deletions

View file

@ -10,6 +10,7 @@ import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/lsp/handlers/handler_completion.dart';
import 'package:analysis_server/src/protocol_server.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:test/test.dart';
import '../../test/integration/lsp_server/integration_tests.dart';
@ -138,6 +139,7 @@ class AnalysisServerMemoryUsageTest
class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
with ClientCapabilitiesHelperMixin {
final _test = LspAnalysisServerMemoryUsageTest();
final PrintableLogger _logger = PrintableLogger();
/// Track the file contents so we can easily convert offsets (used in
/// the interface) to Positions required by LSP without having to keep
@ -162,7 +164,7 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
}
@override
void debugStdio() {}
void debugStdio() => _logger.debugStdio();
@override
Future<int> getMemoryUsage() => _test.getMemoryUsage();
@ -170,11 +172,13 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
@override
Future<void> openFile(String filePath, String contents) {
_fileContents[filePath] = contents;
return _test.openFile(Uri.file(filePath), contents);
return _test.openFile(Uri.file(filePath), contents,
version: _fileVersion++);
}
@override
Future<void> setUp(List<String> roots) async {
_test.instrumentationService = InstrumentationLogAdapter(_logger);
await _test.setUp();
_test.projectFolderPath = roots.single;
_test.projectFolderUri = Uri.file(_test.projectFolderPath);
@ -197,7 +201,10 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
}
@override
Future<void> shutdown() async => _test.tearDown();
Future<void> shutdown() async {
_test.tearDown();
_logger.shutdown();
}
@override
Future<void> updateFile(String filePath, String contents) {

View file

@ -17,6 +17,7 @@ abstract class AbstractLspAnalysisServerIntegrationTest
with ClientCapabilitiesHelperMixin, LspAnalysisServerTestMixin {
final List<String> vmArgs = [];
LspServerClient client;
InstrumentationService instrumentationService;
final Map<int, Completer<ResponseMessage>> _completers = {};
@ -79,7 +80,7 @@ abstract class AbstractLspAnalysisServerIntegrationTest
analysisOptionsPath = join(projectFolderPath, 'analysis_options.yaml');
analysisOptionsUri = Uri.file(analysisOptionsPath);
client = LspServerClient();
client = LspServerClient(instrumentationService);
await client.start(vmArgs: vmArgs);
client.serverToClient.listen((message) {
if (message is ResponseMessage) {
@ -104,11 +105,14 @@ abstract class AbstractLspAnalysisServerIntegrationTest
}
class LspServerClient {
final InstrumentationService instrumentationService;
Process _process;
LspByteStreamServerChannel channel;
final StreamController<Message> _serverToClient =
StreamController<Message>.broadcast();
LspServerClient(this.instrumentationService);
Future<int> get exitCode => _process.exitCode;
Stream<Message> get serverToClient => _serverToClient.stream;
@ -172,8 +176,35 @@ class LspServerClient {
throw 'Analysis Server wrote to stderr:\n\n$message';
});
channel = LspByteStreamServerChannel(
_process.stdout, _process.stdin, InstrumentationService.NULL_SERVICE);
channel = LspByteStreamServerChannel(_process.stdout, _process.stdin,
instrumentationService ?? InstrumentationService.NULL_SERVICE);
channel.listen(_serverToClient.add);
}
}
/// An [InstrumentationLogger] that buffers logs until [debugStdio()] is called.
class PrintableLogger extends InstrumentationLogger {
bool _printLogs = false;
final _buffer = StringBuffer();
void debugStdio() {
print(_buffer.toString());
_buffer.clear();
_printLogs = true;
}
@override
void log(String message) {
if (_printLogs) {
print(message);
} else {
_buffer.writeln(message);
}
}
@override
Future<void> shutdown() async {
_printLogs = false;
_buffer.clear();
}
}