You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make it easier to find/run Flutter apps in profile mode #765
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).
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.
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:
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:
Add a specific profile-mode template to the completion here:
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):
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).
I've done some of the things mentioned above because I think they make sense with or without a command:
Added a snippet for when editing launch.configs:
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):
Added profile mode to the automatic configs (accessed from the bottom link in the side bar, and the Debug: Select and Start command):
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?
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[/+]on 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.
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?
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.
Activity
DanTup commentedon 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).
InMatrix commentedon May 20, 2021
Any news about this issue? We just had a user complain about the difficulty of switching to a profile build in VS Code.
DanTup commentedon 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:
"flutterMode": "profile"set. This means theargsand other settings in yourlaunch.configwould be honoured.Doing that requires that we can identify the selected launch config (microsoft/vscode#47122).
Without that, what we could do:
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 pressingF5would 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.dartfor a real app).Thoughts?
InMatrix commentedon May 21, 2021
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":
launch.config, then create alaunch.configwith both debug and profile modes included and run the app in profile mode.launch.configfor debug mode, then show a message about how to add profile mode to the existinglaunch.config.What do you think?
DanTup commentedon 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:
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:
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:
flutterMode: profileDanTup commentedon May 24, 2021
I've done some of the things mentioned above because I think they make sense with or without a command:
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.jsonis also not reliable, as there could be launch configurations added by the workspace too). Perhaps trying to run a default configuration with justflutterMode: profileis the best we can do, and if users have env variables set we rely on them using the other options above?Add a launch config snippet for running Flutter in Profile mode
[-]Add commands to run profiling/release mode without a launch.json[/-][+]Make it easier to find/run Flutter apps in profile mode[/+]DanTup commentedon 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.
Add a "Profile" CodeLens link to Flutter projects
InMatrix commentedon May 25, 2021
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."?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 commentedon May 26, 2021
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).
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
F5with it selected).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 commentedon 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!