james
james

Reputation: 354

How do I use adb command get the terminal output?

I want to get cpu usage of the phone and then draw on PC.

I want to do like this:

First, run a background process in the phone which caculate the CPU usage and show in terminal.

Second, use adb commnad to get the terminal output.

Finally, draw curve with data.

I'm confused wheather it will work normally without big latency. At first, I want to put the cpu usage into a file, and use command of 'adb pull' to pull the file, then read the file and draw. I thought this may cause big latency.

Does anyone could help me?

Thanks. James.

Upvotes: 6

Views: 16285

Answers (2)

Pete Houston
Pete Houston

Reputation: 15079

  1. Write an Android application write to a file, for sample: cpu_usage.txt

  2. Use LogCat to get output: adb shell cat /path_to_your_file/cpu_usage.txt

Parse the output from command line, then draw it on the graph. High latency? Nope.

Edit: Ok, if you get root permission, just execute the command as you wish, for example,

C:\>adb shell top -m -d 1 -n 1 > C:\top_result.txt

Check out the result at: C:\top_result.txt. Also, as I read your message, you say something like socket, if I were you, I would never use it, because it always causes high latency.

Upvotes: 1

Paul
Paul

Reputation: 5223

I'm not entirely sure if that is what you are trying to achieve but you can use:

  1. adb shell to access the shell prompt of the device and run commands from there. See: http://developer.android.com/tools/help/adb.html#shellcommands

  2. adb logcat to get the live log stream from the device. You can use filters etc to adjust the output to what you need. See: http://developer.android.com/tools/help/adb.html#logcat

Upvotes: 3

Related Questions