瀏覽代碼

ft: rumBkdFile修改

master
SisMaker 4 年之前
父節點
當前提交
5002acc4f1
共有 2 個檔案被更改,包括 29 行新增32 行删除
  1. +28
    -31
      src/backend/rumBkdThrottle.erl
  2. +1
    -1
      src/crashLog/rumCrashLog.erl

+ 28
- 31
src/backend/rumBkdThrottle.erl 查看文件

@ -1,20 +1,18 @@
%% @doc A simple gen_event backend used to monitor mailbox size and
%% switch log messages between synchronous and asynchronous modes.
%% A gen_event handler is used because a process getting its own mailbox
%% size doesn't involve getting a lock, and gen_event handlers run in their
%% parent's process.
-module(rumBkdThrottle).
-behaviour(gen_event).
%% @doc一个简单的gen_event后端
%%使gen_event处理程序是因为进程获得了自己的邮箱的大小不涉及获取锁定
%% gen_event处理程序在其中运行parent's的进程里
-behaviour(gen_emm).
-include("eRum.hrl").
-export([
init/1
, handle_call/2
, handle_event/2
, handle_info/2
, handleCall/2
, handleEvent/2
, handleInfo/2
, terminate/2,
code_change/3
]).
@ -22,46 +20,45 @@
-record(state, {
sink :: atom(),
hwm :: non_neg_integer(),
window_min :: non_neg_integer(),
window :: non_neg_integer(),
async = true :: boolean()
}).
init([{sink, Sink}, Hwm, Window]) ->
rumConfig:set({Sink, async}, true),
{ok, #state{sink = Sink, hwm = Hwm, window_min = Hwm - Window}}.
{ok, #state{sink = Sink, hwm = Hwm, window = Hwm - Window}}.
handle_call(mGetLogLevel, State) ->
{ok, ?LOG_NONE, State};
handle_call({mSetLogLevel, _Level}, State) ->
{ok, ok, State};
handle_call(_Request, State) ->
{ok, ok, State}.
handleCall(mGetLogLevel, State) ->
{reply, ?LOG_NONE, State};
handleCall({mSetLogLevel, _Level}, State) ->
{reply, ok, State};
handleCall(_Msg, State) ->
?ERR("~p call receive unexpect msg ~p ~n ", [?MODULE, _Msg]),
{reply, ok, State}.
handle_event({mWriteLog, _Message}, State) ->
{message_queue_len, Len} = erlang:process_info(self(), message_queue_len),
case {Len > State#state.hwm, Len < State#state.window_min, State#state.async} of
{true, _, true} ->
handleEvent({mWriteLog, _Message}, #state{hwm = Hwm, window = Window, async = Async} = State) ->
{_, MsgLen} = erlang:process_info(self(), message_queue_len),
if
MsgLen > Hwm andalso Async ->
%% need to flip to sync mode
rumConfig:set({State#state.sink, async}, false),
{ok, State#state{async = false}};
{_, true, false} ->
MsgLen < Window andalso not Async ->
%% need to flip to async mode
rumConfig:set({State#state.sink, async}, true),
{ok, State#state{async = true}};
_ ->
true ->
%% nothing needs to change
{okpan>, State}
kpS
end;
handle_event(_Event, State) ->
{okpan>, State}.
handleEvent(_Event, _State) ->
kpS.
handle_info(_Info, State) ->
{okpan>, State}.
handleInfo(_Info, _State) ->
kpS.
%% @private
terminate(_Reason, _State) ->
ok.
%% @private
code_change(_OldVsn, State, _Extra) ->
{ok, State}.

+ 1
- 1
src/crashLog/rumCrashLog.erl 查看文件

@ -1,7 +1,7 @@
-module(rumCrashLog).
%% @doc eRum crash log writererror_logger错误消息以其原始格式发送到`crash_log`, `crash_log`crash logging
%% Crash logs are printed safely using trunc_io via code mostly lifted from riak_err.
%%
%% `crashLogMsgSize` var用于指定最大值要记录的任何消息的大小
%% `crashLogFileSize` 0
%% `crashLogDate`

Loading…
取消
儲存