aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-06-06 14:26:47 +0200
committerLoïc Hoguin <[email protected]>2011-06-06 14:26:47 +0200
commitb00dd6fba212d1d12074df2ac3fb4ed795e77869 (patch)
tree4a371f646dd31df18f34826b12483a4c9c5a45b5
parent2fa1e5392802a271eb530f782e293d2a2a7895a2 (diff)
downloadcowboy-b00dd6fba212d1d12074df2ac3fb4ed795e77869.tar.gz
cowboy-b00dd6fba212d1d12074df2ac3fb4ed795e77869.tar.bz2
cowboy-b00dd6fba212d1d12074df2ac3fb4ed795e77869.zip
Add a 'profile' environment variable to start a profiler when the app starts.
-rw-r--r--src/cowboy_app.erl23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/cowboy_app.erl b/src/cowboy_app.erl
index 91f9818..114eb9a 100644
--- a/src/cowboy_app.erl
+++ b/src/cowboy_app.erl
@@ -15,7 +15,7 @@
-module(cowboy_app).
-behaviour(application).
--export([start/2, stop/1]). %% API.
+-export([start/2, stop/1, profile_output/0]). %% API.
-type application_start_type() :: normal
| {takeover, node()} | {failover, node()}.
@@ -24,8 +24,29 @@
-spec start(application_start_type(), any()) -> {ok, pid()}.
start(_Type, _Args) ->
+ consider_profiling(),
cowboy_sup:start_link().
-spec stop(any()) -> ok.
stop(_State) ->
ok.
+
+-spec profile_output() -> ok.
+profile_output() ->
+ eprof:stop_profiling(),
+ eprof:log("procs.profile"),
+ eprof:analyze(procs),
+ eprof:log("total.profile"),
+ eprof:analyze(total).
+
+%% Internal.
+
+-spec consider_profiling() -> profiling | not_profiling.
+consider_profiling() ->
+ case application:get_env(profile) of
+ {ok, true} ->
+ eprof:start(),
+ eprof:start_profiling([self()]);
+ _ ->
+ not_profiling
+ end.