Merge pull request #4050 from zmstone/chore-delete-stale-code
chore(emqx_vm): delete stale code
This commit is contained in:
commit
23b2f4fa72
112
src/emqx_vm.erl
112
src/emqx_vm.erl
|
@ -40,13 +40,6 @@
|
||||||
-export([ get_ets_list/0
|
-export([ get_ets_list/0
|
||||||
, get_ets_info/0
|
, get_ets_info/0
|
||||||
, get_ets_info/1
|
, get_ets_info/1
|
||||||
, get_ets_object/0
|
|
||||||
, get_ets_object/1
|
|
||||||
]).
|
|
||||||
|
|
||||||
-export([ get_port_types/0
|
|
||||||
, get_port_info/0
|
|
||||||
, get_port_info/1
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([cpu_util/0]).
|
-export([cpu_util/0]).
|
||||||
|
@ -348,111 +341,6 @@ get_ets_info(Tab) ->
|
||||||
mapping(Entries)
|
mapping(Entries)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_ets_object() ->
|
|
||||||
[{Tab, get_ets_object(Tab)} || Tab <- ets:all()].
|
|
||||||
|
|
||||||
get_ets_object(Tab) ->
|
|
||||||
TabInfo = ets:info(Tab),
|
|
||||||
Size = proplists:get_value(size, TabInfo),
|
|
||||||
NameTab = proplists:get_value(named_table, TabInfo),
|
|
||||||
if (Size == 0) or (NameTab == false) ->
|
|
||||||
[];
|
|
||||||
true ->
|
|
||||||
ets:tab2list(Tab)
|
|
||||||
end.
|
|
||||||
|
|
||||||
get_port_types() ->
|
|
||||||
lists:usort(fun({KA, VA},{KB, VB})-> {VA, KB} >{VB, KA} end,
|
|
||||||
ports_type_count([Type || {_Port, Type} <- ports_type_list()])).
|
|
||||||
|
|
||||||
get_port_info() ->
|
|
||||||
[get_port_info(Port) ||Port <- erlang:ports()].
|
|
||||||
|
|
||||||
get_port_info(PortTerm) ->
|
|
||||||
Port = transform_port(PortTerm),
|
|
||||||
[port_info(Port, Type) || Type <- [meta, signals, io, memory_used, specific]].
|
|
||||||
|
|
||||||
port_info(Port, meta) ->
|
|
||||||
{meta, List} = port_info_type(Port, meta, [id, name, os_pid]),
|
|
||||||
case port_info(Port, registered_name) of
|
|
||||||
[] -> {meta, List};
|
|
||||||
Name -> {meta, [Name | List]}
|
|
||||||
end;
|
|
||||||
|
|
||||||
port_info(PortTerm, signals) ->
|
|
||||||
port_info_type(PortTerm, signals, [connected, links, monitors]);
|
|
||||||
|
|
||||||
port_info(PortTerm, io) ->
|
|
||||||
port_info_type(PortTerm, io, [input, output]);
|
|
||||||
|
|
||||||
port_info(PortTerm, memory_used) ->
|
|
||||||
port_info_type(PortTerm, memory_used, [memory, queue_size]);
|
|
||||||
|
|
||||||
port_info(PortTerm, specific) ->
|
|
||||||
Port = transform_port(PortTerm),
|
|
||||||
Props = case erlang:port_info(Port, name) of
|
|
||||||
{_, Type} when Type =:= "udp_inet";
|
|
||||||
Type =:= "tcp_inet";
|
|
||||||
Type =:= "sctp_inet" ->
|
|
||||||
try inet:getstat(Port) of
|
|
||||||
{ok, Stats} -> [{statistics, Stats}];
|
|
||||||
{error, _} -> []
|
|
||||||
catch
|
|
||||||
_Error:_Reason -> []
|
|
||||||
end ++
|
|
||||||
try inet:peername(Port) of
|
|
||||||
{ok, Peer} -> [{peername, Peer}];
|
|
||||||
_ -> []
|
|
||||||
catch
|
|
||||||
_Error:_Reason -> []
|
|
||||||
end ++
|
|
||||||
try inet:sockname(Port) of
|
|
||||||
{ok, Local} -> [{sockname, Local}];
|
|
||||||
{error, _} -> []
|
|
||||||
catch
|
|
||||||
_Error:_Reason -> []
|
|
||||||
end ++
|
|
||||||
try inet:getopts(Port, ?SOCKET_OPTS ) of
|
|
||||||
{ok, Opts} -> [{options, Opts}];
|
|
||||||
{error, _} -> []
|
|
||||||
catch
|
|
||||||
_Error:_Reason -> []
|
|
||||||
end;
|
|
||||||
{_, "efile"} ->
|
|
||||||
[];
|
|
||||||
_ ->
|
|
||||||
[]
|
|
||||||
end,
|
|
||||||
{specific, Props};
|
|
||||||
port_info(PortTerm, Key) when is_atom(Key) ->
|
|
||||||
Port = transform_port(PortTerm),
|
|
||||||
erlang:port_info(Port, Key).
|
|
||||||
|
|
||||||
port_info_type(PortTerm, Type, Keys) ->
|
|
||||||
Port = transform_port(PortTerm),
|
|
||||||
{Type, [erlang:port_info(Port, Key) || Key <- Keys]}.
|
|
||||||
|
|
||||||
transform_port(Port) when is_port(Port) -> Port;
|
|
||||||
transform_port("#Port<0." ++ Id) ->
|
|
||||||
N = list_to_integer(lists:sublist(Id, length(Id) - 1)),
|
|
||||||
transform_port(N);
|
|
||||||
transform_port(N) when is_integer(N) ->
|
|
||||||
Name = iolist_to_binary(atom_to_list(node())),
|
|
||||||
NameLen = iolist_size(Name),
|
|
||||||
Vsn = binary:last(term_to_binary(self())),
|
|
||||||
Bin = <<131, 102, 100, NameLen:2/unit:8, Name:NameLen/binary, N:4/unit:8, Vsn:8>>,
|
|
||||||
binary_to_term(Bin).
|
|
||||||
|
|
||||||
ports_type_list() ->
|
|
||||||
[{Port, PortType} || Port <- erlang:ports(),
|
|
||||||
{_, PortType} <- [erlang:port_info(Port, name)]].
|
|
||||||
|
|
||||||
ports_type_count(Types) ->
|
|
||||||
DictTypes = lists:foldl(fun(Type, Acc)->
|
|
||||||
dict:update_counter(Type, 1, Acc)
|
|
||||||
end, dict:new(), Types),
|
|
||||||
dict:to_list(DictTypes).
|
|
||||||
|
|
||||||
mapping(Entries) ->
|
mapping(Entries) ->
|
||||||
mapping(Entries, []).
|
mapping(Entries, []).
|
||||||
mapping([], Acc) -> Acc;
|
mapping([], Acc) -> Acc;
|
||||||
|
|
|
@ -64,30 +64,6 @@ t_get_ets_info(_Config) ->
|
||||||
end
|
end
|
||||||
end, false, EtsInfos)).
|
end, false, EtsInfos)).
|
||||||
|
|
||||||
t_get_ets_object(_Config) ->
|
|
||||||
ets:new(test, [named_table]),
|
|
||||||
[] = emqx_vm:get_ets_object(test),
|
|
||||||
ets:insert(test, {k, v}),
|
|
||||||
[{k, v}] = emqx_vm:get_ets_object(test).
|
|
||||||
|
|
||||||
t_get_port_types(_Config) ->
|
|
||||||
emqx_vm:get_port_types().
|
|
||||||
|
|
||||||
t_get_port_info(_Config) ->
|
|
||||||
emqx_vm:get_port_info(),
|
|
||||||
spawn(fun easy_server/0),
|
|
||||||
ct:sleep(100),
|
|
||||||
{ok, Sock} = gen_tcp:connect("localhost", 5678, [binary, {packet, 0}]),
|
|
||||||
emqx_vm:get_port_info(),
|
|
||||||
ok = gen_tcp:close(Sock),
|
|
||||||
[_Port | _] = erlang:ports().
|
|
||||||
|
|
||||||
t_transform_port(_Config) ->
|
|
||||||
[Port | _] = erlang:ports(),
|
|
||||||
?assertEqual(Port, emqx_vm:transform_port(Port)),
|
|
||||||
<<131, 102, 100, NameLen:2/unit:8, _Name:NameLen/binary, N:4/unit:8, _Vsn:8>> = erlang:term_to_binary(Port),
|
|
||||||
?assertEqual(Port, emqx_vm:transform_port("#Port<0." ++ integer_to_list(N) ++ ">")).
|
|
||||||
|
|
||||||
t_scheduler_usage(_Config) ->
|
t_scheduler_usage(_Config) ->
|
||||||
emqx_vm:scheduler_usage(5000).
|
emqx_vm:scheduler_usage(5000).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue