Skip to content

Commit

Permalink
correct the units shown for memory data
Browse files Browse the repository at this point in the history
The units returned by `to_byte/1` are kilobytes (KB), megabytes (MB) and
gigabytes (GB) but the actual numeric value are for kibibyte (KiB), mebibyte(MiB)
and gibibyte(GiB). This is because the division is by 1024.

I found this problem when I was comparing the value agaist the output of
rebar:info and didn't match.

I did a similar patch a few years ago on OTP's observer [1].

[1] erlang/otp#6063
  • Loading branch information
gonzalobf authored and zhongwencool committed Feb 17, 2025
1 parent 12ef053 commit c4eba84
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/observer_cli_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ to_byte(Byte) when is_integer(Byte), Byte < 1024 ->
[erlang:integer_to_list(Byte), $\s, $B];
%% kilobyte
to_byte(Byte) when Byte < 1024 * 1024 ->
[erlang:float_to_list(Byte / 1024, [{decimals, 4}]), $\s, $K, $B];
[erlang:float_to_list(Byte / 1024, [{decimals, 4}]), $\s, $K, $i, $B];
%% megabyte
to_byte(Byte) when Byte < 1024 * 1024 * 1024 ->
[erlang:float_to_list(Byte / (1024 * 1024), [{decimals, 4}]), $\s, $M, $B];
[erlang:float_to_list(Byte / (1024 * 1024), [{decimals, 4}]), $\s, $M, $i, $B];
%% megabyte
to_byte(Byte) when is_integer(Byte) ->
[erlang:float_to_list(Byte / (1024 * 1024 * 1024), [{decimals, 4}]), $\s, $G, $B];
[erlang:float_to_list(Byte / (1024 * 1024 * 1024), [{decimals, 4}]), $\s, $G, $i, $B];
%% process died
to_byte(Byte) ->
[to_list(Byte)].
Expand Down

0 comments on commit c4eba84

Please sign in to comment.