ranch_app.erl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. %% Copyright (c) 2011-2018, Loïc Hoguin <essen@ninenines.eu>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. -module(ranch_app).
  15. -behaviour(application).
  16. -export([start/2]).
  17. -export([stop/1]).
  18. -export([profile_output/0]).
  19. -spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}.
  20. start(_, _) ->
  21. _ = consider_profiling(),
  22. ranch_sup:start_link().
  23. -spec stop(term()) -> ok.
  24. stop(_) ->
  25. ok.
  26. -spec profile_output() -> ok.
  27. profile_output() ->
  28. eprof:stop_profiling(),
  29. eprof:log("procs.profile"),
  30. eprof:analyze(procs),
  31. eprof:log("total.profile"),
  32. eprof:analyze(total).
  33. consider_profiling() ->
  34. case application:get_env(profile) of
  35. {ok, true} ->
  36. {ok, _Pid} = eprof:start(),
  37. eprof:start_profiling([self()]);
  38. _ ->
  39. not_profiling
  40. end.