Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to find/run Flutter apps in profile mode #765

Closed
DanTup opened this issue Apr 2, 2018 · 10 comments
Closed

Make it easier to find/run Flutter apps in profile mode #765

DanTup opened this issue Apr 2, 2018 · 10 comments
Labels
in debugger Relates to the debug adapter or process of launching a debug session in flutter Relates to running Flutter apps is enhancement
Milestone

Comments

@DanTup
Copy link
Member

DanTup commented Apr 2, 2018

No description provided.

@DanTup DanTup added is enhancement in flutter Relates to running Flutter apps in debugger Relates to the debug adapter or process of launching a debug session labels Apr 2, 2018
@DanTup DanTup added this to the v2.12.0 milestone Apr 2, 2018
@DanTup
Copy link
Member Author

DanTup commented Apr 3, 2018

Seems like we probably can't do this without new APIs, as we can't launch the "currently selected debug config" nor provide extra arguments.

Opened microsoft/vscode#47122 requesting help (or a new feature).

@DanTup DanTup added the blocked on vs code / lsp / dap Requires a change in VS Code to progress label Apr 3, 2018
@DanTup DanTup modified the milestones: v2.12.0, On Deck Apr 3, 2018
@DanTup DanTup modified the milestones: On Deck, Backlog May 3, 2018
@InMatrix
Copy link

Any news about this issue? We just had a user complain about the difficulty of switching to a profile build in VS Code.

@DanTup
Copy link
Member Author

DanTup commented May 20, 2021

There's not a great way to do this right now (at least as I'd like), though perhaps we could do something more basic.

What I'd like to do:

  • Have a command: "Flutter: Run in Profile Mode" (or similar) that will use your active debug config (selected on the debug sidebar) but with "flutterMode": "profile" set. This means the args and other settings in your launch.config would be honoured.

