Created
October 9, 2020 00:07
-
-
Save IceDragon200/978c548f73172645ee25121168066b93 to your computer and use it in GitHub Desktop.
A small elixir script for bench marking the startup times of applications, specify the top-level app and this will print the slowest application in the tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
excluded = [:stdlib, :kernel, :compiler] | |
bench_startup = fn bench_startup, acc, app -> | |
if acc[app] do | |
acc | |
else | |
apps = Application.spec(app, :applications) -- excluded | |
inc_apps = Application.spec(app, :included_applications) -- excluded | |
all_apps = apps ++ inc_apps | |
acc = | |
Enum.reduce(all_apps, acc, fn app_name, acc -> | |
bench_startup.(bench_startup, acc, app_name) | |
end) | |
{elapsed, _value} = :timer.tc(fn -> | |
Application.ensure_all_started(app) | |
end) | |
Map.put(acc, app, elapsed) | |
end | |
end | |
times_by_app = bench_startup.(bench_startup, %{}, :your_app_name) | |
apps_by_startup = | |
Enum.sort_by(times_by_app, fn {_app, time} -> | |
time | |
end) | |
Enum.each(Enum.reverse(apps_by_startup), fn {app, time} -> | |
IO.puts "#{app}: #{time/1000}ms" | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment