Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Time::HiRes.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Time::HiRes 3"
132.TH Time::HiRes 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134Time::HiRes \- High resolution alarm, sleep, gettimeofday, interval timers
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
139.Ve
140.PP
141.Vb 1
142\& usleep ($microseconds);
143.Ve
144.PP
145.Vb 2
146\& ualarm ($microseconds);
147\& ualarm ($microseconds, $interval_microseconds);
148.Ve
149.PP
150.Vb 2
151\& $t0 = [gettimeofday];
152\& ($seconds, $microseconds) = gettimeofday;
153.Ve
154.PP
155.Vb 3
156\& $elapsed = tv_interval ( $t0, [$seconds, $microseconds]);
157\& $elapsed = tv_interval ( $t0, [gettimeofday]);
158\& $elapsed = tv_interval ( $t0 );
159.Ve
160.PP
161.Vb 1
162\& use Time::HiRes qw ( time alarm sleep );
163.Ve
164.PP
165.Vb 4
166\& $now_fractions = time;
167\& sleep ($floating_seconds);
168\& alarm ($floating_seconds);
169\& alarm ($floating_seconds, $floating_interval);
170.Ve
171.PP
172.Vb 2
173\& use Time::HiRes qw( setitimer getitimer
174\& ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF );
175.Ve
176.PP
177.Vb 2
178\& setitimer ($which, $floating_seconds, $floating_interval );
179\& getitimer ($which);
180.Ve
181.SH "DESCRIPTION"
182.IX Header "DESCRIPTION"
183The \f(CW\*(C`Time::HiRes\*(C'\fR module implements a Perl interface to the usleep,
184ualarm, gettimeofday, and setitimer/getitimer system calls. See the
185\&\s-1EXAMPLES\s0 section below and the test scripts for usage; see your system
186documentation for the description of the underlying usleep, ualarm,
187gettimeofday, and setitimer/getitimer calls.
188.PP
189If your system lacks \fIgettimeofday\fR\|(2) or an emulation of it you don't
190get \fIgettimeofday()\fR or the one-arg form of \fItv_interval()\fR.
191If you don't have \fIusleep\fR\|(3) or \fIselect\fR\|(2) you don't get \fIusleep()\fR
192or \fIsleep()\fR. If your system don't have \fIualarm\fR\|(3) or \fIsetitimer\fR\|(2) you
193don't get \fIualarm()\fR or \fIalarm()\fR. If you try to import an unimplemented
194function in the \f(CW\*(C`use\*(C'\fR statement it will fail at compile time.
195.PP
196The following functions can be imported from this module.
197No functions are exported by default.
198.IP "gettimeofday ()" 4
199.IX Item "gettimeofday ()"
200In array context returns a 2 element array with the seconds and
201microseconds since the epoch. In scalar context returns floating
202seconds like \fITime::HiRes::time()\fR (see below).
203.ie n .IP "usleep ( $useconds )" 4
204.el .IP "usleep ( \f(CW$useconds\fR )" 4
205.IX Item "usleep ( $useconds )"
206Sleeps for the number of microseconds specified. Returns the number
207of microseconds actually slept. Can sleep for more than one second
208unlike the usleep system call. See also \fITime::HiRes::sleep()\fR below.
209.ie n .IP "ualarm ( $useconds\fR [, \f(CW$interval_useconds ] )" 4
210.el .IP "ualarm ( \f(CW$useconds\fR [, \f(CW$interval_useconds\fR ] )" 4
211.IX Item "ualarm ( $useconds [, $interval_useconds ] )"
212Issues a ualarm call; interval_useconds is optional and will be 0 if
213unspecified, resulting in alarm-like behaviour.
214.IP "tv_interval" 4
215.IX Item "tv_interval"
216\&\f(CW\*(C`tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] )\*(C'\fR
217.Sp
218Returns the floating seconds between the two times, which should have
219been returned by \fIgettimeofday()\fR. If the second argument is omitted,
220then the current time is used.
221.IP "time ()" 4
222.IX Item "time ()"
223Returns a floating seconds since the epoch. This function can be
224imported, resulting in a nice drop-in replacement for the \f(CW\*(C`time\*(C'\fR
225provided with core Perl, see the \s-1EXAMPLES\s0 below.
226.Sp
227\&\fB\s-1NOTE\s0 1\fR: this higher resolution timer can return values either less or
228more than the core \fItime()\fR, depending on whether your platforms rounds
229the higher resolution timer values up, down, or to the nearest to get
230the core \fItime()\fR, but naturally the difference should be never more than
231half a second.
232.Sp
233\&\fB\s-1NOTE\s0 2\fR: Since Sunday, September 9th, 2001 at 01:46:40 \s-1AM\s0 \s-1GMT\s0
234(when the \fItime()\fR seconds since epoch rolled over to 1_000_000_000),
235the default floating point format of Perl and the seconds since epoch
236have conspired to produce an apparent bug: if you print the value of
237\&\fITime::HiRes::time()\fR you seem to be getting only five decimals, not six
238as promised (microseconds). Not to worry, the microseconds are there
239(assuming your platform supports such granularity). What is going on
240is that the default floating point format of Perl only outputs 15
241digits. In this case that means ten digits before the decimal
242separator and five after. To see the microseconds you can use either
243printf/sprintf with \f(CW\*(C`%.6f\*(C'\fR, or the \fIgettimeofday()\fR function in list
244context, which will give you the seconds and microseconds as two
245separate values.
246.ie n .IP "sleep ( $floating_seconds )" 4
247.el .IP "sleep ( \f(CW$floating_seconds\fR )" 4
248.IX Item "sleep ( $floating_seconds )"
249Sleeps for the specified amount of seconds. Returns the number of
250seconds actually slept (a floating point value). This function can be
251imported, resulting in a nice drop-in replacement for the \f(CW\*(C`sleep\*(C'\fR
252provided with perl, see the \s-1EXAMPLES\s0 below.
253.ie n .IP "alarm ( $floating_seconds\fR [, \f(CW$interval_floating_seconds ] )" 4
254.el .IP "alarm ( \f(CW$floating_seconds\fR [, \f(CW$interval_floating_seconds\fR ] )" 4
255.IX Item "alarm ( $floating_seconds [, $interval_floating_seconds ] )"
256The \s-1SIGALRM\s0 signal is sent after the specfified number of seconds.
257Implemented using \fIualarm()\fR. The \f(CW$interval_floating_seconds\fR argument
258is optional and will be 0 if unspecified, resulting in \fIalarm()\fR\-like
259behaviour. This function can be imported, resulting in a nice drop-in
260replacement for the \f(CW\*(C`alarm\*(C'\fR provided with perl, see the \s-1EXAMPLES\s0 below.
261.IP "setitimer" 4
262.IX Item "setitimer"
263\&\f(CW\*(C`setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] )\*(C'\fR
264.Sp
265Start up an interval timer: after a certain time, a signal arrives,
266and more signals may keep arriving at certain intervals. To disable
267a timer, use time of zero. If interval is set to zero (or unspecified),
268the timer is disabled \fBafter\fR the next delivered signal.
269.Sp
270Use of interval timers may interfere with \fIalarm()\fR, \fIsleep()\fR, and \fIusleep()\fR.
271In standard-speak the \*(L"interaction is unspecified\*(R", which means that
272\&\fIanything\fR may happen: it may work, it may not.
273.Sp
274In scalar context, the remaining time in the timer is returned.
275.Sp
276In list context, both the remaining time and the interval are returned.
277.Sp
278There are three interval timers: the \f(CW$which\fR can be \s-1ITIMER_REAL\s0,
279\&\s-1ITIMER_VIRTUAL\s0, or \s-1ITIMER_PROF\s0.
280.Sp
281\&\s-1ITIMER_REAL\s0 results in \fIalarm()\fR\-like behavior. Time is counted in
282\&\fIreal time\fR, that is, wallclock time. \s-1SIGALRM\s0 is delivered when
283the timer expires.
284.Sp
285\&\s-1ITIMER_VIRTUAL\s0 counts time in (process) \fIvirtual time\fR, that is, only
286when the process is running. In multiprocessor/user/CPU systems this
287may be more or less than real or wallclock time. (This time is also
288known as the \fIuser time\fR.) \s-1SIGVTALRM\s0 is delivered when the timer expires.
289.Sp
290\&\s-1ITIMER_PROF\s0 counts time when either the process virtual time or when
291the operating system is running on behalf of the process (such as
292I/O). (This time is also known as the \fIsystem time\fR.) (Collectively
293these times are also known as the \fI\s-1CPU\s0 time\fR.) \s-1SIGPROF\s0 is delivered
294when the timer expires. \s-1SIGPROF\s0 can interrupt system calls.
295.Sp
296The semantics of interval timers for multithreaded programs are
297system\-specific, and some systems may support additional interval
298timers. See your \fIsetitimer()\fR documentation.
299.ie n .IP "getitimer ( $which )" 4
300.el .IP "getitimer ( \f(CW$which\fR )" 4
301.IX Item "getitimer ( $which )"
302Return the remaining time in the interval timer specified by \f(CW$which\fR.
303.Sp
304In scalar context, the remaining time is returned.
305.Sp
306In list context, both the remaining time and the interval are returned.
307The interval is always what you put in using \fIsetitimer()\fR.
308.SH "EXAMPLES"
309.IX Header "EXAMPLES"
310.Vb 1
311\& use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
312.Ve
313.PP
314.Vb 2
315\& $microseconds = 750_000;
316\& usleep $microseconds;
317.Ve
318.PP
319.Vb 2
320\& # signal alarm in 2.5s & every .1s thereafter
321\& ualarm 2_500_000, 100_000;
322.Ve
323.PP
324.Vb 2
325\& # get seconds and microseconds since the epoch
326\& ($s, $usec) = gettimeofday;
327.Ve
328.PP
329.Vb 7
330\& # measure elapsed time
331\& # (could also do by subtracting 2 gettimeofday return values)
332\& $t0 = [gettimeofday];
333\& # do bunch of stuff here
334\& $t1 = [gettimeofday];
335\& # do more stuff here
336\& $t0_t1 = tv_interval $t0, $t1;
337.Ve
338.PP
339.Vb 2
340\& $elapsed = tv_interval ($t0, [gettimeofday]);
341\& $elapsed = tv_interval ($t0); # equivalent code
342.Ve
343.PP
344.Vb 8
345\& #
346\& # replacements for time, alarm and sleep that know about
347\& # floating seconds
348\& #
349\& use Time::HiRes;
350\& $now_fractions = Time::HiRes::time;
351\& Time::HiRes::sleep (2.5);
352\& Time::HiRes::alarm (10.6666666);
353.Ve
354.PP
355.Vb 4
356\& use Time::HiRes qw ( time alarm sleep );
357\& $now_fractions = time;
358\& sleep (2.5);
359\& alarm (10.6666666);
360.Ve
361.PP
362.Vb 2
363\& # Arm an interval timer to go off first at 10 seconds and
364\& # after that every 2.5 seconds, in process virtual time
365.Ve
366.PP
367.Vb 1
368\& use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
369.Ve
370.PP
371.Vb 2
372\& $SIG{VTLARM} = sub { print time, "\en" };
373\& setitimer(ITIMER_VIRTUAL, 10, 2.5);
374.Ve
375.SH "C API"
376.IX Header "C API"
377In addition to the perl \s-1API\s0 described above, a C \s-1API\s0 is available for
378extension writers. The following C functions are available in the
379modglobal hash:
380.PP
381.Vb 4
382\& name C prototype
383\& --------------- ----------------------
384\& Time::NVtime double (*)()
385\& Time::U2time void (*)(UV ret[2])
386.Ve
387.PP
388Both functions return equivalent information (like \f(CW\*(C`gettimeofday\*(C'\fR)
389but with different representations. The names \f(CW\*(C`NVtime\*(C'\fR and \f(CW\*(C`U2time\*(C'\fR
390were selected mainly because they are operating system independent.
391(\f(CW\*(C`gettimeofday\*(C'\fR is Un*x\-centric.)
392.PP
393Here is an example of using NVtime from C:
394.PP
395.Vb 6
396\& double (*myNVtime)();
397\& SV **svp = hv_fetch(PL_modglobal, "Time::NVtime", 12, 0);
398\& if (!svp) croak("Time::HiRes is required");
399\& if (!SvIOK(*svp)) croak("Time::NVtime isn't a function pointer");
400\& myNVtime = INT2PTR(double(*)(), SvIV(*svp));
401\& printf("The current time is: %f\en", (*myNVtime)());
402.Ve
403.SH "CAVEATS"
404.IX Header "CAVEATS"
405Notice that the core \fItime()\fR maybe rounding rather than truncating.
406What this means that the core \fItime()\fR may be giving time one second
407later than \fIgettimeofday()\fR, also known as \fITime::HiRes::time()\fR.
408.SH "AUTHORS"
409.IX Header "AUTHORS"
410D. Wegscheid <wegscd@whirlpool.com>
411R. Schertler <roderick@argon.org>
412J. Hietaniemi <jhi@iki.fi>
413G. Aas <gisle@aas.no>
414.SH "REVISION"
415.IX Header "REVISION"
416$Id: HiRes.pm,v 1.20 1999/03/16 02:26:13 wegscd Exp $
417.PP
418$Log: HiRes.pm,v $
419Revision 1.20 1999/03/16 02:26:13 wegscd
420Add documentation for NVTime and U2Time.
421.PP
422Revision 1.19 1998/09/30 02:34:42 wegscd
423No changes, bump version.
424.PP
425Revision 1.18 1998/07/07 02:41:35 wegscd
426No changes, bump version.
427.PP
428Revision 1.17 1998/07/02 01:45:13 wegscd
429Bump version to 1.17
430.PP
431Revision 1.16 1997/11/13 02:06:36 wegscd
432version bump to accomodate HiRes.xs fix.
433.PP
434Revision 1.15 1997/11/11 02:17:59 wegscd
435\&\s-1POD\s0 editing, courtesy of Gisle Aas.
436.PP
437Revision 1.14 1997/11/06 03:14:35 wegscd
438Update version # for Makefile.PL and HiRes.xs changes.
439.PP
440Revision 1.13 1997/11/05 05:36:25 wegscd
441change version # for Makefile.pl and HiRes.xs changes.
442.PP
443Revision 1.12 1997/10/13 20:55:33 wegscd
444Force a new version for Makefile.PL changes.
445.PP
446Revision 1.11 1997/09/05 19:59:33 wegscd
447New version to bump version for \s-1README\s0 and Makefile.PL fixes.
448Fix bad \s-1RCS\s0 log.
449.PP
450Revision 1.10 1997/05/23 01:11:38 wegscd
451Conditional compilation; \s-1EXPORT_FAIL\s0 fixes.
452.PP
453Revision 1.2 1996/12/30 13:28:40 wegscd
454Update documentation for what to do when missing \fIualarm()\fR and friends.
455.PP
456Revision 1.1 1996/10/17 20:53:31 wegscd
457Fix =head1 being next to _\|_END_\|_ so pod2man works
458.PP
459Revision 1.0 1996/09/03 18:25:15 wegscd
460Initial revision
461.SH "COPYRIGHT"
462.IX Header "COPYRIGHT"
463Copyright (c) 1996\-1997 Douglas E. Wegscheid.
464All rights reserved. This program is free software; you can
465redistribute it and/or modify it under the same terms as Perl itself.