Doing that requires that we can identify the selected launch config (microsoft/vscode#47122).

Without that, what we could do:

  • Have a command: "Flutter: Run in Profile Mode" that runs the Flutter app _detected from your open file and ignoring any custom launch config in your launch.json.

This makes things a little different to when you hit F5 (for example if you have multiple apps in your workspace, we might launch a different one to what pressing F5 would do), although for the majority of users (anyone without a launch.json at all, or that hasn't customised it) it would probably be approximately the same.

We could also add an additional "Profile" CodeLens link (next to Run/Debug on the main method) that would do the same, although for Flutter apps it's probably not that common for users to launch from there (it's probably not that often you're inside your lib/main.dart for a real app).

Thoughts?

@InMatrix
Copy link

For the specific user I mentioned above, he did have some environmental variables in his launch config, so supporting your first option is needed.

However, I agree with you that most Flutter projects probably don't have an existing launch.config. Having the IDE create a default launch.config for building the app in profile mode would be convenient. Maybe the following logic would be reasonable when the user issues the command "Flutter: Run in Profile Mode":

  • If the project doesn't have launch.config, then create a launch.config with both debug and profile modes included and run the app in profile mode.
  • If the project already has a launch.config for debug mode, then show a message about how to add profile mode to the existing launch.config.

What do you think?

@DanTup
Copy link
Member Author

DanTup commented May 24, 2021

I think creating the launch.json is a little awkward - depending on the type of workspace open it could go into different places (for example in a multi-root workspace, the configs may go into the workspace file, or any of the individual folders). VS Code already has some UI to help create them that I think may be better to guide people towards:

Screenshot 2021-05-24 at 12 17 02

Clicking the "Create a launch.json file" link creates the file (and in a multi-root workspace lets the user choose which folder or whether to add to workspace config). Clicking "Show all automatic debug configurations" lets you pick a debug config and run it without the file (and we get to choose which ones go there).

So two things that I think would help (though I'm not sure they go far enough) would be:

  1. Add a specific profile-mode template to the completion here:

Screenshot 2021-05-24 at 12 19 46

  1. Add an automatic debug config for Flutter apps (accessed with the bottom link in the VS Code Debug sidebar screenshot above, or using the Debug: Select and Start Debugging command):

Screenshot 2021-05-24 at 12 20 40

Note: Clicking the cog icon on the right would instead copy that config into launch.json for you to customise.

Perhaps we could still add a command, but simplify it slightly to not try to create the file:

  • If there's no launch.json, just run a synthetic one that would be the same as pressing F5, but with flutterMode: profile
  • If there is, show a message (perhaps linking to this page and updating it to reflect how the side bar looks now).

@DanTup
Copy link
Member Author

DanTup commented May 24, 2021

I've done some of the things mentioned above because I think they make sense with or without a command:

  1. Added a snippet for when editing launch.configs:
    Screenshot 2021-05-24 at 12 42 48
  2. Changed the default config provided to VS Code when clicking "Create a launch.json" to now always include a profile config (it's easily deleted if you don't want it, but I think guiding people towards using profile mode more is probably not a bad thing):
    Screenshot 2021-05-24 at 12 44 12
  3. Added profile mode to the automatic configs (accessed from the bottom link in the side bar, and the Debug: Select and Start command):
    Screenshot 2021-05-24 at 12 45 02

The remaining question is whether to have a command like Debug: Run Flutter app in Profile mode and how it would behave (it occurs to me now, that just checking for a launch.json is also not reliable, as there could be launch configurations added by the workspace too). Perhaps trying to run a default configuration with just flutterMode: profile is the best we can do, and if users have env variables set we rely on them using the other options above?

@DanTup DanTup modified the milestones: Backlog, v3.23.0 May 24, 2021
@DanTup DanTup removed the blocked on vs code / lsp / dap Requires a change in VS Code to progress label May 24, 2021
@DanTup DanTup changed the title Add commands to run profiling/release mode without a launch.json Make it easier to find/run Flutter apps in profile mode May 24, 2021
@DanTup
Copy link
Member Author

DanTup commented May 24, 2021

In the interest of improved visibility (even if it's a less common way to run your Flutter app), I also added a CodeLens link for the main method of Flutter projects. Like Run/Debug this will always run a default empty config (the same as the Run config, but with `"flutterMode": "profile"), but also open the DevTools Performance page once the VM Service is available.

Screenshot 2021-05-24 at 12 56 01

DanTup added a commit that referenced this issue May 24, 2021
@InMatrix
Copy link

Perhaps trying to run a default configuration with just flutterMode: profile is the best we can do, and if users have env variables set we rely on them using the other options above?

This sounds reasonable. I do believe increasing the visibility of profile mode is very important. Both providing a command in the palette and a CodeLens link will be helpful. When Dart Code runs a profile build with the default configuration, would it make sense to show a message such as "Running the app in profile mode with a default configuration. To customize it, create or edit launch.json."?

Changed the default config provided to VS Code when clicking "Create a launch.json" to now always include a profile config

I like this idea. The caveat is that this could be the first time someone heard of "profile mode". Maybe we can add an inline comment to explain it briefly and link to documentation, if that's possible in launch.json?

@DanTup DanTup closed this as completed in 6213a33 May 26, 2021
@DanTup
Copy link
Member Author

DanTup commented May 26, 2021

Both providing a command in the palette and a CodeLens link will be helpful.

sgtm - I'd already added the CodeLens, and now I've added a Debug: Profile Flutter app command (I put it in Debug to match all the others for launching and attaching - "Debug" here means VS code's "launch the app" functionality rather than specifically debug mode).

When Dart Code runs a profile build with the default configuration, would it make sense to show a message such as "Running the app in profile mode with a default configuration. To customize it, create or edit launch.json."?

I'd added a one-time prompt to this effect when launching from the command palette. I didn't add it to the CodeLens as the existing Run/Debug links also use default configs (unless overwritten by launch.json) so that seems expected.

To behave more like the CodeLens, I also named it "Profile Flutter app" rathe than "Start in Profile Mode" and made it also open the DevTools Performance view.

My only niggle with this command is that if you do customise it in launch.config then you run this command again, it will continue to run the default config and not your new launch config. To use your launch config, you'd need to select it on the Debug side bar and start from there (or press F5 with it selected).

The caveat is that this could be the first time someone heard of "profile mode". Maybe we can add an inline comment to explain it briefly and link to documentation, if that's possible in launch.json?

Unfortunately we're unable to add comments here - we only supply the launch config to VS Code and it generates the file from that. It's not great, but if you search for "flutter profile mode" the top few search results on Google at least do a pretty good job of explaining what it is.

@DanTup
Copy link
Member Author

DanTup commented May 26, 2021

There's a beta version with the changes in here if you'd like to test it out before release:

https://github.com/Dart-Code/Dart-Code/releases/tag/v3.23.0-beta.1

If anything doesn't work as expected, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in debugger Relates to the debug adapter or process of launching a debug session in flutter Relates to running Flutter apps is enhancement
Projects
None yet
Development

No branches or pull requests

2 participants