Android Dalvik GC Log Analysis
Your mobile app's memory usage impacts the user experience. Gain a better understanding of how memory usage is logged and what it can tell you.
Join the DZone community and get the full member experience.
Join For FreeMemory utilization on a mobile app has a significant impact on the customer experience. If your app creates a lot of objects, then the Garbage Collection (GC) process will be triggered frequently to evict unused objects. Even though Garbage Collection is an automatic process, however, frequent Garbage Collection consumes a lot of CPU, and it will also pause the app. Frequent pauses can mess up the app (e.g. stuttering or halting).
Thus, you need to understand how many objects your app is creating, how frequently Garbage Collection is triggered, how much time it takes to complete, and how much memory is reclaimed after every event. All this information is present in the runtime log messages. Whenever a GC event runs, a log line is printed in the runtime log messages. You can view those log lines through logcat.
GC log line format varies based on whether app runs on Dalvik VM or Android Run Time (ART). In an earlier article, we saw how to analyze ART GC log lines. Now let’s see how to analyze a Dalvik GC log line.
This is how a typical Dalvik GC log line will look:
This one single log line has multiple fields. Below table summarizes each field in detail:
# |
Field | Value | Description |
1 | Timestamp | 07-01 15:56:19.815 | Timestamp at which this Garbage Collection event ran |
2 | GC Reason | GC CONCURRENT | Reason why Garbage Collection event was triggered. Please refer here for different types of GC Reasons. |
3 | Objects freed | 7078K | Amount of objects garbage collected. Totally 7078kb of objects are garbage collected (i.e. freed) in this event. |
4 | Heap usage | 52464K/ 89052K | 52464kb of objects are alive after this particular GC event. Total allocated heap size for this app is 89052 kb. |
5 | GC Pause Time | 14ms+4ms | During certain phases of GC event, application is paused. In this GC event, pause time is 18 ms (i.e. 14 + 4 ms). During pause time, application freezes. One should target for low pause time. |
6 | GC Total Time | 96ms | Amount of time this GC event took to complete. It includes the GC Pause time as well. |
Tools
As it might get tedious to analyze every single GC log line, you can also consider using free online tools such as GCeasy.io – a universal Garbage collection log analyzer, to analyze Android GC logs. You can just upload the Android GC Logs to this tool. Tool parses GC log and generates report instantly. Report contains interactive graphs and insightful metrics. A few excerpts from this report are given below for your reference.
Fig 1: Android memory usage – report generated by GCeasy.io.
Fig 2: KPI – report generated by GCeasy.io.
Published at DZone with permission of Ram Lakshmanan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments