Skip to content

Commit d7cef28

Browse files
bkonyiCommit Queue
authored andcommitted
[ Observatory ] Create fork of runtime/observatory at pkg/observatory
This change further prepares for the removal of Observatory from the shipped Dart SDK by creating a fork to be used by the remaining Observatory users. This is basically a straight copy of the contents from runtime/observatory with the exception of two new scripts: - `bin/observatory.dart`, a utility to launch Observatory - `bin/activate.dart`, which globally activates `bin/observatory.dart` as `observatory` This change also updates the presubmits to ensure that `runtime/observatory` is effectively placed in read-only mode to prevent any divergences with the fork. Work towards #50233 Change-Id: Iff3a7512058f36afa2a96d45d94a1dff424401d6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429800 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent b083c9a commit d7cef28

File tree

284 files changed

+56469
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+56469
-1
lines changed

PRESUBMIT.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,19 @@ def _CheckDartApiWinCSync(input_api, output_api):
537537
return []
538538

539539

540+
def _CheckNoRuntimeObservatoryChanges(input_api, output_api):
541+
"""Ensures that no further changes are made to runtime/observatory."""
542+
for f in input_api.AffectedFiles(include_deletes=False):
543+
path = f.LocalPath()
544+
if path.startswith("runtime/observatory/"):
545+
return [
546+
output_api.PresubmitError(
547+
'Observatory is being moved to pkg/observatory. Files under '
548+
'runtime/observatory should no longer be modified.')
549+
]
550+
return []
551+
552+
540553
def _CommonChecks(input_api, output_api):
541554
results = []
542555
results.extend(_CheckValidHostsInDEPS(input_api, output_api))
@@ -552,6 +565,7 @@ def _CommonChecks(input_api, output_api):
552565
results.extend(_CheckAnalyzerFiles(input_api, output_api))
553566
results.extend(_CheckDevCompilerSync(input_api, output_api))
554567
results.extend(_CheckDartApiWinCSync(input_api, output_api))
568+
results.extend(_CheckNoRuntimeObservatoryChanges(input_api, output_api))
555569
return results
556570

557571

pkg/observatory/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bootstrap_css
2+
out
3+
build
4+
.pub
5+
.idea
6+
.dart_tool

pkg/observatory/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Observatory Developer Tooling
2+
3+
_**WARNING: This tooling is deprecated and maintained on a best-effort basis by members of the Dart VM team.**_
4+
5+
## Activating Observatory
6+
7+
To easily serve Observatory without having to manually run `webdev serve` in this project, Observatory can be activated as a
8+
global `pub` package and run via the `observatory` tool.
9+
10+
To do this, run `dart bin/activate.dart`, which will create the `observatory` script at `$PUB_CACHE/bin`.
11+
12+
**Note:** If any changes are made to `bin/observatory.dart`, `dart bin/activate.dart` must be re-run to pick up the changes.
13+
14+
## Serving Observatory
15+
16+
To serve Observatory, simply run the `observatory` command. To automatically launch Observatory in Chrome, provide the `--launch`
17+
flag.
18+
19+
## Developing Observatory
20+
21+
When making changes to Observatory, run `observatory --debug` to run Observatory with DDC. This will allow for a more typical
22+
web development workflow as changes to the Observatory sources will be picked up automatically on a page refresh.
23+
24+
## Code Reviews
25+
26+
The development workflow of Dart (and Observatory) is based on code reviews.
27+
28+
Follow the code review [instructions][code_review] to be able to successfully
29+
submit your code.
30+
31+
The main reviewers for Observatory related CLs are:
32+
33+
- aam
34+
- rmacnak
35+
36+
[code_review]: https://github.com/dart-lang/sdk/blob/main/docs/Code-review-workflow-with-GitHub-and-Gerrit.md "Code Review"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
analyzer:
2+
errors:
3+
dead_code: info
4+
getter_not_subtype_setter_types: info
5+
missing_enum_constant_in_switch: info
6+
unused_element: info
7+
unused_field: info
8+
unused_import: info
9+
unused_local_variable: info
10+
linter:
11+
rules:
12+
- prefer_relative_imports

