aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percept/src/percept.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/percept/src/percept.erl')
-rw-r--r--lib/percept/src/percept.erl52
1 files changed, 25 insertions, 27 deletions
diff --git a/lib/percept/src/percept.erl b/lib/percept/src/percept.erl
index 24ddf1bd14..046e0b7518 100644
--- a/lib/percept/src/percept.erl
+++ b/lib/percept/src/percept.erl
@@ -26,27 +26,24 @@
-module(percept).
-behaviour(application).
--export([
- profile/1,
- profile/2,
- profile/3,
- stop_profile/0,
- start_webserver/0,
- start_webserver/1,
- stop_webserver/0,
- stop_webserver/1,
- analyze/1,
- % Application behaviour
- start/2,
- stop/1]).
+-export([profile/1,
+ profile/2,
+ profile/3,
+ stop_profile/0,
+ start_webserver/0,
+ start_webserver/1,
+ stop_webserver/0,
+ stop_webserver/1,
+ analyze/1,
+ % Application behaviour
+ start/2,
+ stop/1]).
-include("percept.hrl").
%%==========================================================================
-%%
-%% Type definitions
-%%
+%% Type definitions
%%==========================================================================
%% @type percept_option() = procs | ports | exclusive
@@ -54,9 +51,7 @@
-type percept_option() :: 'procs' | 'ports' | 'exclusive' | 'scheduler'.
%%==========================================================================
-%%
-%% Application callback functions
-%%
+%% Application callback functions
%%==========================================================================
%% @spec start(Type, Args) -> {started, Hostname, Port} | {error, Reason}
@@ -76,9 +71,7 @@ stop(_State) ->
stop_webserver(0).
%%==========================================================================
-%%
-%% Interface functions
-%%
+%% Interface functions
%%==========================================================================
%% @spec profile(Filename::string()) -> {ok, Port} | {already_started, Port}
@@ -158,11 +151,11 @@ start_webserver() ->
{'started', string(), pos_integer()} | {'error', any()}.
start_webserver(Port) when is_integer(Port) ->
- application:load(percept),
+ ok = ensure_loaded(percept),
case whereis(percept_httpd) of
undefined ->
{ok, Config} = get_webserver_config("percept", Port),
- inets:start(),
+ ok = application:ensure_started(inets),
case inets:start(httpd, Config) of
{ok, Pid} ->
AssignedPort = find_service_port_from_pid(inets:services_info(), Pid),
@@ -217,9 +210,7 @@ stop_webserver(Port) ->
do_stop(Port,[]).
%%==========================================================================
-%%
-%% Auxiliary functions
-%%
+%% Auxiliary functions
%%==========================================================================
%% parse_and_insert
@@ -337,3 +328,10 @@ get_webserver_config(Servername, Port) when is_list(Servername), is_integer(Port
{bind_address, any},
{port, Port}],
{ok, Config}.
+
+ensure_loaded(App) ->
+ case application:load(App) of
+ ok -> ok;
+ {error,{already_loaded,App}} -> ok;
+ Error -> Error
+ end.