From a4217eeeda0092b66970edda7b585eb4c4796700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Mon, 16 May 2016 18:39:31 +0200 Subject: percept: Fix unmatched return warnings --- lib/percept/src/percept.erl | 11 ++++-- lib/percept/src/percept_db.erl | 22 ++++++------ lib/percept/src/percept_graph.erl | 20 +++++------ lib/percept/src/percept_html.erl | 74 +++++++++++++++++++-------------------- 4 files changed, 67 insertions(+), 60 deletions(-) (limited to 'lib/percept') diff --git a/lib/percept/src/percept.erl b/lib/percept/src/percept.erl index d53be5f9e2..046e0b7518 100644 --- a/lib/percept/src/percept.erl +++ b/lib/percept/src/percept.erl @@ -151,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), @@ -328,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. diff --git a/lib/percept/src/percept_db.erl b/lib/percept/src/percept_db.erl index 7599a1cd74..6cbe3ce022 100644 --- a/lib/percept/src/percept_db.erl +++ b/lib/percept/src/percept_db.erl @@ -94,7 +94,7 @@ restart(PerceptDB)-> -spec do_start()-> pid(). do_start()-> - Pid = spawn( fun() -> init_percept_db() end), + Pid = spawn(fun() -> init_percept_db() end), erlang:register(percept_db, Pid), Pid. @@ -117,17 +117,17 @@ stop() -> %% @private %% @doc Stops the percept database, with a synchronous call. --spec stop_sync(pid())-> true. +-spec stop_sync(pid()) -> true. -stop_sync(Pid)-> +stop_sync(Pid) -> MonitorRef = erlang:monitor(process, Pid), - stop(), + _ = stop(), receive {'DOWN', MonitorRef, _Type, Pid, _Info}-> true after ?STOP_TIMEOUT-> - erlang:demonitor(MonitorRef, [flush]), - exit(Pid, kill) + erlang:demonitor(MonitorRef, [flush]), + exit(Pid, kill) end. %% @spec insert(tuple()) -> ok @@ -185,19 +185,19 @@ consolidate() -> init_percept_db() -> % Proc and Port information - ets:new(pdb_info, [named_table, private, {keypos, #information.id}, set]), + pdb_info = ets:new(pdb_info, [named_table, private, {keypos, #information.id}, set]), % Scheduler runnability - ets:new(pdb_scheduler, [named_table, private, {keypos, #activity.timestamp}, ordered_set]), + pdb_scheduler = ets:new(pdb_scheduler, [named_table, private, {keypos, #activity.timestamp}, ordered_set]), % Process and Port runnability - ets:new(pdb_activity, [named_table, private, {keypos, #activity.timestamp}, ordered_set]), + pdb_activity = ets:new(pdb_activity, [named_table, private, {keypos, #activity.timestamp}, ordered_set]), % System status - ets:new(pdb_system, [named_table, private, {keypos, 1}, set]), + pdb_system = ets:new(pdb_system, [named_table, private, {keypos, 1}, set]), % System warnings - ets:new(pdb_warnings, [named_table, private, {keypos, 1}, ordered_set]), + pdb_warnings = ets:new(pdb_warnings, [named_table, private, {keypos, 1}, ordered_set]), put(debug, 0), loop_percept_db(). diff --git a/lib/percept/src/percept_graph.erl b/lib/percept/src/percept_graph.erl index 1803e035ab..e5bbaca2b4 100644 --- a/lib/percept/src/percept_graph.erl +++ b/lib/percept/src/percept_graph.erl @@ -33,28 +33,28 @@ %% graph(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, binary_to_list(graph(Env, Input))). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, binary_to_list(graph(Env, Input))). %% activity %% @spec activity(SessionID, Env, Input) -> term() %% @doc An ESI callback implementation used by the httpd server. activity(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, binary_to_list(activity_bar(Env, Input))). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, binary_to_list(activity_bar(Env, Input))). proc_lifetime(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, binary_to_list(proc_lifetime(Env, Input))). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, binary_to_list(proc_lifetime(Env, Input))). percentage(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, binary_to_list(percentage(Env,Input))). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, binary_to_list(percentage(Env,Input))). scheduler_graph(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, binary_to_list(scheduler_graph(Env, Input))). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, binary_to_list(scheduler_graph(Env, Input))). graph(_Env, Input) -> Query = httpd:parse_query(Input), diff --git a/lib/percept/src/percept_html.erl b/lib/percept/src/percept_html.erl index e0649e1451..a675227584 100644 --- a/lib/percept/src/percept_html.erl +++ b/lib/percept/src/percept_html.erl @@ -38,47 +38,47 @@ %% API page(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, overview_content(Env, Input)), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, overview_content(Env, Input)), + ok = mod_esi:deliver(SessionID, footer()). processes_page(SessionID, _, _) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, processes_content()), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, processes_content()), + ok = mod_esi:deliver(SessionID, footer()). concurrency_page(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, concurrency_content(Env, Input)), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, concurrency_content(Env, Input)), + ok = mod_esi:deliver(SessionID, footer()). databases_page(SessionID, _, _) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, databases_content()), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, databases_content()), + ok = mod_esi:deliver(SessionID, footer()). codelocation_page(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, codelocation_content(Env, Input)), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, codelocation_content(Env, Input)), + ok = mod_esi:deliver(SessionID, footer()). process_info_page(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), - mod_esi:deliver(SessionID, menu()), - mod_esi:deliver(SessionID, process_info_content(Env, Input)), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, menu()), + ok = mod_esi:deliver(SessionID, process_info_content(Env, Input)), + ok = mod_esi:deliver(SessionID, footer()). load_database_page(SessionID, Env, Input) -> - mod_esi:deliver(SessionID, header()), + ok = mod_esi:deliver(SessionID, header()), % Very dynamic page, handled differently load_database_content(SessionID, Env, Input), - mod_esi:deliver(SessionID, footer()). + ok = mod_esi:deliver(SessionID, footer()). %%% --------------------------- %%% @@ -442,24 +442,24 @@ load_database_content(SessionId, _Env, Input) -> Filename = filename:join(Path, File), % Check path/file/filename - mod_esi:deliver(SessionId, "
"), + ok = mod_esi:deliver(SessionId, "
"), case file:read_file_info(Filename) of {ok, _} -> Content = "
Parsing: " ++ Filename ++ "
", - mod_esi:deliver(SessionId, Content), - case percept:analyze(Filename) of - {error, Reason} -> - mod_esi:deliver(SessionId, error_msg("Analyze" ++ term2html(Reason))); - _ -> - Complete = "
View
", - mod_esi:deliver(SessionId, Complete) - end; + ok = mod_esi:deliver(SessionId, Content), + case percept:analyze(Filename) of + {error, Reason} -> + ok = mod_esi:deliver(SessionId, error_msg("Analyze" ++ term2html(Reason))); + _ -> + Complete = "
View
", + ok = mod_esi:deliver(SessionId, Complete) + end; {error, Reason} -> - mod_esi:deliver(SessionId, error_msg("File" ++ term2html(Reason))) + ok = mod_esi:deliver(SessionId, error_msg("File" ++ term2html(Reason))) end, - mod_esi:deliver(SessionId, "
"). + ok = mod_esi:deliver(SessionId, "
"). codelocation_content(_Env, Input) -> Query = httpd:parse_query(Input), -- cgit v1.2.3