how to view kmsg when debugging device suspend in android - android

I am debugging the suspend/resume process of an android phone. I am using adb shell into the phone and doing cat /proc/kmsg to view the debug message. The problem is whenever the phone suspends, it will put the usb to sleep, which will disconnects adb and therefore kmsg will terminate. I can unplug and replug in usb and do another cat /proc/kmsg. But the important debug message will be lost.
So my question is how do I capture the kmsg while the phone is going through suspend and resume cycle?
Thank you.

I'm currently trying to debug device suspend in Android, and work around this by:
1) create a shell script that cats /proc/kmsg in background:
/sdcard/log.sh
#!/bin/sh
cat /proc/kmsg > /sdcard/kmsg.log &
2) run the script over adb:
$ adb shell
$ su
# sh /sdcard/log.sh
You can then exit out of adb, unplug the device, and it'll keep logging to /sdcard/kmsg.log. When you're ready to view the log, you can connect it to usb and pull the log. Note that I put my log in /sdcard so that it persists between reboots.

Related

Getting cpu and memory usage for a period of time

I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.

Wait for Android emulator to be running before next shell command?

I started an Android emulator using the following shell command:
emulator -avd TEST_AVD
The emulator starts just fine, but the shell script never finishes executing. It just hangs there even after the emulator has completed startup. I have tried with a number of other arguments that I could find, but nothing could quite do what I want it to. How do I know, or stop the shell command, when the emulator is ready to go?
I am setting up our Jenkins CI to use a Jenkinsfile to start the emulator, and then run a series of gradle commands. In short, I'd like to do this:
sh "emulator -avd TEST_AVD"
sh "./gradlew clean test spoon"
However, I don't want to run the gradle tasks until the emulator has finished startup, and I can't figure out how to do that in the terminal.
If you want to do something after you start the emulator you should start it in the background
emulator -avd TEST_AVD &
adb wait-for-device
# other stuff here
adb can wait for a device over a transport to be in a particular state
adb wait-for[-<transport>]-<state>
- wait for device to be in the given state:
device, recovery, sideload, or bootloader
Transport is: usb, local or any [default=any]
To wait until device (or emulator) boots, you can do something like this (as was already answered by Пионерка):
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
Basically:
Wait for device/emulator to be in adb device state
Open shell & sleep in 1 second intervals until the sys.boot_completed property becomes true
If anybody would be interested what Android Studio does, when running emulator, the answer is this class:
If device is online, then it is ready. No need to go to further steps.
Checks system property adb shell getprop dev.bootcomplete until it is equal to 1
For API 23+ devices runs command to unlock screen: adb shell wm dismiss-keyguard
Waits 1 second.

Device recognized in ADB but not in shell

When I use ADB, my phone is recognized. However, once I enter the shell, the phone mysteriously disappears. This is weird especially because the shell lists "root#nozomi", as "nozomi" is the phone's code name.
And because it is not recognized, I can't, for example, push files:
The adb command is available both on your phone and your host/development machine. However, it is not much useful on your phone from the shell.
adb shell opens a unix command shell on your phone. Commands you enter here are executed on your phone.
When you execute adb devices in the adb shell, you ask your phone if it has any other phones connected to it via the android debugging interface. And clearly your phone tells you, that this is not the case.
Same thing holds for adb push you are asking your phone to push a file to another phone via adb. Since none are connected, you get the error message.
Try exiting the adb shell again and execute commands on the host machine instead.

adb "error device not found" when trying to use 'adb shell' but "adb devices" detects the device

Guys basically I've plugged in a bunch of Android devices to a computer and each of them has adb enabled. I'm running a shell script to push certain files to the devices using the Device Serial Numbers stored in a text file. When I trigger the script the first time it works. if i trigger it again adb throws an error , "error device not found" though the devices are still detected using adb. If i close the terminal and reopen it and run the script it works fine. I plan to eventually automate the script running. How can i stop this from happening.
EDIT: This is the piece of code where the adb shell commands are triggered
cat device_serial | while read line
do
adb -s $line shell
cd /data/
ls
exit
adb -s $line root
adb -s $line push 'stestfile.txt ' /data/
echo "done"
done
I need to look at the script to fix the issue.
But looks like the problem is that the next time you run the script, you are actually in the device's shell instead of your computer's.

adb pull freezes when it encounters kmsg

I'm trying to debug why my android mobile will not boot. When I run:
adb pull / e:\temp
It freezes at
pull: /proc/kmsg -> e:\temp/proc/kmsg
Is there some way to stop it freezing here or to get 'pull' to by-pass this file.
(I'm running this command while the phone is sitting in the recovery menu as I cant get adb to run in any other state).
Samsung Galaxy GT-i5500, android 2.2, windows 7.
You can instead dump the log using
adb logcat -d > log.txt
This will provide you with the log which you can use to debug the issue.
Run-time messages can be obtained through
adb shell dmesg
For kmsg, the following command can be tried.
adb shell cat /proc/kmesg

Categories

Resources