Skip to content

Commit

Permalink
Migrate benchmark/integration/
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com

Change-Id: I0dccc13831ec5aed82d33ee52ffeae1ad38c5b98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194109
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Apr 6, 2021
1 parent b5d4d26 commit 1bf4b0c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 108 deletions.
27 changes: 14 additions & 13 deletions pkg/analysis_server/benchmark/integration/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:math' show max, sqrt;

Expand Down Expand Up @@ -42,13 +40,13 @@ class Driver extends IntegrationTestMixin {
final Logger logger = Logger('Driver');

/// The diagnostic port for Analysis Server or `null` if none.
final int diagnosticPort;
final int? diagnosticPort;

/// A flag indicating whether the server is running.
bool running = false;

@override
Server server;
late Server server;

/// The results collected while running analysis server.
final Results results = Results();
Expand All @@ -65,7 +63,7 @@ class Driver extends IntegrationTestMixin {
/// Perform the given operation.
/// Return a [Future] that completes when the next operation can be performed,
/// or `null` if the next operation can be performed immediately
Future perform(Operation op) {
Future<void>? perform(Operation op) {
return op.perform(this);
}

Expand All @@ -75,7 +73,7 @@ class Driver extends IntegrationTestMixin {
/// normal (non-error) response, the future will be completed with the
/// 'result' field from the response. If the server acknowledges the command
/// with an error response, the future will be completed with an error.
Future<Map<String, dynamic>> send(
Future<Map<String, Object?>?> send(
String method, Map<String, dynamic> params) {
return server.send(method, params);
}
Expand Down Expand Up @@ -206,14 +204,17 @@ class Results {
print('');
print('==================================================================');
print('');
var keys = measurements.keys.toList()..sort();
var keyLen = keys.fold(0, (int len, String key) => max(len, key.length));
var sortedEntries = measurements.entries.toList();
sortedEntries.sort((a, b) => a.key.compareTo(b.key));
var keyLen = sortedEntries
.map((e) => e.key)
.fold(0, (int len, String key) => max(len, key.length));
_printGroupHeader('Request/Response', keyLen);
var totalCount = 0;
var totalErrorCount = 0;
var totalUnexpectedResultCount = 0;
for (var tag in keys) {
var m = measurements[tag];
for (var entry in sortedEntries) {
var m = entry.value;
if (!m.notification) {
m.printSummary(keyLen);
totalCount += m.count;
Expand All @@ -225,8 +226,8 @@ class Results {
keyLen, totalCount, totalErrorCount, totalUnexpectedResultCount);
print('');
_printGroupHeader('Notifications', keyLen);
for (var tag in keys) {
var m = measurements[tag];
for (var entry in sortedEntries) {
var m = entry.value;
if (m.notification) {
m.printSummary(keyLen);
}
Expand All @@ -252,7 +253,7 @@ class Results {
}

void recordUnexpectedResults(String tag) {
measurements[tag].recordUnexpectedResults();
measurements[tag]!.recordUnexpectedResults();
}

void _printGroupHeader(String groupName, int keyLen) {
Expand Down
49 changes: 24 additions & 25 deletions pkg/analysis_server/benchmark/integration/input_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand All @@ -20,14 +18,14 @@ import 'log_file_input_converter.dart';
import 'operation.dart';

/// Common input converter superclass for sharing implementation.
abstract class CommonInputConverter extends Converter<String, Operation> {
abstract class CommonInputConverter extends Converter<String, Operation?> {
static final ERROR_PREFIX = 'Server responded with an error: ';
final Logger logger = Logger('InstrumentationInputConverter');
final Set<String> eventsSeen = <String>{};

/// A mapping from request/response id to request json
/// for those requests for which a response has not been processed.
final Map<String, dynamic> requestMap = {};
final Map<String, Object?> requestMap = {};

/// A mapping from request/response id to a completer
/// for those requests for which a response has not been processed.
Expand All @@ -37,7 +35,7 @@ abstract class CommonInputConverter extends Converter<String, Operation> {

/// A mapping from request/response id to the actual response result
/// for those responses that have not been processed.
final Map<String, dynamic> responseMap = {};
final Map<String, Object?> responseMap = {};

/// A mapping of current overlay content
/// parallel to what is in the analysis server
Expand All @@ -58,16 +56,18 @@ abstract class CommonInputConverter extends Converter<String, Operation> {

CommonInputConverter(this.tmpSrcDirPath, this.srcPathMap);

Map<String, dynamic> asMap(dynamic value) => value as Map<String, dynamic>;
Map<String, Object?> asMap(dynamic value) => value as Map<String, Object?>;

Map<String, Object?>? asMap2(dynamic value) => value as Map<String, Object?>?;

/// Return an operation for the notification or `null` if none.
Operation convertNotification(Map<String, dynamic> json) {
Operation? convertNotification(Map<String, dynamic> json) {
String event = json['event'];
if (event == SERVER_NOTIFICATION_STATUS) {
// {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
var params = asMap(json['params']);
var params = asMap2(json['params']);
if (params != null) {
var analysis = asMap(params['analysis']);
var analysis = asMap2(params['analysis']);
if (analysis != null && analysis['isAnalyzing'] == false) {
return WaitForAnalysisCompleteOperation();
}
Expand All @@ -84,23 +84,20 @@ abstract class CommonInputConverter extends Converter<String, Operation> {
}

/// Return an operation for the request or `null` if none.
Operation convertRequest(Map<String, dynamic> origJson) {
Operation convertRequest(Map<String, Object?> origJson) {
var json = asMap(translateSrcPaths(origJson));
requestMap[json['id']] = json;
String method = json['method'];
requestMap[json['id'] as String] = json;
var method = json['method'] as String;
// Sanity check operations that modify source
// to ensure that the operation is on source in temp space
if (method == ANALYSIS_REQUEST_UPDATE_CONTENT) {
// Track overlays in parallel with the analysis server
// so that when an overlay is removed, the file can be updated on disk
var request = Request.fromJson(json);
var request = Request.fromJson(json)!;
var params = AnalysisUpdateContentParams.fromRequest(request);
params.files.forEach((String filePath, change) {
if (change is AddContentOverlay) {
var content = change.content;
if (content == null) {
throw 'expected new overlay content\n$json';
}
overlays[filePath] = content;
} else if (change is ChangeContentOverlay) {
var content = overlays[filePath];
Expand Down Expand Up @@ -172,8 +169,9 @@ abstract class CommonInputConverter extends Converter<String, Operation> {
void processErrorResponse(String id, exception) {
var result = exception;
if (exception is UnimplementedError) {
if (exception.message.startsWith(ERROR_PREFIX)) {
result = json.decode(exception.message.substring(ERROR_PREFIX.length));
var message = exception.message;
if (message!.startsWith(ERROR_PREFIX)) {
result = json.decode(message.substring(ERROR_PREFIX.length));
}
}
processResponseResult(id, result);
Expand All @@ -186,7 +184,7 @@ abstract class CommonInputConverter extends Converter<String, Operation> {
/// Return a future that completes when the response is received
/// or `null` if the response has already been received
/// and the completer completed.
Future processExpectedResponse(String id, Completer completer) {
Future<void>? processExpectedResponse(String id, Completer completer) {
if (responseMap.containsKey(id)) {
logger.log(Level.INFO, 'processing cached response $id');
completer.complete(responseMap.remove(id));
Expand Down Expand Up @@ -228,7 +226,7 @@ abstract class CommonInputConverter extends Converter<String, Operation> {
return result;
}
if (json is Map) {
var result = <String, dynamic>{};
var result = <String, Object?>{};
json.forEach((origKey, value) {
result[translateSrcPaths(origKey)] = translateSrcPaths(value);
});
Expand All @@ -241,7 +239,7 @@ abstract class CommonInputConverter extends Converter<String, Operation> {
/// [InputConverter] converts an input stream
/// into a series of operations to be sent to the analysis server.
/// The input stream can be either an instrumentation or log file.
class InputConverter extends Converter<String, Operation> {
class InputConverter extends Converter<String, Operation?> {
final Logger logger = Logger('InputConverter');

/// A mapping of source path prefixes
Expand All @@ -259,7 +257,7 @@ class InputConverter extends Converter<String, Operation> {

/// The underlying converter used to translate lines into operations
/// or `null` if it has not yet been determined.
Converter<String, Operation> converter;
Converter<String, Operation?>? converter;

/// [active] is `true` if converting lines to operations
/// or `false` if an exception has occurred.
Expand All @@ -268,10 +266,11 @@ class InputConverter extends Converter<String, Operation> {
InputConverter(this.tmpSrcDirPath, this.srcPathMap);

@override
Operation convert(String line) {
Operation? convert(String line) {
if (!active) {
return null;
}
var converter = this.converter;
if (converter != null) {
try {
return converter.convert(line);
Expand Down Expand Up @@ -335,8 +334,8 @@ class PathMapEntry {
}

class _InputSink extends ChunkedConversionSink<String> {
final Converter<String, Operation> converter;
final Sink<Operation> outSink;
final Converter<String, Operation?> converter;
final Sink<Operation?> outSink;

_InputSink(this.converter, this.outSink);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:convert';

import 'package:analyzer/exception/exception.dart';
Expand All @@ -23,17 +21,18 @@ class InstrumentationInputConverter extends CommonInputConverter {
/// [readBuffer] holds the contents of the file being read from disk
/// as recorded in the instrumentation log
/// or `null` if not converting a "Read" entry.
StringBuffer readBuffer;
StringBuffer? readBuffer;

InstrumentationInputConverter(String tmpSrcDirPath, PathMap srcPathMap)
: super(tmpSrcDirPath, srcPathMap);

@override
Operation convert(String line) {
Operation? convert(String line) {
List<String> fields;
try {
fields = _parseFields(line);
if (fields.length < 2) {
var readBuffer = this.readBuffer;
if (readBuffer != null) {
readBuffer.writeln(fields.length == 1 ? fields[0] : '');
return null;
Expand Down Expand Up @@ -78,7 +77,7 @@ class InstrumentationInputConverter extends CommonInputConverter {
return null;
}

Map<String, dynamic> decodeJson(String line, String text) {
Map<String, Object?> decodeJson(String line, String text) {
try {
return asMap(json.decode(text));
} catch (e, s) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/analysis_server/benchmark/integration/local_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:io';

import 'package:path/path.dart';
Expand Down Expand Up @@ -77,7 +75,7 @@ void main(List<String> args) {
}

/// Print help and exit
void printHelp([String errMsg]) {
void printHelp([String? errMsg]) {
if (errMsg != null) {
print('');
print('Error: $errMsg');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:convert';

import 'package:analyzer/exception/exception.dart';
Expand All @@ -25,7 +23,7 @@ class LogFileInputConverter extends CommonInputConverter {
: super(tmpSrcDirPath, srcPathMap);

@override
Operation convert(String line) {
Operation? convert(String line) {
try {
var timeStampString = _parseTimeStamp(line);
var data = line.substring(timeStampString.length);
Expand Down
Loading

0 comments on commit 1bf4b0c

Please sign in to comment.