[dart2js] be resilient if we can't compute RAM usage.

Under some configurations, we can't obtain an observatoryURI to compute
the RAM utilization of dart2js. It appears this happens when building
in product mode: "./tools/build.py -m product create_sdk".

This changes the logic to return "N/A" when that happens.

Change-Id: Ic8c9e89a09603558db3ac07ea696aed77f2eaca1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245781
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/compiler/lib/src/common/ram_usage.dart b/pkg/compiler/lib/src/common/ram_usage.dart
index 76c5c2d..ade3c7b 100644
--- a/pkg/compiler/lib/src/common/ram_usage.dart
+++ b/pkg/compiler/lib/src/common/ram_usage.dart
@@ -18,10 +18,11 @@
 import 'dart:developer';
 import 'package:vm_service/vm_service_io.dart' as vm_service_io;
 
-Future<int> _currentHeapCapacity() async {
+Future<int?> _currentHeapCapacity() async {
   final info =
       await Service.controlWebServer(enable: true, silenceOutput: true);
-  final observatoryUri = info.serverUri!;
+  final observatoryUri = info.serverUri;
+  if (observatoryUri == null) return null;
   final wsUri = 'ws://${observatoryUri.authority}${observatoryUri.path}ws';
   final vmService = await vm_service_io.vmServiceConnectUri(wsUri);
   int sum = 0;
@@ -35,5 +36,6 @@
 
 Future<String> currentHeapCapacityInMb() async {
   final capacity = await _currentHeapCapacity();
+  if (capacity == null) return "N/A MB";
   return "${(capacity / (1024 * 1024)).toStringAsFixed(3)} MB";
 }