pkg/observatory/bin/activate.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
void main() {
8+
final snapshotDir = Directory(
9+
Platform.script.resolve('../.dart_tool/pub/bin/observatory').toFilePath(),
10+
);
11+
if (snapshotDir.existsSync()) {
12+
print('Deleting previous observatory script snapshot at $snapshotDir');
13+
snapshotDir.deleteSync(recursive: true);
14+
}
15+
16+
print('Globally activating observatory...');
17+
Process.runSync(Platform.resolvedExecutable, <String>[
18+
'pub',
19+
'global',
20+
'activate',
21+
'--source',
22+
'path',
23+
Platform.script.resolve('..').toFilePath(),
24+
]);
25+
print('observatory has been globally activated.');
26+
27+
try {
28+
Process.runSync('observatory', const <String>['--help']);
29+
} on ProcessException {
30+
stderr.writeln('''
31+
WARNING: observatory is globally activated but not available on your path.
32+
Be sure to add \$PUB_CACHE/bin/ to your path.
33+
''');
34+
}
35+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// IMPORTANT: to pick up changes made in this file, activate.dart must be
6+
// re-run to delete the old snapshot.
7+
8+
import 'dart:async';
9+
import 'dart:convert';
10+
import 'dart:io';
11+
12+
import 'package:args/args.dart';
13+
import 'package:args/command_runner.dart';
14+
import 'package:browser_launcher/browser_launcher.dart';
15+
16+
class ObservatoryCommand extends CommandRunner<void> {
17+
ObservatoryCommand()
18+
: super('Observatory', 'Serves the Observatory developer tool.');
19+
20+
static const String kHelp = 'help';
21+
static const String kDebug = 'debug';
22+
static const String kLaunch = 'launch';
23+
24+
@override
25+
final ArgParser argParser = ArgParser()
26+
..addFlag(
27+
kDebug,
28+
help:
29+
'Run Observatory in debug mode. Useful when making changes to '
30+
'Observatory to automatically pick up code changes.',
31+
)
32+
..addFlag(kLaunch, help: 'Launch Observatory in Chrome.');
33+
34+
@override
35+
Future<void> runCommand(ArgResults results) async {
36+
if (results.flag(kHelp)) {
37+
printUsage();
38+
return;
39+
}
40+
if (!_checkForWebDev()) {
41+
print('Warning: webdev is not installed. Installing it now...');
42+
_activateWebDev();
43+
print('webdev installed successfully.');
44+
}
45+
46+
await _startWebDev(
47+
debug: results.flag(kDebug),
48+
launch: results.flag(kLaunch),
49+
);
50+
}
51+
52+
bool _checkForWebDev() {
53+
final result = Process.runSync(Platform.resolvedExecutable, <String>[
54+
'pub',
55+
'global',
56+
'list',
57+
]);
58+
return result.stdout.contains('webdev');
59+
}
60+
61+
void _activateWebDev() {
62+
final result = Process.runSync(Platform.resolvedExecutable, <String>[
63+
'pub',
64+
'global',
65+
'activate',
66+
'webdev',
67+
]);
68+
if (result.exitCode != 0) {
69+
throw StateError('''
70+
Unexpected issue encountered while activating webdev.'
71+
72+
STDOUT:
73+
${result.stdout}
74+
75+
STDERR:
76+
${result.stderr}
77+
''');
78+
}
79+
}
80+
81+
Future<void> _startWebDev({required bool debug, required bool launch}) async {
82+
Directory.current = _findObservatoryProjectRoot();
83+
final process = await Process.start(Platform.resolvedExecutable, <String>[
84+
'pub',
85+
'global',
86+
'run',
87+
'webdev',
88+
'serve',
89+
if (!debug) '--release',
90+
]);
91+
final uriCompleter = Completer<String>();
92+
final uriRegExp = RegExp('Serving `web` on (http://.*)');
93+
late StreamSubscription<String> sub;
94+
sub = process.stdout.transform(utf8.decoder).listen((e) {
95+
if (uriRegExp.hasMatch(e)) {
96+
uriCompleter.complete(uriRegExp.firstMatch(e)!.group(1));
97+
sub.cancel();
98+
}
99+
});
100+
101+
final observatoryUri = await uriCompleter.future;
102+
print('Observatory is available at: $observatoryUri');
103+
104+
if (launch) {
105+
Chrome.start(<String>[observatoryUri]);
106+
}
107+
await process.exitCode;
108+
}
109+
110+
String _findObservatoryProjectRoot() {
111+
final uri = Platform.script;
112+
String relativePath = '..';
113+
if (uri.path.endsWith('.snapshot')) {
114+
relativePath = '../../../..';
115+
}
116+
return uri.resolve(relativePath).toFilePath();
117+
}
118+
}
119+
120+
Future<void> main(List<String> args) async {
121+
await ObservatoryCommand().run(args);
122+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library allocation_profiler;
6+
7+
import 'models.dart' as M;
8+
import 'service.dart' as S;
9+
10+
part 'src/allocation_profile/allocation_profile.dart';

pkg/observatory/lib/app.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library app;
6+
7+
import 'dart:async';
8+
import 'dart:convert';
9+
import 'dart:js_interop';
10+
11+
import 'package:logging/logging.dart';
12+
import 'package:stack_trace/stack_trace.dart';
13+
import 'package:web/web.dart' as web;
14+
15+
import 'elements.dart';
16+
import 'event.dart';
17+
import 'models.dart' as M;
18+
import 'repositories.dart';
19+
import 'service_html.dart';
20+
import 'src/elements/helpers/element_utils.dart';
21+
import 'src/elements/helpers/uris.dart';
22+
import 'tracer.dart';
23+
24+
export 'utils.dart';
25+
26+
part 'src/app/application.dart';
27+
part 'src/app/location_manager.dart';
28+
part 'src/app/notification.dart';
29+
part 'src/app/page.dart';
30+
part 'src/app/settings.dart';
31+
part 'src/app/view_model.dart';

pkg/observatory/lib/cli.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library cli;
6+
7+
import 'dart:async';
8+
9+
part 'src/cli/command.dart';

pkg/observatory/lib/debugger.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library debugger;
6+
7+
import 'dart:async';
8+
9+
import 'models.dart' as M;
10+
import 'service.dart';
11+
12+
part 'src/debugger/debugger.dart';
13+
part 'src/debugger/debugger_location.dart';

0 commit comments

Comments
 (0)