How to measure time from adb shell with resolution in milliseconds?

How to measure time from adb shell with resolution in milliseconds or nanoseconds?

Using date +%.%N from the adb shell returns 1401546811.N (resolution of seconds) instead of something like 1401547289.231869798 (resolution of nanoseconds).

How can I get the resolution of milliseconds or nanoseconds from adb shell?

Is there some kind of terminal program that I can use to give me this? I can measure the time using System.currentTimeMillis() and System.nanoTime() from the Android application code, but I also need something from the adb shell .

+8
android shell mksh adb
source share
3 answers

mksh (the standard Android shell since version 4.0) has a built-in EPOCHREALTIME environment variable:

Time elapsed since epoch returned by gettimeofday(2) , formatted as decimal tv_sec followed by a period . and tv_usec, filled with exactly six decimal places.

Thus, the command for obtaining epoch time accurate to the microsecond in Windows will be:

 adb shell echo $EPOCHREALTIME 

or on Linux:

 adb shell 'echo $EPOCHREALTIME' 

If you only need millisecond precision:

 adb shell 'echo ${EPOCHREALTIME:0:14}' 

Or just a part in milliseconds to use with another temporary format:

 adb shell 'echo $(date +%T)${EPOCHREALTIME:10:4}' 
+16
source share

Kind of my problem being solved with botbrew. Probably not an idea, but at least now it works. /data/botbrew-basil/init -- date +%s.%N - returns nanosecond resolution.

0
source share

adb shell echo $EPOCHREALTIME gives you time in microseconds, (do not write it with '\' in front of the variable name)

0
source share

All Articles