瀏覽代碼

Add formatting for emfile and for various system limits

pull/4/head
Andrew Thompson 14 年之前
父節點
當前提交
a6325a7831
共有 2 個文件被更改,包括 24 次插入1 次删除
  1. +17
    -1
      src/error_logger_lager_h.erl
  2. +7
    -0
      test/crash.erl

+ 17
- 1
src/error_logger_lager_h.erl 查看文件

@ -156,7 +156,23 @@ format_reason({badarith, [MFA|_]}) ->
["bad arithmetic expression in ", format_mfa(MFA)];
format_reason({{badmatch, Val}, [MFA|_]}) ->
[io_lib:format("no match of right hand value ~w in ", [Val]), format_mfa(MFA)];
%format_reason({system_limit,
format_reason({emfile, _Trace}) ->
"maximum number of file descriptors exhausted, check ulimit -n";
format_reason({system_limit, [{M, F, _}|_] = Trace}) ->
Limit = case {M, F} of
{erlang, open_port} ->
"maximum number of ports exceeded";
{erlang, spawn} ->
"maximum number of processes exceeded";
{erlang, spawn_opt} ->
"maximum number of processes exceeded";
{erlang, list_to_atom} ->
"tried to create an atom larger than 255, or maximum atom count exceeded";
_ ->
{Str, _} = trunc_io:print(Trace, 500),
Str
end,
["system limit: ", Limit];
format_reason({badarg, [MFA,MFA2|_]}) ->
case MFA of
{_M, _F, A} when is_list(A) ->

+ 7
- 0
test/crash.erl 查看文件

@ -55,6 +55,13 @@ handle_call(badarg2, _, State) ->
handle_call(system_limit, _, State) ->
Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
{reply, Res, State};
handle_call(process_limit, _, State) ->
%% run with +P 300 to make this crash
[erlang:spawn(fun() -> timer:sleep(5000) end) || _ <- lists:seq(0, 500)],
{reply, ok, State};
handle_call(port_limit, _, State) ->
[erlang:open_port({spawn, "ls"}, []) || _ <- lists:seq(0, 1024)],
{reply, ok, State};
handle_call(noproc, _, State) ->
Res = gen_event:call(foo, bar, baz),
{reply, Res, State};

Loading…
取消
儲存