|
| 1 | +# |
| 2 | +# This file is part of elixir-lang. |
| 3 | +# |
| 4 | +# Copyright 2012-2024 Elixir Contributors |
| 5 | +# https://github.com/elixir-lang/elixir/blob/v1.17/lib/elixir/lib/system.ex |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | +# SPDX-License-Identifier: Apache-2.0 |
| 20 | +# |
| 21 | + |
| 22 | +defmodule System do |
| 23 | + @compile {:autoload, false} |
| 24 | + @type time_unit :: |
| 25 | + :second |
| 26 | + | :millisecond |
| 27 | + | :microsecond |
| 28 | + |
| 29 | + @doc """ |
| 30 | + Returns the current monotonic time in the given time unit. |
| 31 | +
|
| 32 | + This time is monotonically increasing and starts in an unspecified |
| 33 | + point in time. |
| 34 | + """ |
| 35 | + @spec monotonic_time(time_unit) :: integer |
| 36 | + def monotonic_time(unit) do |
| 37 | + :erlang.monotonic_time(unit) |
| 38 | + end |
| 39 | + |
| 40 | + @doc """ |
| 41 | + Returns the current system time in the given time unit. |
| 42 | +
|
| 43 | + It is the VM view of the `os_time/0`. They may not match in |
| 44 | + case of time warps although the VM works towards aligning |
| 45 | + them. This time is not monotonic. |
| 46 | + """ |
| 47 | + @spec system_time(time_unit) :: integer |
| 48 | + def system_time(unit) do |
| 49 | + :erlang.system_time(unit) |
| 50 | + end |
| 51 | +end |
0 commit comments