One, theBug appears, need to "kill" it
Bug sounds scary, but as long as you understand,Android bug is very good solution, because Android provides the log mechanism, the specific underlying code, in the future to analyze, as long as you will see the bug,
Application development in Android is also very simple.
Let's take a look at the ANR in Android, how does the ANR appear, very simple.
# adb Shell
# CD Data/app
# monkey-p Com.xxx.xxx-v (Com.xxx.xxx is your app's package name, if you want to know monkey detailed usage, execute monkey Help)
In fact, many good Android applications will appear ANR, such as the UC Browser, so on, if you are interested to go back to try,
In this way, the ANR appeared. Start making modifications to prepare for the log file.
Someone asked where the log file is?
Generally under the/data/log (but the real machine only). You can take a look through the command adb shell and pull the log file onto your computer.
OK, we got the log file and we're ready to start working . I upload the detailed log file to the attachment for your reference.
To http://download.csdn.net/detail/andy_android/3785393
Second, the type of log
Android.util.Log commonly used methods include the following six:log.v () log.d ( ) log.i () LOG.W ( ), log.e () and Log.a () ( Android 4.0 new additions). According to the first letter corresponds to VERBOSE,Debug,info,warn,error,assert.
1, log.v debugging color is black , any message will be output, here V for verbose wordy meaning, usually use is LOG.V ("," ");
2, LOG.D output color is blue , only the meaning of debug debugging output, but he will output the upper level of information, filtering up can be DDMS by the logcat tag to choose.
3, LOG.I output is green , general informational message information, it will not output LOG.V and LOG.D information, but will display I, W and e information
4, log.w the meaning of Orange , can be seen as a warning warning, we generally need to pay attention to optimize the Android code, while selecting it will also output LOG.E information.
5, LOG.E is red, you can think of error errors, here only the red error message, these errors need our careful analysis, view the stack of information.
6 LOG.A for 4.0 new added.
Start Eclipse, open Ddms Everyone can see in the logcat (provided that the Android 4.0 ADT)
Third, how to analyze and study log file, how to look at the log information. Log status in Android is very important, if as an Android programmer can not analyze log this, is not an introduction to Android. Let's say how to handle the log file.
Log is divided into fatal and ANR
When will the log file be generated?
Log generation We all know that we all know that through DDMS to see log (this is needless to say), but when will generate a log file? A log file is typically generated in the following situations.
1, program abnormal exit, Uncausedexception (Fatal)
2, program forced shutdown, forceclosed (FC) (Fatal)
3, program unresponsive, Applicationno Response (ANR)
The following two types of ANR appear
A click-to-wait response time for the interface action button is longer than 5 seconds
The B Handlemessage callback function executes for more than 10 seconds, and the Onrecive () method in Broadcasterreciver processes more than 10 seconds
4, manually generated.
Get a log file, to be divided into several paragraphs to see. The log file is very long and contains more than 10 small pieces of information, but not to be frightened, in fact he consists mainly of three blocks.
1, the system basic information, including memory, CPU, process queue, virtual memory, garbage collection and other information. ------MEMORY INFO (/proc/meminfo)------
------CPU INFO (top-n 1-d 1-m 30-t)------
------Procrank (Procrank)------
------VIRTUAL MEMORY STATS (/proc/vmstat)------
------Vmalloc INFO (/proc/vmallocinfo)------
The format is as follows:
------MEMORY INFO (/proc/meminfo)------
memtotal:347076 KB
memfree:56408 KB
buffers:7192 KB
cached:104064 KB
swapcached:0 KB
active:192592 KB
inactive:40548 KB
Active (anon): 129040 KB
Inactive (anon): 1104 KB
Active (file): 63552 KB
Inactive (file): 39444 KB
unevictable:7112 KB
mlocked:0kb
swaptotal:0 KB
swapfree:0 KB
dirty:44kb
writeback:0 KB
anonpages:129028 KB
mapped:73728 KB
shmem:1148kb
slab:13072kb
sreclaimable:4564 KB
sunreclaim:8508 KB
kernelstack:3472 KB
pagetables:12172 KB
nfs_unstable:0 KB
bounce:0kb
writebacktmp:0 KB
commitlimit:173536 KB
committed_as:7394524 KB
vmalloctotal:319488 KB
vmallocused:90752 KB
vmallocchunk:181252 KB
2, event information, is also our main analysis of information.
------Vmalloc INFO (/proc/vmallocinfo)------
------EVENT INFO (/proc/vmallocinfo)------
The format is as follows:
------SYSTEM LOG (logcat-b system-v time-d *:v)------
01-1516:41:43.671 W/packagemanager (2466): Unknown Permissioncom.wsomacp.permission.PROVIDER in Package Com.android.mms
01-1516:41:43.671 I/activitymanager (2466): Force stopping Packagecom.android.mms uid=10092
01-1516:41:43.675 i/usagestats (2466): Something wrong here, didn ' t expectcom.sec.android.app.twlauncher to be paused
01-1516:41:44.108 I/activitymanager (2466): Start proccom.sec.android.widgetapp.infoalarm for servicecom.sec.android.widgetapp.infoalarm/.engine.dataservice:pid=20634uid=10005 gids={3003, 1015, 3002}
01-1516:41:44.175 W/activitymanager (2466): Activity Pause Timeout forhistoryrecord{ 48589868com.sec.android.app.twlauncher/. Launcher}
01-1516:41:50.864 I/keyinputqueue (2466): Input Event
01-1516:41:50.866 D/keyinputqueue (2466): Screencapturekeyflag SETTING0
01-1516:41:50.882 I/powermanagerservice (2466): Ulight 0->7|0
01-1516:41:50.882 I/powermanagerservice (2466): Setting target 2:cur=0.0target=70 delta=4.6666665 nominalCurrentValue =0
01-1516:41:50.882 I/powermanagerservice (2466): Scheduling lightanimator!
01-1516:41:51.706 D/powermanagerservice (2466): enablelightsensortrue
01-1516:41:51.929 I/keyinputqueue (2466): Input Event
01-1516:41:51.933 W/windowmanager (2466): No Focus window, dropping:keyevent{action=0 code=26 repeat=0 meta=0 scancode= 26MFLAGS=9}
3, virtual machine information, including process, thread tracking information, which is a good place to track process and thread specific points.
------VM traces JUST now (/data/anr/traces.txt.bugreport:2011-01-1516:49:02)------
------VM traces at last ANR (/data/anr/traces.txt:2011-01-15 16:49:02)------
The format is as follows:
-----pid 21161 at 2011-01-15 16:49:01-----
Cmdline:com.android.mms
Dalvikthreads:
"Main" prio=5 tid=1 NATIVE
|group= "main" scount=1 dscount=0 s=n BJ=0X4001D8D0SELF=0XCCC8
|systid=21161 nice=0 sched=0/0 Cgrp=default handle=-1345017808
|schedstat= (4151552996 5342265329 10995)
Atandroid.media.mediaplayer._reset (Native Method)
Atandroid.media.MediaPlayer.reset (mediaplayer.java:1218)
Atandroid.widget.VideoView.release (videoview.java:499)
ATANDROID.WIDGET.VIDEOVIEW.ACCESS$2100 (VIDEOVIEW.JAVA:50)
Atandroid.widget.videoview$6.surfacedestroyed (videoview.java:489)
Atandroid.view.SurfaceView.reportSurfaceDestroyed (surfaceview.java:572)
Atandroid.view.SurfaceView.updateWindow (surfaceview.java:476)
Atandroid.view.SurfaceView.onWindowVisibilityChanged (surfaceview.java:206)
Atandroid.view.View.dispatchDetachedFromWindow (view.java:6082)
Atandroid.view.ViewGroup.dispatchDetachedFromWindow (viewgroup.java:1156)
Atandroid.view.ViewGroup.removeAllViewsInLayout (viewgroup.java:2296)
Atandroid.view.ViewGroup.removeAllViews (viewgroup.java:2254)
Atcom.android.mms.ui.SlideView.reset (slideview.java:687)
Atcom.android.mms.ui.SlideshowPresenter.presentSlide (slideshowpresenter.java:189)
Atcom.android.mms.ui.slideshowpresenter$3.run (slideshowpresenter.java:531)
Atandroid.os.Handler.handleCallback (handler.java:587)
Atandroid.os.Handler.dispatchMessage (handler.java:92)
Atandroid.os.Looper.loop (looper.java:123)
Atandroid.app.ActivityThread.main (activitythread.java:4627)
Atjava.lang.reflect.Method.invokeNative (Native Method)
Atjava.lang.reflect.Method.invoke (method.java:521)
Atcom.android.internal.os.zygoteinit$methodandargscaller.run (zygoteinit.java:858)
Atcom.android.internal.os.ZygoteInit.main (zygoteinit.java:616)
Atdalvik.system.NativeStart.main (Nativemethod)
--------------------------------------------------------------------------------------------------------------- ------------------------
With less gossip, I summed up the basic steps of observing the log file. 1, if it is ANR problem, search "ANR" keyword. Quickly navigate to critical event information.
2, if it is forceclosed and other abnormal exit information, search "Fatal" keyword, quickly locate the key event information.
3, after locating the critical event information, if the information is not clear, then search the application package for virtual machine information, view the specific process and thread tracking log, to locate the code.
With this method, there are problems, there is no need to debug breakpoints, direct positioning to the problem, and tried.
Let's start by analyzing the log of this example.
Open the log file, because it is a ANR error, so Search "ANR", why add a space, you add and remove the comparison will know. You can block out many invalid information saved to the Anr.log file.
Navigate to the key event information as follows:
01-1516:49:02.433 E/activitymanager (2466): ANR in Com.android.mms (Com.android.mms/.ui. slideshowactivity)
01-1516:49:02.433 E/activitymanager (2466): Reason:keydispatchingtimedout
01-1516:49:02.433 E/activitymanager (2466): load:0.6/0.61/0.42
01-1516:49:02.433 E/activitymanager (2466): CPU usage from 1337225ms to57ms ago:
01-1516:49:02.433 E/activitymanager (2466): sensorserver_ya:8% = 0% user + 8% kernel/faults:40 minor
......
01-1516:49:02.433 E/activitymanager (2466):-com.android.mms:0% = 0% user + 0% kernel
01-1516:49:02.433 E/activitymanager (2466):-flush-179:8: 0% =0% user + 0% kernel
01-1516:49:02.433 E/activitymanager (2466): total:25% = 10% user + 14%kernel + 0% iowait + 0% IRQ + 0% SOFTIRQ
01-1516:49:02.436 i/(2466):d umpmesg > "/data/log/dumpstate_app_anr.log"
We use natural language to describe the log, which is a kind of ability.
01-1516:49:02.433 E/activitymanager (2466): ANR in Com.android.mms (Com.android.mms/.ui. slideshowactivity)
Translation: at 16:49 minutes, 2 seconds, 433 milliseconds Activitymanager
Log log file analysis in Android