From 6487aac5977cf470bc6a2cd0964da2850ee38717 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Thu, 30 Oct 2014 23:57:01 +0100 Subject: Introduce a new time API The old time API is based on erlang:now/0. The major issue with erlang:now/0 is that it was intended to be used for so many unrelated things. This tied these unrelated operations together and unnecessarily caused performance, scalability as well as accuracy, and precision issues for operations that do not need to have such issues. The new API spreads different functionality over multiple functions in order to improve on this. The new API consists of a number of new BIFs: - erlang:convert_time_unit/3 - erlang:monotonic_time/0 - erlang:monotonic_time/1 - erlang:system_time/0 - erlang:system_time/1 - erlang:time_offset/0 - erlang:time_offset/1 - erlang:timestamp/0 - erlang:unique_integer/0 - erlang:unique_integer/1 - os:system_time/0 - os:system_time/1 and a number of extensions of existing BIFs: - erlang:monitor(time_offset, clock_service) - erlang:system_flag(time_offset, finalize) - erlang:system_info(os_monotonic_time_source) - erlang:system_info(time_offset) - erlang:system_info(time_warp_mode) - erlang:system_info(time_correction) - erlang:system_info(start_time) See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information. --- lib/kernel/doc/src/os.xml | 48 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'lib/kernel/doc') diff --git a/lib/kernel/doc/src/os.xml b/lib/kernel/doc/src/os.xml index 2b57e75023..763bf01cc9 100644 --- a/lib/kernel/doc/src/os.xml +++ b/lib/kernel/doc/src/os.xml @@ -128,15 +128,50 @@ DirOut = os:cmd("dir"), % on Win32 platform environment is set using wide character interfaces.

+ + + Current OS system time + +

Returns current + OS system time + in native + time unit.

+ +

This time is not a monotonically increasing time.

+
+
+ + + Current OS system time + +

Returns current + OS system time + converted into the Unit passed as argument.

+ +

Calling os:system_time(Unit) is equivalent to: + erlang:convert_time_unit(os:system_time(), + native, Unit).

+ +

This time is not a monotonically increasing time.

+
+
Timestamp = {MegaSecs, Secs, MicroSecs} - Returna a timestamp from the OS in the erlang:now/0 format + Current OS system time on the erlang:timestamp/0 format -

Returns a tuple in the same format as erlang:now/0. The difference is that this function returns what the operating system thinks (a.k.a. the wall clock time) without any attempts at time correction. The result of two different calls to this function is not guaranteed to be different.

-

The most obvious use for this function is logging. The tuple can be used together with the function calendar:now_to_universal_time/1 -or calendar:now_to_local_time/1 to get calendar time. Using the calendar time together with the MicroSecs part of the return tuple from this function allows you to log timestamps in high resolution and consistent with the time in the rest of the operating system.

-

Example of code formatting a string in the format "DD Mon YYYY HH:MM:SS.mmmmmm", where DD is the day of month, Mon is the textual month name, YYYY is the year, HH:MM:SS is the time and mmmmmm is the microseconds in six positions:

+

Returns current + OS system time + in the same format as erlang:timestamp/0. + The tuple can be used together with the function + calendar:now_to_universal_time/1 + or calendar:now_to_local_time/1 to + get calendar time. Using the calendar time together with the MicroSecs part of the return + tuple from this function allows you to log timestamps in high resolution and consistent with the + time in the rest of the operating system.

+

Example of code formatting a string in the format "DD Mon YYYY HH:MM:SS.mmmmmm", where + DD is the day of month, Mon is the textual month name, YYYY is the year, HH:MM:SS is the time and + mmmmmm is the microseconds in six positions:

-module(print_time). -export([format_utc_timestamp/0]). @@ -155,6 +190,9 @@ format_utc_timestamp() -> 1> io:format("~s~n",[print_time:format_utc_timestamp()]). 29 Apr 2009 9:55:30.051711 +

OS system time can also be retreived by + os:system_time/0, + and os:system_time/1.

-- cgit v1.2.3