TODClock (System function): Difference between revisions
(Automatically generated page update) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Template:System:TODClock subtitle}} | {{Template:System:TODClock subtitle}} | ||
This method provides access to the value of the hardware TOD (Time Of Day) clock. | |||
This | |||
==Syntax== | ==Syntax== | ||
{{Template:System:TODClock syntax}} | {{Template:System:TODClock syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%string</th><td> | <tr><th>%string</th><td>The eight-byte binary value of the TOD clock at the time the method was invoked.</td></tr> | ||
<tr><th nowrap="true"><var>%(System)</var></th> | <tr><th nowrap="true"><var>%(System)</var></th> | ||
<td>The class name in parentheses denotes a shared method. <var>TODClock</var> can also be invoked via a <var>System</var> object variable, which may be <var>Null</var>.</td></tr> | <td>The class name in parentheses denotes a shared method. <var>TODClock</var> can also be invoked via a <var>System</var> object variable, which may be <var>Null</var>.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>Bit 51 of the TOD clock (where the highest order bit is bit 0 and the lowest is bit 63) is incremented by one every microsecond. Bit 31 is incremented approximately once every second. For more information on the TOD clock see the ''z/Architecture Principles of Operation''. | |||
<li>The TOD clock has 64 bits of precision which requires approximately 20 significant decimal digits. Unfortunately Model 204 only really supports 15 decimal places. As such, the TOD clock value is more useful as a simple stamp than as a value used in calculations. However, with a bit of effort, it can be used to get more precise timings than is possible otherwise with Model 204. See the example below for an illustration. | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following local method indicates how TOD clock values can be used to provide a microsecond precision interval calculator. The inputs (method object and parameter) are assumed to be the results of TODClock calls. | |||
<p class="code">local function (string):microsecondTodClockDifference(%start is string len 8) is float | |||
assert %this:length eq 8 | |||
assert %start:length eq 8 | |||
%highWord is float | |||
%lowWord is float | |||
%hexValue1 is string len 16 | |||
%hexValue2 is string len 16 | |||
%hexValue2 = %this:stringToHex | |||
%hexValue1 = %start:stringToHex | |||
%highWord = %hexValue2:left(8):hexToInteger - %hexValue1:left(8):hexToInteger | |||
%lowWord = %hexValue2:substring(9, 5):hexToInteger - %hexValue1:substring(9, 5):hexToInteger | |||
return %highWord * 2:toPower(32 - 12) + %lowWord | |||
end function | |||
</p> | |||
While in general TOD clock values or microseconds since January 1, 1900 (the standard time base in 204) require more significant digits than 204 provides, microsecond intervals can be easily handled by Model 204 unless the intervals exceed several years. With the above code, one can do microsecond level interval timing: | |||
<p class="code">%tod1 is string len 8 | |||
%tod2 is string len 8 | |||
%tod1 = %(system):todclock | |||
pause 1 | |||
%tod2 = %(system):todclock | |||
printText {~=%tod1:stringToHex}, {~=%tod2:stringToHex} | |||
printText {~=%tod2:microsecondTodClockDifference(%tod1)} | |||
</p> | |||
One would expect the value printed by the last line to be just a little bit more than 1000000 (microseconds). | |||
==See also== | ==See also== | ||
<ul> | |||
<li>[[UUIDTime (System function)]] | |||
</ul> | |||
{{Template:System:TODClock footer}} | {{Template:System:TODClock footer}} |
Latest revision as of 02:48, 9 May 2014
Get binary TOD clock value (System class)
[Introduced in Model 204 7.5]
This method provides access to the value of the hardware TOD (Time Of Day) clock.
Syntax
%string = %(System):TODClock
Syntax terms
%string | The eight-byte binary value of the TOD clock at the time the method was invoked. |
---|---|
%(System) | The class name in parentheses denotes a shared method. TODClock can also be invoked via a System object variable, which may be Null. |
Usage notes
- Bit 51 of the TOD clock (where the highest order bit is bit 0 and the lowest is bit 63) is incremented by one every microsecond. Bit 31 is incremented approximately once every second. For more information on the TOD clock see the z/Architecture Principles of Operation.
- The TOD clock has 64 bits of precision which requires approximately 20 significant decimal digits. Unfortunately Model 204 only really supports 15 decimal places. As such, the TOD clock value is more useful as a simple stamp than as a value used in calculations. However, with a bit of effort, it can be used to get more precise timings than is possible otherwise with Model 204. See the example below for an illustration.
Examples
The following local method indicates how TOD clock values can be used to provide a microsecond precision interval calculator. The inputs (method object and parameter) are assumed to be the results of TODClock calls.
local function (string):microsecondTodClockDifference(%start is string len 8) is float assert %this:length eq 8 assert %start:length eq 8 %highWord is float %lowWord is float %hexValue1 is string len 16 %hexValue2 is string len 16 %hexValue2 = %this:stringToHex %hexValue1 = %start:stringToHex %highWord = %hexValue2:left(8):hexToInteger - %hexValue1:left(8):hexToInteger %lowWord = %hexValue2:substring(9, 5):hexToInteger - %hexValue1:substring(9, 5):hexToInteger return %highWord * 2:toPower(32 - 12) + %lowWord end function
While in general TOD clock values or microseconds since January 1, 1900 (the standard time base in 204) require more significant digits than 204 provides, microsecond intervals can be easily handled by Model 204 unless the intervals exceed several years. With the above code, one can do microsecond level interval timing:
%tod1 is string len 8 %tod2 is string len 8 %tod1 = %(system):todclock pause 1 %tod2 = %(system):todclock printText {~=%tod1:stringToHex}, {~=%tod2:stringToHex} printText {~=%tod2:microsecondTodClockDifference(%tod1)}
One would expect the value printed by the last line to be just a little bit more than 1000000 (microseconds).