I am working on an Android phone based on the Linux Kernel. I'm using kmsg for kernel logs and adb logcat -v time for platform logs. The problem is Kernel logs shows time from 0.000000 and logcat is showing from the start of system time ( For example, if time on the phone is 10.43.00, it'll show the first log from this time )
Now I am unable to compare events from these 2 logs as the time base ( reference) is different. Can anyone kindly point out how to sync these 2 times?
Another solution would be similar to jpg's answer, but in the other direction, redirect
the kernel messages into logcat. This is better, because too many logcat messages might overload the serial console (if you have it active).
you can run this in an android shell:
cat /proc/kmsg | while read LINE; do echo '\06kernel\0'$LINE'\0' > /dev/log/main; done
or this in a host shell:
adb shell '(cat /proc/kmsg | while read LINE; do echo \\06kernel\\0$LINE\\0 > /dev/log/main; done)'
The first time you start the command you will see all of the current dmesg messages in one place, but any further messages will be interleaved, when they appear.
and then examine logcat in a different shell. If you examine logcat with -v time, then the kernel messages will contain both the logcat and the kernel timestamps. Of course there may be delays between the two.
Another, even simpler way to see messages interleaved would be:
adb shell '(logcat & cat /proc/kmsg) > /path/to/log/file'
But in this case it's a little harder to identify messages coming from the kernel, and you can't tell how kernel timestamps relate to logcat timestamps.
you can create a single file containing both kernel and platform logs as follows:
$adb shell
$logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog_log.txt
you can differentiate both the logs using time stamps in the platform logs. And then pull the file to your local drive using
adb pull /data/klog_plog_log.txt > sample.txt
Refer http://jai-tech.blogspot.com/2012/01/taking-kernel-and-platform-logs-of.html . Hope this helps.
Regards,
JP
Pavan,
Perhaps with you can tag your logcat prints with the time since last boot? This should be closer to the time shown in kmsg.
Time since last boot can be retrieved with elapsedRealtime().
The single file method described above is nice but may not always be useful as the input from logcat and kmsg might be delayed due to buffering. So you will most likely see a block of kmsg entries and then a block of logcat entries which might still be interleaved in real time.
That said, you might be able to sync kmsg time and logcat time by looking for device suspend messages in kmsg (grep UTC):
<6>[249485.550811] suspend: exit suspend, ret = 0 (2012-12-27 16:16:46.300872527 UTC)
As you can see those entries in kmsg report the current system wallclock time which can then be synchronized with the kmsg time value. Note however that the kmsg time value does not increase when the device is asleep while the wallclock time obviously does. To that end you will have to resynchronize on the wallclock time on every suspend entry and exit in order to get the correct wallclock time.
I think it can use like this:
adb shell logcat -v time -f /dev/kmsg | adb shell cat /proc/kmsg >sample.txt
Related
In my app, I am using Timber as a logger. I am accessing the logs from the terminal via adb using this isntruction:
./adb logcat com.company.my_app:D
I do get the logs but the issue is that I am getting a crazy amount of noise from the OS (ie SurfaceFlinger , GraphicBuffer, vndksupport) which make the logs harder to read.
Is there a way to filter the logs like in Android Studio and just get logs from my app. Thank you !
P.S. I have trie a few answers from here but none of them remove the noise.
What works best for me is to grep for the process ID which is displayed in every log line. In the example below 7098 is printed with every log line.
08-10 18:48:39.825 7098 7144 D NetworkModule: --> END POST
So this is the adb instruction used to get filtered logs:
adb logcat | grep -F "7098"
Note: the process ID is not static and it is going to change if app is hard-closed or device is restarted.
I don't know if it is the best solution, but it works in my case.
My app is a root app and I have access to root shell on android phone. My requirement is to write logcat output for one minute into a file and then send the file to server. My app handles the file sending part but I am having trouble with collecting the log for specified amount of time.! I do not see any option in logcat command to specify the time duration. Is there any other way.! The following are the limitations I have
Command needs to be executed only on android phone shell. Since the device is not with me I can not use a laptop to run/schedule the command.
Command has to run only specified amount of time. I looked at -d of logcat options but it gives me log for around 5 seconds which is not sufficient for me to look at crashes.
I am trying to write a python function that captures the time it takes for an android device to get gps fix. I want to do this by capturing the timestamp of the logcat record which mentions that system time is syncronised with GPS. So I submit an adb logcat with timestamp and grep for "Setting system time at". The I want to give the timestamp value of this line to a varialble. Specifically I want to capture the characters 10-18 of this line as this reflects the exact time from device boot. Once the string has been detected once I want the function to exit and my program to continue.
I try in the following:
cmdtimegps='adb logcat -v time| grep "Setting system time at"'
w=subprocess.check_output(cmdtimegps.split())
print w
My main problem is making the command (adb logcat -v time| grep SetTimeFromGPSService) work. I get a "/system/bin/sh: grep: not found" error. Any help with this or advice on the following steps would be very welcome. Many thanks in advance,
You have a couple of problems. First, this is a piped shell command so you need to pass the string without splitting it into a list and set shell=True. Second, check_output is a bad choice here because it only returns after the program terminates but your particular command runs forever.
A better solution is to stop grepping and have python process the command. Then you can kill it when you see the data you want.
proc = subprocess.Popen(['adb', 'logcat', '-v', 'time'], stdout=subprocess.PIPE)
for line in proc.stdout:
if "Setting system time at" in line:
proc.kill()
break
proc.wait()
I already posted similar question, but still could not get my job done, so this a a second attempt, where
I would like to more clearly state my stumbling block.
So basically I am in Android phone's adb shell, communicating with the GPRS modem by sending AT commands.
I am able to do it by redirecting at command to the device file representing the modem; and I can read back
the response using cat utility running on the background (started earlier). I implemented it in a script
which can send a single AT command and read back the response. For example, here is the script to
send at+cops? to get the name of the operator the mobile is camping on:
#SendATCommand script
cat /dev/pts/7 &
echo -e at+cops?\\r > /dev/pts/7
The output looks as follows:
# ./sendATCommand
./sendATCommand
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
Now here are two problems which I cannot resolve:
I still need to manually press ENTER button to get back adb shell prompt "#". Is there a way to return
to "#" prompt programmatically? Again, I am in adb shell.
The displayed response cannot be captured, neither in a variable, nor in file, (such as(#./sendATCommand > output.txt) Output.txt file will be empty. I tried various redirections, but still did not get it to work.
Can anyone please help me resolve those two problems (if ever possible)? Ultimately I want this little script to be
called from a "super" script (e.g. Perl or Powershell) running on PC to which my Android device is
connected, but there is no way to do it until those two problems resolved. Thanks a lot in advance!
I suggest that you try out my atinout program which should be exactly what you are asking for: a program to send AT commands from the command line and capture the output.
In your case the result should be like
$ echo 'at+cops?' | atinout - /dev/pts/7 -
+COPS: 0,0,"AT&T",6
OK
$
and to capture the output just put a file name instead of the last -.
I had similar problems with redirecting output to file. I resolved my problem by adding CMD /c in front of the echo command. I.e. if I understand correctly you need to tell the system that it needs to wait until command finishes executing and only then redirect output to a file. I was doing it in DOS.
Since you are running on ANDROID try adding sh -c in front of your command. Hope it helps.
I want to dump all logs out to test a long usage of my app, maybe 2-3 days, but the logs seem to be cleared out while running after a long time.
How can I keep the logs?
I do not want to connect my device with eclipse all the day, I want the log just keep for me, like store it in the sd card for further check.
I had same requirement for my application. By default there is logcat process that tracks logs up to around 64kb (depends on device).
You can start your own logcat process using adb shell with some custom arguments. For example:
adb shell logcat -f /mnt/sdcard/large.log -r 100 -n 10
This will save up to 1mb of logs evenly distributed among 10 files (large.log, large.log.0, larget.log.1, etc.);
The next step is to launch logcat from your application:
String [] args = new String[] { Logcat, "-v", "threadtime",
"-f", logFile.getAbsolutePath(),
"-r", Integer.toString(sizePerFile),
"-n", Integer.toString(rotationCount),
"*:"+filter};
Runtime.getRuntime().exec(args);
So now your app may start saving logs. But you should be careful not to enable this in your production versions of application (or at least make this opt-in feature).
Instead of using the eclipse log use the apps like 'log viewer'. I think that app can solve your issue. I think the log will remain until you clear the log manually in 'log viewer'. I just downloaded it today morning and still has the logs of actions I performed just after I switched on the device.
Did you try dumping the log to a file?
adb logcat > log.txt