Skip to content

Commit 313fa13

Browse files
Add appSizeBase and appSizeTest args to the devtools server (#2546)
1 parent 823c59e commit 313fa13

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

packages/devtools_server/lib/src/server.dart

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const argHelp = 'help';
3030
const argVmUri = 'vm-uri';
3131
const argEnableNotifications = 'enable-notifications';
3232
const argAllowEmbedding = 'allow-embedding';
33+
const argAppSizeBase = 'appSizeBase';
34+
const argAppSizeTest = 'appSizeTest';
3335
const argHeadlessMode = 'headless';
3436
const argDebugMode = 'debug';
3537
const argLaunchBrowser = 'launch-browser';
@@ -90,6 +92,8 @@ Future<void> _serveDevToolsWithArgs(
9092
: defaultTryPorts;
9193
final bool verboseMode = args[argVerbose];
9294
final String hostname = args[argHost];
95+
final String appSizeBase = args[argAppSizeBase];
96+
final String appSizeTest = args[argAppSizeTest];
9397

9498
if (help) {
9599
print('Dart DevTools version ${await _getVersion()}');
@@ -132,6 +136,8 @@ Future<void> _serveDevToolsWithArgs(
132136
profileFilename: profileFilename,
133137
verboseMode: verboseMode,
134138
hostname: hostname,
139+
appSizeBase: appSizeBase,
140+
appSizeTest: appSizeTest,
135141
);
136142
}
137143

@@ -155,6 +161,8 @@ Future<HttpServer> serveDevTools({
155161
shelf.Handler handler,
156162
String serviceProtocolUri,
157163
String profileFilename,
164+
String appSizeBase,
165+
String appSizeTest,
158166
}) async {
159167
hostname ??= 'localhost';
160168

@@ -208,12 +216,27 @@ Future<HttpServer> serveDevTools({
208216
_normalizeVmServiceUri(serviceProtocolUri).toString();
209217
}
210218

211-
String url = devToolsUrl.toString();
212-
// If serviceProtocolUri != null, add it to the url.
213-
if (serviceProtocolUri != null) {
214-
url = Uri.parse(devToolsUrl).replace(queryParameters: {
215-
'uri': serviceProtocolUri,
216-
}).toString();
219+
final queryParameters = {
220+
if (serviceProtocolUri != null) 'uri': serviceProtocolUri,
221+
if (appSizeBase != null) 'appSizeBase': appSizeBase,
222+
if (appSizeTest != null) 'appSizeTest': appSizeTest,
223+
};
224+
String url = Uri.parse(devToolsUrl)
225+
.replace(queryParameters: queryParameters)
226+
.toString();
227+
228+
// If app size parameters are present, open to the standalone `appsize`
229+
// page, regardless if there is a vm service uri specified. We only check
230+
// for the presence of [appSizeBase] here because [appSizeTest] may or may
231+
// not be specified (it should only be present for diffs). If [appSizeTest]
232+
// is present without [appSizeBase], we will ignore the parameter.
233+
if (appSizeBase != null) {
234+
final startQueryParamIndex = url.indexOf('?');
235+
if (startQueryParamIndex != -1) {
236+
url = '${url.substring(0, startQueryParamIndex)}'
237+
'/#/appsize'
238+
'${url.substring(startQueryParamIndex)}';
239+
}
217240
}
218241

219242
try {
@@ -494,6 +517,20 @@ ArgParser _createArgsParser(bool verbose) {
494517
argProfileMemoryOld,
495518
defaultsTo: 'memory_samples.json',
496519
hide: true,
520+
)
521+
..addOption(
522+
argAppSizeBase,
523+
valueHelp: 'appSizeBase',
524+
help: 'Path to the base app size file used for app size debugging.',
525+
hide: true,
526+
)
527+
..addOption(
528+
argAppSizeTest,
529+
valueHelp: 'appSizeTest',
530+
help: 'Path to the test app size file used for app size debugging. This '
531+
'file should only be specified if a base app size file (appSizeBase) '
532+
'is also specified.',
533+
hide: true,
497534
);
498535

499536
// Args to show for verbose mode.

0 commit comments

Comments
 (0)