diff options
author | Björn-Egil Dahlberg <[email protected]> | 2016-05-18 11:39:47 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2016-05-18 11:39:47 +0200 |
commit | 02288f2c754c8d54d138a736fbada68706bf035e (patch) | |
tree | 4bce0eb4968b02caed179e89b516a4b34e3c7f45 /lib | |
parent | a41966287e6d5d973ab15e327c5065ea1692900e (diff) | |
parent | bcf2da2389d1df99629ae524a4cc451bdf6224ae (diff) | |
download | otp-02288f2c754c8d54d138a736fbada68706bf035e.tar.gz otp-02288f2c754c8d54d138a736fbada68706bf035e.tar.bz2 otp-02288f2c754c8d54d138a736fbada68706bf035e.zip |
Merge branch 'egil/percept/fix-unmatched_return/OTP-13595'
* egil/percept/fix-unmatched_return/OTP-13595:
egd: Fix unmatched return warnings
egd: Small code style refactoring
percept: Fix unmatched return warnings
percept: Small code style refactoring
Diffstat (limited to 'lib')
-rw-r--r-- | lib/percept/src/egd.erl | 46 | ||||
-rw-r--r-- | lib/percept/src/egd.hrl | 3 | ||||
-rw-r--r-- | lib/percept/src/egd_font.erl | 11 | ||||
-rw-r--r-- | lib/percept/src/egd_render.erl | 1 | ||||
-rw-r--r-- | lib/percept/src/percept.erl | 52 | ||||
-rw-r--r-- | lib/percept/src/percept_db.erl | 54 | ||||
-rw-r--r-- | lib/percept/src/percept_graph.erl | 20 | ||||
-rw-r--r-- | lib/percept/src/percept_html.erl | 102 |
8 files changed, 126 insertions, 163 deletions
diff --git a/lib/percept/src/egd.erl b/lib/percept/src/egd.erl index d57b7bb81d..fe52da71f1 100644 --- a/lib/percept/src/egd.erl +++ b/lib/percept/src/egd.erl @@ -37,9 +37,7 @@ -include("egd.hrl"). %%========================================================================== -%% -%% Type definitions -%% +%% Type definitions %%========================================================================== %% @type egd_image() @@ -54,9 +52,7 @@ -type color() :: {float(), float(), float(), float()}. %%========================================================================== -%% -%% Interface functions -%% +%% Interface functions %%========================================================================== %% @spec create(integer(), integer()) -> egd_image() @@ -74,8 +70,7 @@ create(Width,Height) -> -spec destroy(Image :: egd_image()) -> ok. destroy(Image) -> - cast(Image, destroy), - ok. + cast(Image, destroy). %% @spec render(egd_image()) -> binary() @@ -113,8 +108,7 @@ render(Image, Type, Options) -> %% mainly. information(Pid) -> - cast(Pid, information), - ok. + cast(Pid, information). %% @spec line(egd_image(), point(), point(), color()) -> ok %% @doc Creates a line object from P1 to P2 in the image. @@ -126,8 +120,7 @@ information(Pid) -> Color :: color()) -> 'ok'. line(Image, P1, P2, Color) -> - cast(Image, {line, P1, P2, Color}), - ok. + cast(Image, {line, P1, P2, Color}). %% @spec color( Value | Name ) -> color() %% where @@ -152,74 +145,67 @@ color(_Image, Color) -> %% @doc Creates a text object. text(Image, P, Font, Text, Color) -> - cast(Image, {text, P, Font, Text, Color}), - ok. + cast(Image, {text, P, Font, Text, Color}). %% @spec rectangle(egd_image(), point(), point(), color()) -> ok %% @doc Creates a rectangle object. rectangle(Image, P1, P2, Color) -> - cast(Image, {rectangle, P1, P2, Color}), - ok. + cast(Image, {rectangle, P1, P2, Color}). %% @spec filledRectangle(egd_image(), point(), point(), color()) -> ok %% @doc Creates a filled rectangle object. filledRectangle(Image, P1, P2, Color) -> - cast(Image, {filled_rectangle, P1, P2, Color}), - ok. + cast(Image, {filled_rectangle, P1, P2, Color}). %% @spec filledEllipse(egd_image(), point(), point(), color()) -> ok %% @doc Creates a filled ellipse object. filledEllipse(Image, P1, P2, Color) -> - cast(Image, {filled_ellipse, P1, P2, Color}), - ok. + cast(Image, {filled_ellipse, P1, P2, Color}). %% @spec filledTriangle(egd_image(), point(), point(), point(), color()) -> ok %% @hidden %% @doc Creates a filled triangle object. filledTriangle(Image, P1, P2, P3, Color) -> - cast(Image, {filled_triangle, P1, P2, P3, Color}), - ok. + cast(Image, {filled_triangle, P1, P2, P3, Color}). %% @spec polygon(egd_image(), [point()], color()) -> ok %% @hidden %% @doc Creates a filled filled polygon object. polygon(Image, Pts, Color) -> - cast(Image, {polygon, Pts, Color}), - ok. + cast(Image, {polygon, Pts, Color}). %% @spec arc(egd_image(), point(), point(), color()) -> ok %% @hidden %% @doc Creates an arc with radius of bbx corner. arc(Image, P1, P2, Color) -> - cast(Image, {arc, P1, P2, Color}), - ok. + cast(Image, {arc, P1, P2, Color}). %% @spec arc(egd_image(), point(), point(), integer(), color()) -> ok %% @hidden %% @doc Creates an arc. arc(Image, P1, P2, D, Color) -> - cast(Image, {arc, P1, P2, D, Color}), - ok. + cast(Image, {arc, P1, P2, D, Color}). %% @spec save(binary(), string()) -> ok %% @doc Saves the binary to file. save(Binary, Filename) when is_binary(Binary) -> - file:write_file(Filename, Binary), + ok = file:write_file(Filename, Binary), ok. % --------------------------------- % Aux functions % --------------------------------- cast(Pid, Command) -> - Pid ! {egd, self(), Command}. + Pid ! {egd, self(), Command}, + ok. call(Pid, Command) -> Pid ! {egd, self(), Command}, diff --git a/lib/percept/src/egd.hrl b/lib/percept/src/egd.hrl index 1b125d3a08..fc0a7e10ee 100644 --- a/lib/percept/src/egd.hrl +++ b/lib/percept/src/egd.hrl @@ -41,6 +41,5 @@ -ifdef(debug). -define(dbg(X), io:format("DEBUG: ~p:~p~n",[?MODULE, X])). -else. --define(dbg(X), void). +-define(dbg(X), ok). -endif. - diff --git a/lib/percept/src/egd_font.erl b/lib/percept/src/egd_font.erl index 95203d5441..ef1cc434df 100644 --- a/lib/percept/src/egd_font.erl +++ b/lib/percept/src/egd_font.erl @@ -51,9 +51,7 @@ %% %%========================================================================== -%% -%% Interface functions -%% +%% Interface functions %%========================================================================== size(Font) -> @@ -70,15 +68,14 @@ load(Filename) -> load_font_header(Font). %%========================================================================== -%% -%% Internal functions -%% +%% Internal functions %%========================================================================== %% ETS handler functions initialize_table() -> - ets:new(egd_font_table, [named_table, ordered_set, public]). + egd_font_table = ets:new(egd_font_table, [named_table, ordered_set, public]), + ok. glyph_insert(Font, Code, Translation, LSs) -> Element = {{Font, Code}, Translation, LSs}, diff --git a/lib/percept/src/egd_render.erl b/lib/percept/src/egd_render.erl index c0075b8c42..6c708e3e86 100644 --- a/lib/percept/src/egd_render.erl +++ b/lib/percept/src/egd_render.erl @@ -662,4 +662,3 @@ eps_header(W,H) -> eps_footer() -> "%%EOF\n". - 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. diff --git a/lib/percept/src/percept_db.erl b/lib/percept/src/percept_db.erl index 6c2dddccac..6cbe3ce022 100644 --- a/lib/percept/src/percept_db.erl +++ b/lib/percept/src/percept_db.erl @@ -24,21 +24,17 @@ -module(percept_db). --export([ - start/0, - stop/0, - insert/1, - select/2, - select/1, - consolidate/0 - ]). +-export([start/0, + stop/0, + insert/1, + select/2, + select/1, + consolidate/0]). -include("percept.hrl"). -define(STOP_TIMEOUT, 1000). %%========================================================================== -%% -%% Type definitions -%% +%% Type definitions %%========================================================================== %% @type activity_option() = @@ -64,9 +60,7 @@ %%========================================================================== -%% -%% Interface functions -%% +%% Interface functions %%========================================================================== %% @spec start() -> ok | {started, Pid} | {restarted, Pid} @@ -100,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. @@ -123,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 @@ -186,26 +180,24 @@ consolidate() -> ok. %%========================================================================== -%% -%% Database loop -%% +%% Database loop %%========================================================================== 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(). @@ -232,9 +224,7 @@ loop_percept_db() -> end. %%========================================================================== -%% -%% Auxiliary functions -%% +%% Auxiliary functions %%========================================================================== %% cleans trace messages from external pids @@ -788,5 +778,3 @@ update_system_stop_ts(TS) -> Unhandled -> io:format("update_system_stop_ts, unhandled ~p ~n", [Unhandled]) end. - - 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 a8eb29b741..a675227584 100644 --- a/lib/percept/src/percept_html.erl +++ b/lib/percept/src/percept_html.erl @@ -18,22 +18,18 @@ %% %CopyrightEnd% -module(percept_html). --export([ - page/3, - codelocation_page/3, - databases_page/3, - load_database_page/3, - processes_page/3, - concurrency_page/3, - process_info_page/3 - ]). - --export([ - value2pid/1, - pid2value/1, - get_option_value/2, - join_strings_with/2 - ]). +-export([page/3, + codelocation_page/3, + databases_page/3, + load_database_page/3, + processes_page/3, + concurrency_page/3, + process_info_page/3]). + +-export([value2pid/1, + pid2value/1, + get_option_value/2, + join_strings_with/2]). -include("percept.hrl"). -include_lib("kernel/include/file.hrl"). @@ -42,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()). %%% --------------------------- %%% @@ -446,24 +442,24 @@ load_database_content(SessionId, _Env, Input) -> Filename = filename:join(Path, File), % Check path/file/filename - mod_esi:deliver(SessionId, "<div id=\"content\">"), + ok = mod_esi:deliver(SessionId, "<div id=\"content\">"), case file:read_file_info(Filename) of {ok, _} -> Content = "<center> Parsing: " ++ Filename ++ "<br> </center>", - mod_esi:deliver(SessionId, Content), - case percept:analyze(Filename) of - {error, Reason} -> - mod_esi:deliver(SessionId, error_msg("Analyze" ++ term2html(Reason))); - _ -> - Complete = "<center><a href=\"/cgi-bin/percept_html/page\">View</a></center>", - 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 = "<center><a href=\"/cgi-bin/percept_html/page\">View</a></center>", + 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, "</div>"). + ok = mod_esi:deliver(SessionId, "</div>"). codelocation_content(_Env, Input) -> Query = httpd:parse_query(Input), |