浏览代码

ft: 代码修改

master
SisMaker 3 年前
父节点
当前提交
5d14e553ae
共有 4 个文件被更改,包括 39 次插入23 次删除
  1. +25
    -7
      include/eTpf.hrl
  2. +2
    -4
      src/callgrind/tpCallgrind.erl
  3. +2
    -2
      src/tracer/tpTracerFile.erl
  4. +10
    -10
      src/utils/tpTermCut.erl

+ 25
- 7
include/eTpf.hrl 查看文件

@ -2,13 +2,14 @@
-define(eTpfHole, '$eTpfHole').
%%
-define(MaxDepth, 3).
-define(MaxListSize, 32).
-define(MaxMapSize, 32).
-define(MaxTupleSize, 32).
-define(MaxBinSize, 128).
-define(MaxBitSize, ?MaxBinSize * 8).
-define(MaxNestStruct, 6).
-define(tcmIsCut, false).
-define(tcmDepth, 3).
-define(tcmListSize, 32).
-define(tcmMapSize, 32).
-define(tcmTupleSize, 32).
-define(tcmBinSize, 128).
-define(tcmBitSize, ?tcmBinSize * 8).
-define(tcmNestStruct, 6).
%%
-export_type([input/0, userInput/0, traceOpts/0, tracerOpts/0]).
@ -29,5 +30,22 @@ mode => trace | profile
}.
-type tracerOpts() :: #{
%% tracer for socket
port => pos_integer()
%% tracer for file
,filename_prefix => string()
, max_size => pos_integer()
, events_per_frame => pos_integer()
%% tracer for console
%% trace msg term cut cfg
,tcmIsCut => boolean() %% cut trace msg term
,tcmDepth => boolean() %% term cut时保留的最大深度
,tcmListSize => boolean() %% List term cut时保留的最大数量
,tcmMapSize => boolean() %% Map term cut时保留的最大数量
,tcmTupleSize => boolean() %% Tuple term cut时保留的最大数量
,tcmBitSize => boolean() %% Bits term cut时保留的最大字节数
,tcmNestStruct => boolean() %% term cut时保留的最大数量
}.

+ 2
- 4
src/callgrind/tpCallgrind.erl 查看文件

@ -9,10 +9,8 @@
%% @todo Add an option with a list of modules to exclude.
-type opts() :: #{
%% Whether we filter the output per process.
scope => global | per_process,
%% Whether we compute and save wait times.
running => boolean()
scope => global | per_process, %% Whether we filter the output per process.
running => boolean() %% Whether we compute and save wait times.
}.
-record(call, {

+ 2
- 2
src/tracer/tpTracerFile.erl 查看文件

@ -44,8 +44,8 @@ loop(State = #state{parent = Parent, size = Size, ioDevice = IoDevice, eventsPer
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], State);
{'EXIT', Parent, Reason} ->
terminate(Reason, State);
Msg0 ->
Msg = tpTermCut:cut(Msg0),
RMsg ->
Msg = tpTermCut:cut(RMsg),
Bin = term_to_binary(Msg),
BinSize = byte_size(Bin),
Buffer = <<Buffer0/binary, BinSize:32, Bin/binary>>,

+ 10
- 10
src/utils/tpTermCut.erl 查看文件

@ -11,28 +11,28 @@
cut(Term) ->
cut(Term, 1).
cut(_, Depth) when Depth > ?MaxDepth ->
cut(_, Depth) when Depth > ?tcmDepth ->
'$truncated11';
cut(Bits, _) when is_bitstring(Bits), bit_size(Bits) > ?MaxBitSize ->
<<CutBits:?MaxBinSize/binary, _/bits>> = Bits,
cut(Bits, _) when is_bitstring(Bits), bit_size(Bits) > ?tcmBitSize ->
<<CutBits:?tcmBitSize/binary, _/bits>> = Bits,
<<CutBits/binary, "$truncated">>;
cut(Term, Depth) when is_list(Term) ->
cutList(Term, Depth, 0, ?MaxListSize, 0, []);
cut(Term, Depth) when is_map(Term), Depth =:= ?MaxDepth ->
cutList(Term, Depth, 0, ?tcmListSize, 0, []);
cut(Term, Depth) when is_map(Term), Depth =:= ?tcmDepth ->
#{'$truncated' => '$truncated'};
cut(Term, Depth) when is_map(Term) ->
maps:from_list(cutMap(maps_to_list(Term, ?MaxMapSize), Depth, 0));
cut(Term, Depth) when is_tuple(Term), Depth =:= ?MaxDepth ->
maps:from_list(cutMap(maps_to_list(Term, ?tcmMapSize), Depth, 0));
cut(Term, Depth) when is_tuple(Term), Depth =:= ?tcmDepth ->
{'$truncated'};
cut(Term, Depth) when is_tuple(Term) ->
list_to_tuple(cutList(tuple_to_list(Term), Depth, 0, ?MaxTupleSize, 0, []));
list_to_tuple(cutList(tuple_to_list(Term), Depth, 0, ?tcmTupleSize, 0, []));
cut(Term, _) ->
Term.
cutList([], _, _, _, _, Acc) ->
lists:reverse(Acc);
cutList([Term | Tail], Depth, Len, MaxLen, NumStructs, Acc) ->
case Len >= MaxLen orelse NumStructs >= ?MaxNestStruct of
case Len >= MaxLen orelse NumStructs >= ?tcmNestStruct of
true ->
lists:reverse(['$truncated33' | Acc]);
_ ->
@ -45,7 +45,7 @@ cutList(Term, Depth, _, _, _, Acc) -> %% if List was a cons [[[a,a,a|b],1,2,3]|
cutMap([], _, _) ->
[];
cutMap(_, _, NumStructs) when NumStructs > ?MaxNestStruct ->
cutMap(_, _, NumStructs) when NumStructs > ?tcmNestStruct ->
[{'$truncated', '$truncated'}];
cutMap([{Key, Value} | Tail], Depth, NumStructs) ->
AddStruct = isStruct(Key) + isStruct(Value),

正在加载...
取消
保存