Skip to content

Commit 4475267

Browse files
bkonyiCommit Bot
authored and
Commit Bot
committed
[ VM / Service ] Add --log_service_response_sizes=<log.csv> debug option
Providing `--log_service_response_sizes` will cause the VM to log VM service response sizes to the provided file in CSV format. Also added `--service_response_sizes_directory` to the service test runner to allow for collecting response size data for the entire service test suite. TEST=Local Change-Id: I7aaf4ba936e2593e67d46ff9052e2130374ef461 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226805 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 1982520 commit 4475267

File tree

8 files changed

+99
-1
lines changed

8 files changed

+99
-1
lines changed

pkg/test_runner/lib/src/configuration.dart

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class TestConfiguration {
6464
this.keepGeneratedFiles,
6565
this.sharedOptions,
6666
String packages,
67+
this.serviceResponseSizesDirectory,
6768
this.suiteDirectory,
6869
this.outputDirectory,
6970
this.reproducingArguments,
@@ -176,6 +177,7 @@ class TestConfiguration {
176177
return _packages;
177178
}
178179

180+
final String serviceResponseSizesDirectory;
179181
final String outputDirectory;
180182
final String suiteDirectory;
181183
String get babel => configuration.babel;

pkg/test_runner/lib/src/options.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ has been specified on the command line.''',
338338
hide: true),
339339
_Option.bool('print_passing_stdout',
340340
'Print the stdout of passing, as well as failing, tests.',
341-
hide: true)
341+
hide: true),
342+
_Option('service_response_sizes_directory',
343+
'Log VM service response sizes in CSV files in the provided directory',
344+
hide: true),
342345
];
343346

344347
/// For printing out reproducing command lines, we don't want to add these
@@ -777,6 +780,8 @@ has been specified on the command line.''',
777780
localIP: data["local_ip"] as String,
778781
sharedOptions: sharedOptions,
779782
packages: data["packages"] as String,
783+
serviceResponseSizesDirectory:
784+
data['service_response_sizes_directory'] as String,
780785
suiteDirectory: data["suite_dir"] as String,
781786
outputDirectory: data["output_directory"] as String,
782787
reproducingArguments:

pkg/test_runner/lib/src/test_suite.dart

+2
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ class StandardTestSuite extends TestSuite {
763763
...vmOptionsList[vmOptionsVariant],
764764
...extraVmOptions,
765765
if (emitDdsTest) '-DUSE_DDS=true',
766+
if (configuration.serviceResponseSizesDirectory != null)
767+
'-DSERVICE_RESPONSE_SIZES_DIR=${configuration.serviceResponseSizesDirectory}',
766768
];
767769
var isCrashExpected = expectations.contains(Expectation.crash);
768770
var commands = _makeCommands(

runtime/observatory/tests/service/test_helper.dart

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export 'service_test_common.dart' show DDSTest, IsolateTest, VMTest;
1818
/// Determines whether DDS is enabled for this test run.
1919
const bool useDds = const bool.fromEnvironment('USE_DDS');
2020

21+
/// The directory to output VM service response size data files to.
22+
const String serviceResponseSizesDir =
23+
const String.fromEnvironment('SERVICE_RESPONSE_SIZES_DIR');
24+
2125
/// The extra arguments to use
2226
const List<String> extraDebuggingArgs = ['--lazy-async-stacks'];
2327

@@ -178,6 +182,15 @@ class _ServiceTesteeLauncher {
178182
if (!testeeControlsServer) {
179183
fullArgs.add('--enable-vm-service:$port');
180184
}
185+
if (serviceResponseSizesDir != null) {
186+
// Dump service response size details to a CSV. This feature is not used
187+
// on the build bots and the generated output will persist after the test
188+
// has completed.
189+
final dir = path.prettyUri(serviceResponseSizesDir);
190+
final testName = path.withoutExtension(path.basename(args.last));
191+
final logName = '${testName}_${useDds ? "" : "no_"}dds_sizes.csv';
192+
fullArgs.add('--log_service_response_sizes=$dir/$logName');
193+
}
181194
fullArgs.addAll(args);
182195

183196
return _spawnCommon(dartExecutable, fullArgs, <String, String>{});

runtime/observatory_2/tests/service_2/test_helper.dart

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export 'service_test_common.dart' show DDSTest, IsolateTest, VMTest;
2020
/// Determines whether DDS is enabled for this test run.
2121
const bool useDds = const bool.fromEnvironment('USE_DDS');
2222

23+
/// The directory to output VM service response size data files to.
24+
const String serviceResponseSizesDir =
25+
const String.fromEnvironment('SERVICE_RESPONSE_SIZES_DIR');
26+
2327
/// The extra arguments to use
2428
const List<String> extraDebuggingArgs = ['--lazy-async-stacks'];
2529

@@ -178,6 +182,15 @@ class _ServiceTesteeLauncher {
178182
if (!testeeControlsServer) {
179183
fullArgs.add('--enable-vm-service:$port');
180184
}
185+
if (serviceResponseSizesDir != null) {
186+
// Dump service response size details to a CSV. This feature is not used
187+
// on the build bots and the generated output will persist after the test
188+
// has completed.
189+
final dir = path.prettyUri(serviceResponseSizesDir);
190+
final testName = path.withoutExtension(path.basename(args.last));
191+
final logName = '${testName}_${useDds ? "" : "no_"}dds_sizes.csv';
192+
fullArgs.add('--log_service_response_sizes=$dir/$logName');
193+
}
181194
fullArgs.addAll(args);
182195

183196
return _spawnCommon(dartExecutable, fullArgs, <String, String>{});

runtime/vm/dart.cc

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ char* Dart::DartInit(const uint8_t* vm_isolate_snapshot,
343343
Isolate::InitVM();
344344
UserTags::Init();
345345
PortMap::Init();
346+
Service::Init();
346347
FreeListElement::Init();
347348
ForwardingCorpse::Init();
348349
Api::Init();
@@ -802,6 +803,7 @@ char* Dart::Cleanup() {
802803
ShutdownIsolate();
803804
vm_isolate_ = NULL;
804805
ASSERT(Isolate::IsolateListLength() == 0);
806+
Service::Cleanup();
805807
PortMap::Cleanup();
806808
UserTags::Cleanup();
807809
IsolateGroup::Cleanup();

runtime/vm/service.cc

+53
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,56 @@ DEFINE_FLAG(bool,
7272
"Print a message when an isolate is paused but there is no "
7373
"debugger attached.");
7474

75+
DEFINE_FLAG(
76+
charp,
77+
log_service_response_sizes,
78+
nullptr,
79+
"Log sizes of service responses and events to a file in CSV format.");
80+
81+
void* Service::service_response_size_log_file_ = nullptr;
82+
83+
void Service::LogResponseSize(const char* method, JSONStream* js) {
84+
if (service_response_size_log_file_ == nullptr) {
85+
return;
86+
}
87+
Dart_FileWriteCallback file_write = Dart::file_write_callback();
88+
char* entry =
89+
OS::SCreate(nullptr, "%s, %" Pd "\n", method, js->buffer()->length());
90+
(*file_write)(entry, strlen(entry), service_response_size_log_file_);
91+
free(entry);
92+
}
93+
94+
void Service::Init() {
95+
if (FLAG_log_service_response_sizes == nullptr) {
96+
return;
97+
}
98+
Dart_FileOpenCallback file_open = Dart::file_open_callback();
99+
Dart_FileWriteCallback file_write = Dart::file_write_callback();
100+
Dart_FileCloseCallback file_close = Dart::file_close_callback();
101+
if ((file_open == nullptr) || (file_write == nullptr) ||
102+
(file_close == nullptr)) {
103+
OS::PrintErr("Error: Could not access file callbacks.");
104+
UNREACHABLE();
105+
}
106+
ASSERT(service_response_size_log_file_ == nullptr);
107+
service_response_size_log_file_ =
108+
(*file_open)(FLAG_log_service_response_sizes, true);
109+
if (service_response_size_log_file_ == nullptr) {
110+
OS::PrintErr("Warning: Failed to open service response size log file: %s\n",
111+
FLAG_log_service_response_sizes);
112+
return;
113+
}
114+
}
115+
116+
void Service::Cleanup() {
117+
if (service_response_size_log_file_ == nullptr) {
118+
return;
119+
}
120+
Dart_FileCloseCallback file_close = Dart::file_close_callback();
121+
(*file_close)(service_response_size_log_file_);
122+
service_response_size_log_file_ = nullptr;
123+
}
124+
75125
static void PrintInvalidParamError(JSONStream* js, const char* param) {
76126
#if !defined(PRODUCT)
77127
js->PrintError(kInvalidParams, "%s: invalid '%s' parameter: %s", js->method(),
@@ -988,6 +1038,7 @@ ErrorPtr Service::InvokeMethod(Isolate* I,
9881038
return T->StealStickyError();
9891039
}
9901040
method->entry(T, &js);
1041+
Service::LogResponseSize(c_method_name, &js);
9911042
js.PostReply();
9921043
return T->StealStickyError();
9931044
}
@@ -1239,6 +1290,8 @@ void Service::PostEventImpl(Isolate* isolate,
12391290
}
12401291
}
12411292

1293+
Service::LogResponseSize(kind, event);
1294+
12421295
// Message is of the format [<stream id>, <json string>].
12431296
//
12441297
// Build the event message in the C heap to avoid dart heap

runtime/vm/service.h

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class StreamInfo {
8989

9090
class Service : public AllStatic {
9191
public:
92+
static void Init();
93+
static void Cleanup();
94+
9295
// Handles a message which is not directed to an isolate.
9396
static ErrorPtr HandleRootMessage(const Array& message);
9497

@@ -159,6 +162,9 @@ class Service : public AllStatic {
159162
const Instance& id,
160163
const Error& error);
161164

165+
// Logs the size of the contents of `js` to FLAG_log_service_response_sizes.
166+
static void LogResponseSize(const char* method, JSONStream* js);
167+
162168
// Enable/Disable timeline categories.
163169
// Returns True if the categories were successfully enabled, False otherwise.
164170
static bool EnableTimelineStreams(char* categories_list);
@@ -250,6 +256,8 @@ class Service : public AllStatic {
250256
static Dart_GetVMServiceAssetsArchive get_service_assets_callback_;
251257
static Dart_EmbedderInformationCallback embedder_information_callback_;
252258

259+
static void* service_response_size_log_file_;
260+
253261
static const uint8_t* dart_library_kernel_;
254262
static intptr_t dart_library_kernel_len_;
255263
};

0 commit comments

Comments
 (0)