How to get Android system uptime and realtime from command line?
Asked Answered
P

2

9

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!

Pedicular answered 8/8, 2013 at 20:57 Comment(1)
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.Pedicular
W
15

Try:

adb shell cat /proc/uptime
Weatherman answered 8/8, 2013 at 21:10 Comment(2)
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.Pedicular
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)Hebetic
D
11

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
Drugi answered 30/4, 2015 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.