Name

SPVM::Sys::Time - System Calls for Time Manipulation

Description

The Sys::Process class of SPVM has methods to call system calls for time manipulation.

Usage

use Sys::Time;

my $epoch = Sys::Time->time;

my $time_info_local = Sys::Time->localtime($epoch);

my $time_info_utc = Sys::Time->gmtime($epoch);

Class Methods

time

static method time : long ();

Gets the current epoch time.

This method is the same as time function of Linux.

my $epoch = Sys::Time->time;

localtime

static method localtime : Sys::Time::Tm ($time : long);

Converts an epoch $time to the Sys::Time::Tm object that is local time.

This method is the same as localtime function of Linux.

my $time_info = Sys::Time->localtime($epoch);

gmtime

static method gmtime : Sys::Time::Tm ($time : long);

Converts an epoch $time to the Sys::Time::Tm object that is UTC.

This method is the same as gmtime function of Linux.

my $time_info = Sys::Time->gmtime($epoch);

gettimeofday

static method gettimeofday : int ($tv : Sys::Time::Timeval, $tz : Sys::Time::Timezone);

The functions gettimeofday() can get the time as well as a timezone. The tv argument is a struct timeval (as specified in <sys/time.h>):

See gettimeofday(2) - Linux man page in Linux.

clock

static method clock : long ()

The value returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC.

See clock(3) - Linux man page in Linux.

clock_gettime

static method clock_gettime : int ($clk_id : int, $tp : Sys::Time::Timespec);

The functions clock_gettime() retrieves the time of the specified clock clk_id.

See clock_gettime(3) - Linux man page in Linux.

The $tp is a Sys::Time::Timespec object.

clock_getres

static method clock_getres : int ($clk_id : int, $res : Sys::Time::Timespec);

The functions clock_getres() retrieves the time of the specified clock clk_id.

See clock_getres(3) - Linux man page in Linux.

The $res is a Sys::Time::Timespec object.

setitimer

static method setitimer : int ($which : int, $new_value : Sys::Time::Itimerval, $old_value : Sys::Time::Itimerval)

The function setitimer() sets the specified timer to the value in new_value. If old_value is non-NULL, the old value of the timer is stored there.

See setitimer(2) - Linux man page in Linux.

The $new_value is a Sys::Time::Itimerval object.

The $old_value is a Sys::Time::Itimerval object.

getitimer

static method getitimer : int ($which : int, $curr_value : Sys::Time::Itimerval);

The function getitimer() fills the structure pointed to by curr_value with the current setting for the timer specified by which (one of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF).

See getitimer(2) - Linux man page in Linux.

The $curr_value is a Sys::Time::Itimerval object.

times

static method times : long ($buffer : Sys::Time::Tms);

times() stores the current process times in the struct tms that buf points to. The struct tms is as defined in <sys/times.h>:

See the detail of the times function in the case of Linux.

clock_nanosleep

static method clock_nanosleep : int ($clockid : int, $flags : int, $request : Sys::Time::Timespec, $remain : Sys::Time::Timespec);

Like nanosleep(2), clock_nanosleep() allows the calling thread to sleep for an interval specified with nanosecond precision. It differs in allowing the caller to select the clock against which the sleep interval is to be measured, and in allowing the sleep interval to be specified as either an absolute or a relative value.

See the detail of the clock_nanosleep(2) - Linux man page function in the case of Linux.

The $request is a Sys::Time::Timespec object.

The $remain is a Sys::Time::Timespec object.

nanosleep

static method nanosleep : int ($rqtp : Sys::Time::Timespec, $rmtp : Sys::Time::Timespec);

The nanosleep() function shall cause the current thread to be suspended from execution until either the time interval specified by the rqtp argument has elapsed or a signal is delivered to the calling thread, and its action is to invoke a signal-catching function or to terminate the process.

See the detail of the nanosleep function in the case of Linux.

The rqtp is a Sys::Time::Timespec object.

The rmtp is a Sys::Time::Timespec object.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License