-
Notifications
You must be signed in to change notification settings - Fork 66
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
Added initial Solaris support to Benchee.System #422
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
Includes information such as elixir/erlang version, OS, CPU and memory. | ||
|
||
So far supports/should work for Linux, MacOS, FreeBSD and Windows. | ||
So far supports/should work for Linux, MacOS, FreeBSD, Solaris and Windows. | ||
""" | ||
|
||
alias Benchee.Conversion.Memory | ||
|
@@ -36,7 +36,7 @@ | |
erlang: String.t(), | ||
jit_enabled?: boolean(), | ||
num_cores: pos_integer(), | ||
os: :macOS | :Windows | :FreeBSD | :Linux, | ||
os: :macOS | :Windows | :FreeBSD | :Solaris | :Linux, | ||
cpu_speed: String.t(), | ||
available_memory: String.t() | ||
} | ||
|
@@ -105,6 +105,7 @@ | |
defp os(:darwin), do: :macOS | ||
defp os(:nt), do: :Windows | ||
defp os(:freebsd), do: :FreeBSD | ||
defp os(:sunos), do: :Solaris | ||
defp os(_), do: :Linux | ||
|
||
defp cpu_speed, do: cpu_speed(os()) | ||
|
@@ -121,6 +122,10 @@ | |
parse_cpu_for(:FreeBSD, system_cmd("sysctl", ["-n", "hw.model"])) | ||
end | ||
|
||
defp cpu_speed(:Solaris) do | ||
parse_cpu_for(:Solaris, system_cmd("kstat", ["-j", "cpu_info:0::brand"])) | ||
end | ||
|
||
defp cpu_speed(:Linux) do | ||
parse_cpu_for(:Linux, system_cmd("cat", ["/proc/cpuinfo"])) | ||
end | ||
|
@@ -139,6 +144,11 @@ | |
|
||
def parse_cpu_for(:FreeBSD, raw_output), do: String.trim(raw_output) | ||
|
||
def parse_cpu_for(:Solaris, raw_output) do | ||
{:ok, [decoded]} = Jason.decode(raw_output) | ||
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.13.4, OTP 23.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.13.4, OTP 24.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.13.4, OTP 25.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.14.5, OTP 23.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.14.5, OTP 24.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.14.5, OTP 25.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.8.2, OTP 20.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.10.4, OTP 21.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.11.4, OTP 22.3)
Check warning on line 148 in lib/benchee/system.ex GitHub Actions / Test on Ubuntu (Elixir 1.12.3, OTP 23.3)
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works by accident. Benchee does not depend on
so, we need make do here without |
||
decoded["data"]["brand"] | ||
end | ||
|
||
def parse_cpu_for(:Linux, raw_output) do | ||
match_info = Regex.run(@linux_cpuinfo_regex, raw_output, capture: :all_but_first) | ||
|
||
|
@@ -165,6 +175,10 @@ | |
parse_memory_for(:FreeBSD, system_cmd("sysctl", ["-n", "hw.physmem"])) | ||
end | ||
|
||
defp available_memory(:Solaris) do | ||
parse_memory_for(:Solaris, system_cmd("prtconf", ["-m"])) | ||
end | ||
|
||
defp available_memory(:Linux) do | ||
parse_memory_for(:Linux, system_cmd("cat", ["/proc/meminfo"])) | ||
end | ||
|
@@ -187,6 +201,12 @@ | |
Memory.format(memory) | ||
end | ||
|
||
defp parse_memory_for(:Solaris, raw_output) do | ||
{memory_in_megabytes, _} = Integer.parse(raw_output) | ||
{memory_in_bytes, _} = Memory.convert({memory_in_megabytes, :megabyte}, :byte) | ||
Memory.format(memory_in_bytes) | ||
end | ||
|
||
defp parse_memory_for(:Linux, raw_output) do | ||
["MemTotal:" <> memory_info] = Regex.run(~r/MemTotal.*kB/, raw_output) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a test may be neat, that's the reason that function is public :) It's also nice for me to have an example of the output: https://github.com/bencheeorg/benchee/blob/main/test/benchee/system_test.exs#L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Illumos kstat can be flagged to output data in json format:
More universally, the
-p
(parsable) flag can be used to reduce the output to key value pairs:This second command is effective across pretty much every variant of Solaris.