SisMaker 4 anni fa
parent
commit
68c7006eee
6 ha cambiato i file con 100 aggiunte e 93 eliminazioni
  1. +38
    -34
      src/gen_ipc.erl
  2. +55
    -52
      src/gen_srv.erl
  3. +1
    -1
      test/ping1.erl
  4. +4
    -4
      test/ping2.erl
  5. +1
    -1
      test/pong1.erl
  6. +1
    -1
      test/pong2.erl

+ 38
- 34
src/gen_ipc.erl Vedi File

@ -1050,11 +1050,11 @@ report_error(_EpmHer, {swapped, _, _}, _, _) -> ok;
report_error(#epmHer{epmId = EpmId, epmM = EpmM}, Reason, State, LastIn) ->
?LOG_ERROR(
#{
label=>{gen_ipc, epm_terminate},
label => {gen_ipc, epm_terminate},
handler => {EpmId, EpmM},
name => undefined,
last_message => LastIn,
state=> State,
state => State,
reason => Reason
},
#{
@ -2096,15 +2096,17 @@ format_log(Report) ->
limit_report(Report, unlimited) ->
Report;
limit_report(
#{label:={gen_ipc, terminate},
queue:=Q,
postponed:=Postponed,
module:=Module,
status:=FmtData,
timeouts:=Timeouts,
log:=Log,
reason:={Class, Reason, Stacktrace},
client_info:=ClientInfo} = Report,
#{
label := {gen_ipc, terminate},
queue := Q,
postponed := Postponed,
module := Module,
status := FmtData,
timeouts := Timeouts,
log := Log,
reason := {Class, Reason, Stacktrace},
client_info := ClientInfo
} = Report,
Depth) ->
Report#{
queue =>
@ -2153,25 +2155,26 @@ format_log(Report, FormatOpts0) ->
FormatOpts = maps:merge(Default, FormatOpts0),
IoOpts =
case FormatOpts of
#{ chars_limit:=unlimited} -> [];
#{ chars_limit:=Limit} -> [{chars_limit, Limit}]
#{chars_limit := unlimited} -> [];
#{chars_limit := Limit} -> [{chars_limit, Limit}]
end,
{Format, Args} = format_log_single(Report, FormatOpts),
io_lib:format(Format, Args, IoOpts).
format_log_single(
#{
label:={gen_ipc, terminate},
name:=Name,
queue:=Q,
label := {gen_ipc, terminate},
name := Name,
queue := Q,
%% postponed
%% isEnter
status:=FmtData,
status := FmtData,
%% timeouts
log:=Log,
reason:={Class, Reason, Stacktrace},
client_info:=ClientInfo},
#{single_line:=true, depth:=Depth} = FormatOpts) ->
log := Log,
reason := {Class, Reason, Stacktrace},
client_info := ClientInfo
},
#{single_line := true, depth := Depth} = FormatOpts) ->
P = p(FormatOpts),
{FixedReason, FixedStacktrace} = fix_reason(Class, Reason, Stacktrace),
{ClientFmt, ClientArgs} = format_client_log_single(ClientInfo, P, Depth),
@ -2221,18 +2224,19 @@ format_log_single(Report, FormatOpts) ->
format_log_multi(
#{
label:={gen_ipc, terminate},
name:=Name,
queue:=Q,
postponed:=Postponed,
module:=Module,
isEnter:=StateEnter,
status:=FmtData,
timeouts:=Timeouts,
log:=Log,
reason:={Class, Reason, Stacktrace},
client_info:=ClientInfo},
#{depth:=Depth} = FormatOpts) ->
label := {gen_ipc, terminate},
name := Name,
queue := Q,
postponed := Postponed,
module := Module,
isEnter := StateEnter,
status := FmtData,
timeouts := Timeouts,
log := Log,
reason := {Class, Reason, Stacktrace},
client_info := ClientInfo
},
#{depth := Depth} = FormatOpts) ->
P = p(FormatOpts),
{FixedReason, FixedStacktrace} = fix_reason(Class, Reason, Stacktrace),
{ClientFmt, ClientArgs} = format_client_log(ClientInfo, P, Depth),
@ -2375,7 +2379,7 @@ format_client_log({_Pid, {Name, Stacktrace}}, P, Depth) ->
end,
{Format, Args}.
p(#{ single_line:=Single, depth:=Depth, encoding:=Enc}) ->
p(#{single_line := Single, depth := Depth, encoding := Enc}) ->
"~" ++ single(Single) ++ mod(Enc) ++ p(Depth);
p(unlimited) ->
"p";

+ 55
- 52
src/gen_srv.erl Vedi File

@ -967,17 +967,18 @@ error_info(_Reason, application_controller, _From, _Msg, _Mod, _State, _Debug) -
ok;
error_info(Reason, Name, From, Msg, Module, Debug, State) ->
Log = sys:get_log(Debug),
?LOG_ERROR(#{label=>{gen_server, terminate},
name=>Name,
last_message=>Msg,
state=>format_status(terminate, Module, get(), State),
log=>format_log_state(Module, Log),
reason=>Reason,
client_info=>client_stacktrace(From)},
#{domain=>[otp],
report_cb=>fun gen_server:format_log/2,
error_logger=>#{tag=>error,
report_cb=>fun gen_server:format_log/1}}),
?LOG_ERROR(#{label => {gen_server, terminate},
name => Name,
last_message => Msg,
state => format_status(terminate, Module, get(), State),
log => format_log_state(Module, Log),
reason => Reason,
client_info => client_stacktrace(From)},
#{
domain => [otp],
report_cb => fun gen_server:format_log/2,
error_logger => #{tag => error, report_cb => fun gen_server:format_log/1}
}),
ok.
client_stacktrace(undefined) ->
@ -1012,21 +1013,23 @@ format_log(Report) ->
limit_report(Report, unlimited) ->
Report;
limit_report(#{ label:={gen_server, terminate},
last_message:=Msg,
state:=State,
log:=Log,
reason:=Reason,
client_info:=Client} = Report,
limit_report(#{label := {gen_server, terminate},
last_message := Msg,
state := State,
log := Log,
reason := Reason,
client_info := Client} = Report,
Depth) ->
Report#{last_message=>io_lib:limit_term(Msg, Depth),
state=>io_lib:limit_term(State, Depth),
log=>[io_lib:limit_term(L, Depth) || L <- Log],
reason=>io_lib:limit_term(Reason, Depth),
client_info=>limit_client_report(Client, Depth)};
limit_report(#{label:={gen_server, no_handle_info},
message:=Msg} = Report, Depth) ->
Report#{message=>io_lib:limit_term(Msg, Depth)}.
Report#{
last_message => io_lib:limit_term(Msg, Depth),
state => io_lib:limit_term(State, Depth),
log => [io_lib:limit_term(L, Depth) || L <- Log],
reason => io_lib:limit_term(Reason, Depth),
client_info => limit_client_report(Client, Depth)
};
limit_report(#{label := {gen_server, no_handle_info},
message := Msg} = Report, Depth) ->
Report#{message => io_lib:limit_term(Msg, Depth)}.
limit_client_report({From, {Name, Stacktrace}}, Depth) ->
{From, {Name, io_lib:limit_term(Stacktrace, Depth)}};
@ -1043,22 +1046,22 @@ format_log(Report, FormatOpts0) ->
FormatOpts = maps:merge(Default, FormatOpts0),
IoOpts =
case FormatOpts of
#{ chars_limit:=unlimited} ->
#{chars_limit := unlimited} ->
[];
#{ chars_limit:=Limit} ->
#{chars_limit := Limit} ->
[{chars_limit, Limit}]
end,
{Format, Args} = format_log_single(Report, FormatOpts),
io_lib:format(Format, Args, IoOpts).
format_log_single(#{ label:={gen_server, terminate},
name:=Name,
last_message:=Msg,
state:=State,
log:=Log,
reason:=Reason,
client_info:=Client},
#{ single_line:=true, depth:=Depth} = FormatOpts) ->
format_log_single(#{label := {gen_server, terminate},
name := Name,
last_message := Msg,
state := State,
log := Log,
reason := Reason,
client_info := Client},
#{single_line := true, depth := Depth} = FormatOpts) ->
P = p(FormatOpts),
Format1 = lists:append(["Generic server ", P, " terminating. Reason: ", P,
". Last message: ", P, ". State: ", P, "."]),
@ -1074,10 +1077,10 @@ format_log_single(#{label:={gen_server, terminate},
end,
{Format1 ++ ServerLogFormat ++ ClientLogFormat,
Args1 ++ ServerLogArgs ++ ClientLogArgs};
format_log_single(#{ label:={gen_server, no_handle_info},
module:=Module,
message:=Msg},
#{ single_line:=true, depth:=Depth} = FormatOpts) ->
format_log_single(#{label := {gen_server, no_handle_info},
module := Module,
message := Msg},
#{single_line := true, depth := Depth} = FormatOpts) ->
P = p(FormatOpts),
Format = lists:append(["Undefined handle_info in ", P,
". Unhandled message: ", P, "."]),
@ -1092,14 +1095,14 @@ format_log_single(#{label:={gen_server, no_handle_info},
format_log_single(Report, FormatOpts) ->
format_log_multi(Report, FormatOpts).
format_log_multi(#{ label:={gen_server, terminate},
name:=Name,
last_message:=Msg,
state:=State,
log:=Log,
reason:=Reason,
client_info:=Client},
#{ depth:=Depth} = FormatOpts) ->
format_log_multi(#{label := {gen_server, terminate},
name := Name,
last_message := Msg,
state := State,
log := Log,
reason := Reason,
client_info := Client},
#{depth := Depth} = FormatOpts) ->
Reason1 = fix_reason(Reason),
{ClientFmt, ClientArgs} = format_client_log(Client, FormatOpts),
P = p(FormatOpts),
@ -1131,10 +1134,10 @@ format_log_multi(#{label:={gen_server, terminate},
end ++ ClientArgs
end,
{Format, Args};
format_log_multi(#{ label:={gen_server, no_handle_info},
module:=Module,
message:=Msg},
#{ depth:=Depth} = FormatOpts) ->
format_log_multi(#{label := {gen_server, no_handle_info},
module := Module,
message := Msg},
#{depth := Depth} = FormatOpts) ->
P = p(FormatOpts),
Format =
"** Undefined handle_info in ~p~n"
@ -1214,7 +1217,7 @@ format_client_log({_From, {Name, Stacktrace}}, FormatOpts) ->
end,
{Format, Args}.
p(#{ single_line:=Single, depth:=Depth, encoding:=Enc}) ->
p(#{single_line := Single, depth := Depth, encoding := Enc}) ->
"~" ++ single(Single) ++ mod(Enc) ++ p(Depth);
p(unlimited) ->
"p";

+ 1
- 1
test/ping1.erl Vedi File

@ -10,7 +10,7 @@ call(N) ->
doCall(0, Pid, StartTime) ->
EndTime = erlang:system_time(nanosecond),
exit(Pid, kill),
io:format("call1 over use time: ~p ns~n",[EndTime - StartTime]);
io:format("call1 over use time: ~p ns~n", [EndTime - StartTime]);
doCall(N, Pid, StartTime) ->
gen_server:call(Pid, ping),
doCall(N - 1, Pid, StartTime).

+ 4
- 4
test/ping2.erl Vedi File

@ -10,7 +10,7 @@ call(N) ->
doCall(0, Pid, StartTime) ->
EndTime = erlang:system_time(nanosecond),
exit(Pid, kill),
io:format("call2 over use time: ~p ns~n",[EndTime - StartTime]);
io:format("call2 over use time: ~p ns~n", [EndTime - StartTime]);
doCall(N, Pid, StartTime) ->
gen_srv:call(Pid, ping),
doCall(N - 1, Pid, StartTime).
@ -21,11 +21,11 @@ send(N) ->
doSend(N, Pid, StartTime).
doSend(0, Pid, StartTime) ->
% Ret = gen_srv:call(Pid, ping),
% Ret = gen_srv:call(Pid, ping),
Ret = 1,
EndTime = erlang:system_time(nanosecond),
exit(Pid, kill),
io:format("send2 over use time: ~p ~p ns~n",[Ret, EndTime - StartTime]);
io:format("send2 over use time: ~p ~p ns~n", [Ret, EndTime - StartTime]);
doSend(N, Pid, StartTime) ->
gen_srv:send(Pid, ping),
doSend(N - 1, Pid, StartTime).
@ -40,7 +40,7 @@ doCast(0, Pid, StartTime) ->
Ret = 1,
EndTime = erlang:system_time(nanosecond),
exit(Pid, kill),
io:format("cast2 over use time: ~p ~p ns~n",[Ret, EndTime - StartTime]);
io:format("cast2 over use time: ~p ~p ns~n", [Ret, EndTime - StartTime]);
doCast(N, Pid, StartTime) ->
gen_srv:cast(Pid, ping),
doCast(N - 1, Pid, StartTime).

+ 1
- 1
test/pong1.erl Vedi File

@ -7,7 +7,7 @@
start() ->
gen_server:start(?MODULE, 0, []).
init(_Args) ->
init(_Args) ->
{ok, 0}.
handle_call(ping, _From, State) ->

+ 1
- 1
test/pong2.erl Vedi File

@ -7,7 +7,7 @@
start() ->
gen_srv:start(?MODULE, 0, []).
init(_Args) ->
init(_Args) ->
{ok, 0}.
handleCall(ping, _State, _From) ->

Caricamento…
Annulla
Salva