[erlang-questions] Probably cpu_sup bug?

Viacheslav V. Kovalev kovyl2404@REDACTED
Fri Jan 9 17:39:05 CET 2015


Probably cpu_sup bug?

Hello. I'am using Erlang E17 on Ubuntu boxes with kernel 3.16.0-28.
Some time ago I've noticed strange messages in logs.

> {{badmatch,{more,"~d",24,[51,1.090200e+02,1.199300e+02,1.487400e+02]}},
> [{cpu_sup,get_uint32_measurement,2,[{file,"cpu_sup.erl"},{line,226}]},
> {cpu_sup,measurement_server_loop,1,[{file,"cpu_sup.erl"},{line,585}]}]}

It comes from this code
https://github.com/erlang/otp/blob/maint/lib/os_mon/src/cpu_sup.erl#L226.
Actually there is `io_lib:fread/2` failed when tried to parse input
string read from `/proc/loadavg`. Looking on its input stack I believe
that input string was  "148.74 119.93 109.02 51/...". But `cpu_sup`
reads EXACTLY 24 characters from file (thinking that load avg's are
lesser than 100).

Doesn't this looks buggy? Why not to rewrite this code as following
(or something like that)?

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
    end;



More information about the erlang-questions mailing list