6

I'm writing a script containing several "adb shell" command. I also want to record the time when program execute these command in a form of realtime and uptime. I know I can get uptime and realtime through SystemClock:

SystemClock.uptimeMillis();
SystemClock.elapsedRealtime();

Is there any way I can get these information from the command line?

Thanks a lot!

Wei Yang
  • 825
  • 3
  • 13
  • 25
  • Yes. I mean adb shell command. I thought there might be some command that can inquire about system status. I know adb shell sysdump gfxinfo will return the uptime and realtime at the end of its output. What I want is a cleaner one. – Wei Yang Aug 08 '13 at 21:04

2 Answers2

10

Try:

adb shell cat /proc/uptime
Diego Torres Milano
  • 57,580
  • 7
  • 101
  • 124
  • Thanks! Diego. The second number matches `SystemClock.elapsedRealtime()`. One small problem is that the numbers in `uptime` file is recorded in seconds with two decimal places. It seems that `SystemClock.elapsedRealtime()` is more accurate because it uses milliseconds. – Wei Yang Aug 08 '13 at 21:42
  • Is there a way to get use it on a specific device when several are connected to the machine? (error: more than one device and emulator) – Eyal Sooliman Jul 27 '15 at 13:23
6

If you only need to-the-second accuracy, adb shell uptime will also work. Example output:

up time: 00:09:26, idle time: 00:07:15, sleep time: 00:00:00
Matthew Read
  • 926
  • 1
  • 26
  • 43