Skip to content

Commit

Permalink
Measure the time to boot the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 21, 2024
1 parent 2db9796 commit 6e07eb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/mix/lib/mix/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ defmodule Mix.CLI do
Mix.start()

if env_variable_activated?("MIX_QUIET"), do: Mix.shell(Mix.Shell.Quiet)
if env_variable_activated?("MIX_DEBUG"), do: Mix.debug(true)

debug? =
if env_variable_activated?("MIX_DEBUG") do
Mix.debug(true)
true
else
false
end

if profile = System.get_env("MIX_PROFILE") do
Mix.State.put(:profile, String.split(profile, ","))
Expand All @@ -22,6 +29,13 @@ defmodule Mix.CLI do
:version ->
display_version()

nil when debug? ->
shell = Mix.shell()
shell.info("-> Running mix CLI")
{time, res} = :timer.tc(&proceed/1, [args])
shell.info(["<- Ran mix CLI in ", Integer.to_string(div(time, 1000)), "ms"])
res

nil ->
proceed(args)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/lib/mix/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ defmodule Mix.Task do
task in Mix.State.get(:profile, []) ->
shell = Mix.shell()
shell.info(["-> Profiling mix ", task_to_string(task, args), project_to_string(proj)])
Mix.Tasks.Profile.Eprof.profile(fun, warmup: false, set_on_spawn: false)
Mix.Tasks.Profile.Tprof.profile(fun, warmup: false, set_on_spawn: false)

true ->
fun.()
Expand Down

0 comments on commit 6e07eb6

Please sign in to comment.