Wrap `os:type` for cpu:sup call
This commit is contained in:
parent
439c481e35
commit
6e0a269ff6
|
@ -451,26 +451,24 @@ mapping([{Key, Value}|Entries], Acc) ->
|
||||||
mapping(Entries, [{Key, Value}|Acc]).
|
mapping(Entries, [{Key, Value}|Acc]).
|
||||||
|
|
||||||
avg1() ->
|
avg1() ->
|
||||||
case cpu_sup:avg1() of
|
compat_windows(fun cpu_sup:avg1/0).
|
||||||
V when is_integer(V) -> V;
|
|
||||||
{error, _Reason} -> 0.00
|
|
||||||
end.
|
|
||||||
|
|
||||||
avg5() ->
|
avg5() ->
|
||||||
case cpu_sup:avg5() of
|
compat_windows(fun cpu_sup:avg5/0).
|
||||||
V when is_integer(V) -> V;
|
|
||||||
{error, _Reason} -> 0.00
|
|
||||||
end.
|
|
||||||
|
|
||||||
avg15() ->
|
avg15() ->
|
||||||
case cpu_sup:avg15() of
|
compat_windows(fun cpu_sup:avg15/0).
|
||||||
V when is_integer(V) -> V;
|
|
||||||
{error, _Reason} -> 0.00
|
|
||||||
end.
|
|
||||||
|
|
||||||
cpu_util() ->
|
cpu_util() ->
|
||||||
|
compat_windows(fun cpu_sup:util/0).
|
||||||
|
|
||||||
|
compat_windows(Fun) ->
|
||||||
case os:type() of
|
case os:type() of
|
||||||
{win32, nt} -> 0;
|
{win32, nt} -> 0;
|
||||||
_Other -> cpu_sup:util()
|
_Other -> handle_error(Fun())
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
handle_error(Value) when is_number(Value) ->
|
||||||
|
Value;
|
||||||
|
handle_error({error, _Reason}) ->
|
||||||
|
0.
|
||||||
|
|
Loading…
Reference in New Issue