Skip to content

Commit 5533cc4

Browse files
author
José Valim
committed
Expose schedulers_online and otp_release information
1 parent 873dbc1 commit 5533cc4

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/elixir/lib/system.ex

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ defmodule System do
3434
next = System.monotonic_time()
3535
diff = next - prev
3636
37-
3837
Generally speaking, the VM provides three time measurements:
3938
4039
* `os_time/0` - the time reported by the OS. This time may be
@@ -157,8 +156,7 @@ defmodule System do
157156
%{build: build,
158157
date: get_date,
159158
revision: revision,
160-
version: version,
161-
}
159+
version: version}
162160
end
163161

164162
# Returns a string of the build info
@@ -730,6 +728,30 @@ defmodule System do
730728
:os.system_time(normalize_time_unit(unit))
731729
end
732730

731+
@doc """
732+
Returns the OTP release number.
733+
"""
734+
@spec otp_release :: String.t
735+
def otp_release do
736+
:erlang.list_to_binary :erlang.system_info(:otp_release)
737+
end
738+
739+
@doc """
740+
Returns the number of schedulers in the VM.
741+
"""
742+
@spec schedulers :: pos_integer
743+
def schedulers do
744+
:erlang.system_info(:schedulers)
745+
end
746+
747+
@doc """
748+
Returns the number of schedulers online in the VM.
749+
"""
750+
@spec schedulers_online :: pos_integer
751+
def schedulers_online do
752+
:erlang.system_info(:schedulers_online)
753+
end
754+
733755
@doc """
734756
Generates and returns an integer that is unique in the current runtime
735757
instance.

lib/elixir/test/elixir/system_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,16 @@ defmodule SystemTest do
187187
time = System.monotonic_time(:nanoseconds)
188188
assert abs(System.convert_time_unit(time, :nanoseconds, :microseconds)) < abs(time)
189189
end
190+
191+
test "schedulers/0" do
192+
assert System.schedulers >= 1
193+
end
194+
195+
test "schedulers_online/0" do
196+
assert System.schedulers_online >= 1
197+
end
198+
199+
test "otp_release/0" do
200+
assert is_binary System.otp_release
201+
end
190202
end

0 commit comments

Comments
 (0)