Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ devtools-profiler run \
-- dart run bin/profiled_app.dart
```

Profile your own Dart command:
Profile your own Dart file:

```bash
devtools-profiler run \
--cwd /path/to/your/dart/app \
bin/main.dart
```

Profile a full Dart command:

```bash
devtools-profiler run \
Expand All @@ -55,8 +63,11 @@ devtools-profiler run \
-- dart run bin/main.dart
```

Everything after `--` is the command being profiled. The first token must be
`dart` or `flutter`.
Bare Dart files are expanded to `dart run <file>`. For full Dart or Flutter
commands, put profiler options before the target command and use `--` when the
target command has its own options. Dart launches are held at isolate exit long
enough for final CPU and memory snapshots, so short scripts can still produce a
whole-session profile.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Profile a Flutter test run:

Expand Down Expand Up @@ -542,7 +553,8 @@ devtools-profiler help

Commands:

- `run -- <command...>` launches and profiles a Dart or Flutter command.
- `run [--] <dart-file|command...>` launches and profiles a Dart file, Dart
command, or Flutter command.
- `attach <vm-service-uri>` profiles an already-running VM service for a fixed
`--duration`.
- `summarize <path>` summarizes a session directory or profile artifact.
Expand Down Expand Up @@ -709,7 +721,9 @@ models. It does not depend on `packages/devtools_app`,

- Attach mode captures a fixed whole-session VM-service window from an existing
process, but explicit region markers normally require launch mode.
- The launched command must start with `dart` or `flutter`.
- Launch mode supports bare Dart files, Dart VM commands, and supported Flutter
commands. Put profiler options before the target, and use `--` when the
target command has its own options.
- `dart compile ...` targets and Flutter release/AOT targets are not supported.
- Flutter support is limited to VM-service targets from `flutter run` and
`flutter test`; browser/web profiling is not supported.
Expand Down
7 changes: 7 additions & 0 deletions packages/devtools_profiler_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.2.1-wip

- Added `devtools-profiler run <file>.dart` shorthand for profiling Dart files
without spelling out `dart run`.
- Improved Dart run behavior for short-lived scripts by using the backend's
exit-pause capture path instead of reporting a disposed VM service error.

## 0.2.0

- Added `inspect-classes` and the `profile_inspect_classes` MCP tool for
Expand Down
14 changes: 12 additions & 2 deletions packages/devtools_profiler_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ devtools-profiler run \

Profile your own app:

```bash
devtools-profiler run \
--cwd /path/to/app \
bin/main.dart
```

For full Dart or Flutter commands, put profiler options before the target
command. Use `--` when the target command has its own options:

```bash
devtools-profiler run \
--json \
Expand All @@ -53,8 +62,9 @@ devtools-profiler run \
-- dart run bin/main.dart
```

Everything after `--` is the command being profiled. The command must start
with `dart` or `flutter`.
Bare Dart files are expanded to `dart run <file>`. Dart launches are held at
isolate exit long enough for final CPU and memory snapshots, so short scripts
can still produce a whole-session profile.

Profile a Flutter test:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class RunCommand extends ProfilerCommand {

@override
String get invocation =>
'${runner!.executableName} run [options] -- <dart-or-flutter-command>';
'${runner!.executableName} run [options] [--] <dart-file|dart-or-flutter-command>';

@override
String formatUsage({bool includeDescription = true}) => usageWithExamples(
super.formatUsage(includeDescription: includeDescription),
const [
'devtools-profiler run bin/main.dart',
'devtools-profiler run -- dart run bin/main.dart',
'devtools-profiler run --cwd path/to/app -- dart run bin/main.dart',
'devtools-profiler run --duration 15s --cwd path/to/flutter_app -- flutter run -d linux -t lib/main.dart',
Expand All @@ -68,8 +69,9 @@ class RunCommand extends ProfilerCommand {
final commandArguments = argResults!.rest;
if (commandArguments.isEmpty) {
usageException(
'A profiled Dart or Flutter command is required after "--". '
'Put profiler options before "--" and the target command after it.',
'A profiled Dart file, Dart command, or Flutter command is required. '
'Put profiler options before the target command, and use "--" when '
'the target command has options that could be parsed as profiler options.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/devtools_profiler_cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: devtools_profiler_cli
description: CLI and local stdio MCP server for automated Dart and Flutter CPU profiling.

version: 0.2.0
version: 0.2.1-wip

environment:
sdk: '>=3.10.0 <4.0.0'
Expand All @@ -17,7 +17,7 @@ executables:
dependencies:
artisanal: ^0.3.0
dart_mcp: ^0.5.0
devtools_profiler_core: ^0.2.0
devtools_profiler_core: ^0.2.1-wip
path: ^1.9.0
stream_channel: ^2.1.4
vm_service: ^15.0.2
Expand Down
5 changes: 4 additions & 1 deletion packages/devtools_profiler_cli/test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ void main() {
expect(exitCode, 0);
expect(
stdoutCapture.text,
contains('devtools-profiler run [options] -- <dart-or-flutter-command>'),
contains(
'devtools-profiler run [options] [--] <dart-file|dart-or-flutter-command>',
),
);
expect(stdoutCapture.text, contains('Examples:'));
expect(stdoutCapture.text, contains('devtools-profiler run bin/main.dart'));
expect(
stdoutCapture.text,
contains('devtools-profiler run -- dart run bin/main.dart'),
Expand Down
7 changes: 7 additions & 0 deletions packages/devtools_profiler_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.2.1-wip

- Added bare Dart file launch support by expanding file paths to
`dart run <file>`.
- Improved short-lived Dart process profiling by holding isolates at exit long
enough to capture final whole-session CPU and memory snapshots.

## 0.2.0

- Added memory class artifact inspection helpers for stored session, region, and
Expand Down
17 changes: 15 additions & 2 deletions packages/devtools_profiler_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,21 @@ Future<void> main() async {
}
```

The launched command must start with `dart` or `flutter`. Compile targets,
Flutter release mode, and AOT targets are not supported.
The launched command must start with `dart` or `flutter`, or with a Dart file
path. Bare Dart files are expanded to `dart run <file>`:

```dart
await runner.run(
const ProfileRunRequest(
command: ['bin/main.dart'],
workingDirectory: '/path/to/app',
),
);
```

Dart launches are held at isolate exit long enough for final CPU and memory
snapshots, so short scripts can still produce a whole-session profile. Compile
targets, Flutter release mode, and AOT targets are not supported.

Flutter examples:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// A request to launch and profile a Dart or Flutter command.
///
/// Use this with [ProfileRunner.run] when the profiler should own the target
/// process lifecycle. The command must start with `dart` or `flutter`.
/// process lifecycle. The command must start with `dart` or `flutter`, or with
/// a Dart file path that will be expanded to `dart run <file>`.
/// Session artifacts are written under [artifactDirectory] when provided, or
/// under a generated `.dart_tool/devtools_profiler/sessions/...` directory
/// inside [workingDirectory] otherwise.
Expand All @@ -19,7 +20,7 @@ class ProfileRunRequest {

/// The command to launch.
///
/// The first argument must be `dart` or `flutter`.
/// The first argument must be `dart`, `flutter`, or a Dart file path.
final List<String> command;

/// The working directory to use for the launched process.
Expand Down
Loading
Loading