Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otp 21 support #27

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/cluster_info_compat.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-ifndef(CLUSTER_INFO_COMPAT_HRL).

-ifdef(OTP_RELEASE). %% this implies OTP 21 or higher
-define(COMPAT_CATCH(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(COMPAT_GET_STACKTRACE(Stacktrace), Stacktrace).
-else.
-define(COMPAT_CATCH(Class, Reason, _), Class:Reason).
-define(COMPAT_GET_STACKTRACE(_), erlang:get_stacktrace()).
-endif.

-define(CLUSTER_INFO_COMPAT_HRL, 1).

-endif.
10 changes: 6 additions & 4 deletions src/cluster_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

-define(DICT_KEY, '^_^--cluster_info').

-include("cluster_info_compat.hrl").

%% application callbacks
%% Note: It is *not* necessary to start this application as a real/true OTP
%% application before you can use it. The application behavior here
Expand Down Expand Up @@ -118,9 +120,9 @@ dump_node(Node, Path, Opts) when is_atom(Node), is_list(Path) ->
{ok, MRef} = gmt_util_make_monitor(Remote),
Res = try
ok = collect_remote_info(Remote, FH)
catch X:Y ->
catch ?COMPAT_CATCH(X, Y, ST) ->
io:format("Error: ~P ~P at ~p\n",
[X, 20, Y, 20, erlang:get_stacktrace()]),
[X, 20, Y, 20, ?COMPAT_GET_STACKTRACE(ST)]),
error
after
catch file:close(FH),
Expand Down Expand Up @@ -262,9 +264,9 @@ dump_local_info(CPid, Opts) ->
[Name, node()]),
format_noescape(CPid, "<pre>\n", []),
Fun(CPid)
catch X:Y ->
catch ?COMPAT_CATCH(X, Y, ST) ->
format(CPid, "Error in ~p: ~p ~p at ~p\n",
[Name, X, Y, erlang:get_stacktrace()])
[Name, X, Y, ?COMPAT_GET_STACKTRACE(ST)])
after
format_noescape(CPid, "</pre>\n", []),
format_noescape(CPid, "\n",[])
Expand Down
10 changes: 6 additions & 4 deletions src/cluster_info_basic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

-module(cluster_info_basic).

-include("cluster_info_compat.hrl").

%% Registration API
-export([register/0]).

Expand Down Expand Up @@ -76,9 +78,9 @@ application_info(C) ->
cluster_info:format(C, " ~p\n\n", [application:get_all_key(App)]),
cluster_info:format(C, " Application:get_all_env(~p):\n", [App]),
cluster_info:format(C, " ~p\n\n", [application:get_all_env(App)])
catch X:Y ->
catch ?COMPAT_CATCH(X, Y, ST) ->
cluster_info:format(C, "Error for ~p: ~p ~p at ~p\n",
[App, X, Y, erlang:get_stacktrace()])
[App, X, Y, ?COMPAT_GET_STACKTRACE(ST)])
end || App <- lists:sort([A || {A, _, _} <- application:which_applications()])].

capture_ets_i(C) ->
Expand Down Expand Up @@ -166,9 +168,9 @@ loaded_modules(C) ->
[try
cluster_info:format(C, " Module ~p:\n", [Mod]),
cluster_info:format(C, " ~p\n\n", [Mod:module_info()])
catch X:Y ->
catch ?COMPAT_CATCH(X, Y, ST) ->
cluster_info:format(C, "Error for ~p: ~p ~p at ~p\n",
[Mod, X, Y, erlang:get_stacktrace()])
[Mod, X, Y, ?COMPAT_GET_STACKTRACE(ST)])
end || Mod <- lists:sort([M || {M, _} <- code:all_loaded()])].

memory_hogs(C, Num) ->
Expand Down