Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gather mem information for MacOS and Linux #20

Merged
merged 5 commits into from
May 11, 2022
Merged

Conversation

roznawsk
Copy link
Member

@roznawsk roznawsk commented May 4, 2022

No description provided.

@roznawsk roznawsk requested a review from mickel8 May 4, 2022 12:52
Comment on lines 43 to 53
@spec mem(atom()) :: integer()
defp mem(os) do
{memory_str, 0} =
case os do
:macOS -> System.cmd("sysctl", ["-n", "hw.memsize"])
:Linux -> System.cmd("awk", ["/MemTotal/ {print $2}", "/proc/meminfo"])
_os -> 0
end

memory_str |> String.trim() |> String.to_integer()
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments here

  1. I think that we shouldn't assume that there is awk installed in OS. Instead let's parse this file on our own.
  2. The same for sysctl. I am not sure about using it. Wouldn't it be possible to read some system file manually? Could we check how benchee does it?
  3. We should be prepared for situation where we couldn't get MEM info and in such a case return something like {:error, :couldnt_get_mem_info} or -1. We should then change typespec for mem in stuct SystemInfo to pos_integer() | :unknown or integer() depending on what we want to return from mem().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://unix.stackexchange.com/questions/82409/are-there-versions-of-unix-that-dont-have-awk-in-default-install I will assume, that all linux distributions have awk installed. I would assume as well, that all MacOS distibutions come with sysctl.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm 🤔 Okay so let's keep this as it is

end
end

def format_memory(_mem) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change typespec for format_memory. It requires non_neg_integer but here we are handling all non_pos_integers. Let's run dialyzer to check other typespecs too 😉

@roznawsk roznawsk requested a review from mickel8 May 6, 2022 07:30
@mickel8 mickel8 removed their request for review May 6, 2022 10:33
@mickel8
Copy link
Member

mickel8 commented May 6, 2022

As I wrote @shuntrho, it looks like I won't be able to continue supervising this project. Someone else has to be responsible for leading it.

cc @DominikWolek

@DominikWolek DominikWolek self-requested a review May 6, 2022 11:49
mix.exs Outdated
@@ -46,7 +46,8 @@ defmodule Beamchmark.MixProject do
{:bunch, "~> 1.3.0"},
{:dialyxir, "~> 1.1.0", only: :dev, runtime: false},
{:credo, "~> 1.6.1", only: :dev, runtime: false},
{:ex_doc, "~> 0.27.0", only: :dev, runtime: false}
{:ex_doc, "~> 0.27.0", only: :dev, runtime: false},
{:math, "~> 0.6.0"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use math 0.7.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version wasn't updated in Math's hexdocs, I just copy-pasted it :P.

def format_memory(mem) when is_integer(mem) do
log_mem = Math.log(mem, 1024)

cond do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: please also add the case for TB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense if we decide to use this function to parse disk space as well.

Comment on lines 8 to +16
otp_version: String.t(),
nif_version: String.t(),
os: atom(),
mem: pos_integer() | :unknown,
arch: String.t(),
num_cores: pos_integer()
}

@enforce_keys [:elixir_version, :otp_version, :nif_version, :os, :arch, :num_cores]
@enforce_keys [:elixir_version, :otp_version, :nif_version, :os, :mem, :arch, :num_cores]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: please sort the struct fields alphabetically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see the fields ordered logically rather than alphabetically, so I will leave them as they are.

@DominikWolek
Copy link
Contributor

image

@roznawsk roznawsk merged commit 61d73a8 into master May 11, 2022
@roznawsk roznawsk deleted the gather_mem_information branch May 26, 2022 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants