summaryrefslogtreecommitdiff
path: root/lib/os_mon/src/cpu_sup.erl
diff options
context:
space:
mode:
authorAlexander Clouter <alex@digriz.org.uk>2018-09-27 20:33:16 +0100
committerAlexander Clouter <alex@digriz.org.uk>2018-09-29 00:11:10 +0100
commitf2ca9d9cb14527fb5dd3016cbccd45355cc2a6c7 (patch)
tree885e38d07dd4849dc472a99ba4af802e925a4358 /lib/os_mon/src/cpu_sup.erl
parentf29c1d4bc5ac7cb578206a1193867c9037741bd3 (diff)
downloaderlang-f2ca9d9cb14527fb5dd3016cbccd45355cc2a6c7.tar.gz
Make Erlang's cpu_sup function better on Android
Due to `/proc` restrictions in newer Android releases enforced by SELinux, Erlang needs a fix so that it can get some basic CPU stats (use the `sysinfo` syscall rather than reading `/proc/loadavg`).
Diffstat (limited to 'lib/os_mon/src/cpu_sup.erl')
-rw-r--r--lib/os_mon/src/cpu_sup.erl26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/os_mon/src/cpu_sup.erl b/lib/os_mon/src/cpu_sup.erl
index 81e049ef22..ba2d89313e 100644
--- a/lib/os_mon/src/cpu_sup.erl
+++ b/lib/os_mon/src/cpu_sup.erl
@@ -220,17 +220,21 @@ code_change(_OldVsn, State, _Extra) ->
%% internal functions
%%----------------------------------------------------------------------
-get_uint32_measurement(Request, #internal{os_type = {unix, linux}}) ->
- {ok,F} = file:open("/proc/loadavg",[read,raw]),
- {ok,D} = file:read_line(F),
- ok = file:close(F),
- {ok,[Load1,Load5,Load15,_PRun,PTotal],_} = io_lib:fread("~f ~f ~f ~d/~d", D),
- case Request of
- ?avg1 -> sunify(Load1);
- ?avg5 -> sunify(Load5);
- ?avg15 -> sunify(Load15);
- ?ping -> 4711;
- ?nprocs -> PTotal
+get_uint32_measurement(Request, #internal{port = P, os_type = {unix, linux}}) ->
+ case file:open("/proc/loadavg",[read,raw]) of
+ {ok,F} ->
+ {ok,D} = file:read_line(F),
+ ok = file:close(F),
+ {ok,[Load1,Load5,Load15,_PRun,PTotal],_} = io_lib:fread("~f ~f ~f ~d/~d", D),
+ case Request of
+ ?avg1 -> sunify(Load1);
+ ?avg5 -> sunify(Load5);
+ ?avg15 -> sunify(Load15);
+ ?ping -> 4711;
+ ?nprocs -> PTotal
+ end;
+ {error,_} ->
+ port_server_call(P, Request)
end;
get_uint32_measurement(Request, #internal{port = P, os_type = {unix, Sys}}) when
Sys == sunos;