Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure time from adb shell with milliseconds resolution?

How can I measure time from adb shell with milliseconds or nanoseconds resolution?

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

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

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

like image 431
22332112 Avatar asked May 31 '14 14:05

22332112


People also ask

Can the time command be used to convert milliseconds to milliseconds?

The time command itself is not capable of doing this directly. It does output a time in a fractional format, so it can be parsed back into milliseconds by multiplying by 1000:

How to use ADB shell?

How to use ADB Shell 1 Step 1: Set up ADB#N#Setting up ADB is a pretty simple process depending on your requirements. You can set it up for... 2 Step 2: Make sure ADB is working#N#(Please first make sure you have set up ADB as given above.)#N#Open CMD in the Platform... 3 Step 3: Use ADB Shell More ...

What is the best tool for measuring execution time with microsecond resolution?

A logic analyzer is one of the best tools for accurately measuringexecution time with microsecond resolution, especially when accuratetiming is essential. The drawback is that the it requires specializedhardware and more effort than some of the previous techniques describedabove. There are two approaches to using a logic analyzer.

How do I measure the time a program takes to execute?

A typical way to use the command is to wrap the program that isbeing measured in a shell script or alias with the following commands: As with the stop-watch method, this will only provide an estimate ofhow long the full program takes to execute. It does not take intoconsideration preemption, interrupts, or I/O.


1 Answers

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

Time since the epoch, as returned by gettimeofday(2), formatted as decimal tv_sec followed by a dot . and tv_usec padded to exactly six decimal digits.

So the command to get epoch time with microsecond accuracy in Windows would be:

adb shell echo $EPOCHREALTIME

or in Linux:

adb shell 'echo $EPOCHREALTIME'

If you just need millisecond accuracy:

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

Or just the milliseconds part to use with another time format:

adb shell 'echo $(date +%T)${EPOCHREALTIME:10:4}'
like image 192
Alex P. Avatar answered Oct 19 '22 10:10

Alex P.