KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Calculating machine uptime with Tickcount
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: December 21, 2010

When calculating machine uptime, Tickcount provides greater longevity while Milliseconds would give better granularity.

The reason why is because the value returned by both of these commands is a Long Int which has a maxmimum value of 2,147,483,647 (MAXLONG).

Milliseconds returns the number of milliseconds (1000ths of a second) elapsed since the machine was started:

totalSeconds = (MAXLONG / 1000)
  // 2,147,483.647


Tickcount returns the numbers of ticks (60th of a second) elapsed since the machine was started:

totalSeconds = (MAXLONG / 60)
  // 35,791,394.1166666


Using the MAXLONG constant we can quickly see a difference in the total number of seconds of uptime these commands can return.

The maximum uptime one could calculate using Tickcount is "414 days 6 hours 3 minutes 14 seconds 7 ticks".

The maximum uptime once could calculate using Milliseconds is "25 days 20 hours 31 minutes 23 seconds 647 milliseconds"

The following code example calculates the machine uptime using the command Tickcount.

C_TEXT($0;$msg2)
C_LONGINT($upticks;$secs;$mins;$hours;$days)
C_LONGINT($totalSecs;$totalMins;$totalHours;$ticks)

$upticks:=Tickcount
$ticks:=Mod($upticks;60)

$totalSecs:=($upticks/60)
$secs:=Mod(Int($totalSecs);60)

$totalMins:=($totalSecs/60)
$mins:=Mod(Int($totalMins);60)

$totalHours:=($totalMins/60)
$hours:=Mod(Int($totalHours);24)

$days:=Int($totalHours/24)

$msg2:=""

If ($days>0)
  $msg2:=$msg2+String($days)+" days "
End if

If ($hours>0)
  $msg2:=$msg2+String($hours)+" hours "
End if

If ($mins>0)
  $msg2:=$msg2+String($mins)+" minutes "
End if

If ($secs>0)
  $msg2:=$msg2+String($secs)+" seconds "
End if

If ($ticks>0)
  $msg2:=$msg2+String($ticks)+" ticks "
End if

$0:=$msg2



If the above method was saved as UTIL_getUptime you could use it like so:

ALERT("The machine has been up for: "+UTIL_getUptime)