⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hires.pm

📁 Astercon2 开源软交换 2.2.0
💻 PM
📖 第 1 页 / 共 2 页
字号:
package Time::HiRes;use strict;use vars qw($VERSION $XS_VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);require Exporter;require DynaLoader;@ISA = qw(Exporter DynaLoader);@EXPORT = qw( );@EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval		 getitimer setitimer nanosleep clock_gettime clock_getres		 clock clock_nanosleep		 CLOCK_HIGHRES CLOCK_MONOTONIC CLOCK_PROCESS_CPUTIME_ID		 CLOCK_REALTIME CLOCK_SOFTTIME CLOCK_THREAD_CPUTIME_ID		 CLOCK_TIMEOFDAY CLOCKS_PER_SEC		 ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF		 TIMER_ABSTIME		 d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer		 d_nanosleep d_clock_gettime d_clock_getres		 d_clock d_clock_nanosleep);	$VERSION = '1.86';$XS_VERSION = $VERSION;$VERSION = eval $VERSION;sub AUTOLOAD {    my $constname;    ($constname = $AUTOLOAD) =~ s/.*:://;    # print "AUTOLOAD: constname = $constname ($AUTOLOAD)\n";    die "&Time::HiRes::constant not defined" if $constname eq 'constant';    my ($error, $val) = constant($constname);    # print "AUTOLOAD: error = $error, val = $val\n";    if ($error) {        my (undef,$file,$line) = caller;        die "$error at $file line $line.\n";    }    {	no strict 'refs';	*$AUTOLOAD = sub { $val };    }    goto &$AUTOLOAD;}sub import {    my $this = shift;    for my $i (@_) {	if (($i eq 'clock_getres'    && !&d_clock_getres)    ||	    ($i eq 'clock_gettime'   && !&d_clock_gettime)   ||	    ($i eq 'clock_nanosleep' && !&d_clock_nanosleep) ||	    ($i eq 'clock'           && !&d_clock)           ||	    ($i eq 'nanosleep'       && !&d_nanosleep)       ||	    ($i eq 'usleep'          && !&d_usleep)          ||	    ($i eq 'ualarm'          && !&d_ualarm)) {	    require Carp;	    Carp::croak("Time::HiRes::$i(): unimplemented in this platform");	}    }    Time::HiRes->export_to_level(1, $this, @_);}bootstrap Time::HiRes;# Preloaded methods go here.sub tv_interval {    # probably could have been done in C    my ($a, $b) = @_;    $b = [gettimeofday()] unless defined($b);    (${$b}[0] - ${$a}[0]) + ((${$b}[1] - ${$a}[1]) / 1_000_000);}# Autoload methods go after =cut, and are processed by the autosplit program.1;__END__=head1 NAMETime::HiRes - High resolution alarm, sleep, gettimeofday, interval timers=head1 SYNOPSIS  use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep		      clock_gettime clock_getres clock_nanosleep clock );  usleep ($microseconds);  nanosleep ($nanoseconds);  ualarm ($microseconds);  ualarm ($microseconds, $interval_microseconds);  $t0 = [gettimeofday];  ($seconds, $microseconds) = gettimeofday;  $elapsed = tv_interval ( $t0, [$seconds, $microseconds]);  $elapsed = tv_interval ( $t0, [gettimeofday]);  $elapsed = tv_interval ( $t0 );  use Time::HiRes qw ( time alarm sleep );  $now_fractions = time;  sleep ($floating_seconds);  alarm ($floating_seconds);  alarm ($floating_seconds, $floating_interval);  use Time::HiRes qw( setitimer getitimer		      ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF );  setitimer ($which, $floating_seconds, $floating_interval );  getitimer ($which);  $realtime   = clock_gettime(CLOCK_REALTIME);  $resolution = clock_getres(CLOCK_REALTIME);  clock_nanosleep(CLOCK_REALTIME, 1.5);  clock_nanosleep(CLOCK_REALTIME, time() + 10, TIMER_ABSTIME);  my $ticktock = clock();=head1 DESCRIPTIONThe C<Time::HiRes> module implements a Perl interface to theC<usleep>, C<nanosleep>, C<ualarm>, C<gettimeofday>, andC<setitimer>/C<getitimer> system calls, in other words, highresolution time and timers. See the L</EXAMPLES> section below and thetest scripts for usage; see your system documentation for thedescription of the underlying C<nanosleep> or C<usleep>, C<ualarm>,C<gettimeofday>, and C<setitimer>/C<getitimer> calls.If your system lacks C<gettimeofday()> or an emulation of it you don'tget C<gettimeofday()> or the one-argument form of C<tv_interval()>.If your system lacks all of C<nanosleep()>, C<usleep()>,C<select()>, and C<poll>, you don't get C<Time::HiRes::usleep()>,C<Time::HiRes::nanosleep()>, or C<Time::HiRes::sleep()>.If your system lacks both C<ualarm()> and C<setitimer()> you don't getC<Time::HiRes::ualarm()> or C<Time::HiRes::alarm()>.If you try to import an unimplemented function in the C<use> statementit will fail at compile time.If your subsecond sleeping is implemented with C<nanosleep()> insteadof C<usleep()>, you can mix subsecond sleeping with signals sinceC<nanosleep()> does not use signals.  This, however, is not portable,and you should first check for the truth value ofC<&Time::HiRes::d_nanosleep> to see whether you have nanosleep, andthen carefully read your C<nanosleep()> C API documentation for anypeculiarities.If you are using C<nanosleep> for something else than mixing sleepingwith signals, give some thought to whether Perl is the tool you shouldbe using for work requiring nanosecond accuracies.The following functions can be imported from this module.No functions are exported by default.=over 4=item gettimeofday ()In array context returns a two-element array with the seconds andmicroseconds since the epoch.  In scalar context returns floatingseconds like C<Time::HiRes::time()> (see below).=item usleep ( $useconds )Sleeps for the number of microseconds (millionths of a second)specified.  Returns the number of microseconds actually slept.  Cansleep for more than one second, unlike the C<usleep> system call. Canalso sleep for zero seconds, which often works like a I<thread yield>.See also C<Time::HiRes::usleep()>, C<Time::HiRes::sleep()>, andC<Time::HiRes::clock_nanosleep()>.Do not expect usleep() to be exact down to one microsecond.=item nanosleep ( $nanoseconds )Sleeps for the number of nanoseconds (1e9ths of a second) specified.Returns the number of nanoseconds actually slept (accurate only tomicroseconds, the nearest thousand of them).  Can sleep for more thanone second.  Can also sleep for zero seconds, which often works like aI<thread yield>.  See also C<Time::HiRes::sleep()>,C<Time::HiRes::usleep()>, and C<Time::HiRes::clock_nanosleep()>.Do not expect nanosleep() to be exact down to one nanosecond.Getting even accuracy of one thousand nanoseconds is good.=item ualarm ( $useconds [, $interval_useconds ] )Issues a C<ualarm> call; the C<$interval_useconds> is optional andwill be zero if unspecified, resulting in C<alarm>-like behaviour.Note that the interaction between alarms and sleeps is unspecified.=item tv_interval tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] )Returns the floating seconds between the two times, which should havebeen returned by C<gettimeofday()>. If the second argument is omitted,then the current time is used.=item time ()Returns a floating seconds since the epoch. This function can beimported, resulting in a nice drop-in replacement for the C<time>provided with core Perl; see the L</EXAMPLES> below.B<NOTE 1>: This higher resolution timer can return values either lessor more than the core C<time()>, depending on whether your platformrounds the higher resolution timer values up, down, or to the nearest secondto get the core C<time()>, but naturally the difference should be nevermore than half a second.  See also L</clock_getres>, if availablein your system.B<NOTE 2>: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, whenthe C<time()> seconds since epoch rolled over to 1_000_000_000, thedefault floating point format of Perl and the seconds since epoch haveconspired to produce an apparent bug: if you print the value ofC<Time::HiRes::time()> you seem to be getting only five decimals, notsix as promised (microseconds).  Not to worry, the microseconds arethere (assuming your platform supports such granularity in the firstplace).  What is going on is that the default floating point format ofPerl only outputs 15 digits.  In this case that means ten digitsbefore the decimal separator and five after.  To see the microsecondsyou can use either C<printf>/C<sprintf> with C<"%.6f">, or theC<gettimeofday()> function in list context, which will give you theseconds and microseconds as two separate values.=item sleep ( $floating_seconds )Sleeps for the specified amount of seconds.  Returns the number ofseconds actually slept (a floating point value).  This function canbe imported, resulting in a nice drop-in replacement for the C<sleep>provided with perl, see the L</EXAMPLES> below.Note that the interaction between alarms and sleeps is unspecified.=item alarm ( $floating_seconds [, $interval_floating_seconds ] )The C<SIGALRM> signal is sent after the specified number of seconds.Implemented using C<ualarm()>.  The C<$interval_floating_seconds> argumentis optional and will be zero if unspecified, resulting in C<alarm()>-likebehaviour.  This function can be imported, resulting in a nice drop-inreplacement for the C<alarm> provided with perl, see the L</EXAMPLES> below.B<NOTE 1>: With some combinations of operating systems and Perlreleases C<SIGALRM> restarts C<select()>, instead of interrupting it.This means that an C<alarm()> followed by a C<select()> may togethertake the sum of the times specified for the the C<alarm()> and the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -