Application Performance Profiling in Android Dalvik Virtual Machines 1297
Total Page:16
File Type:pdf, Size:1020Kb
VOL. E99-D NO. 5 MAY 2016 The usage of this PDF file must comply with the IEICE Provisions on Copyright. The author(s) can distribute this PDF file for research and educational (nonprofit) purposes only. Distribution by anyone other than the author(s) is prohibited. IEICE TRANS. INF. & SYST., VOL.E99–D, NO.5 MAY 2016 1296 PAPER Application Performance Profiling in Android Dalvik Virtual Machines Hung-Cheng CHANG†a), Kuei-Chung CHANG††, Nonmembers, Ying-Dar LIN†, Member, and Yuan-Cheng LAI†††, Nonmember SUMMARY Most Android applications are written in JAVA and run However, some approaches cannot be directly used for on a Dalvik virtual machine. For smartphone vendors and users who wish Android systems. First, the source code of an application to know the performance of an application on a particular smartphone but usually cannot be obtained easily, which makes the source cannot obtain the source code, we propose a new technique, Dalvik Pro- filer for Applications (DPA), to profile an Android application on a Dalvik code instrumentation not feasible. Second, an Android sys- virtual machine without the support of source code. Within a Dalvik vir- tem runs applications on a Dalvik virtual machine (DVM). tual machine, we determine the entry and exit locations of a method, log its A classical Java virtual machine is a stack-based VM, and execution time, and analyze the log to determine the performance of the ap- a Dalvik virtual machine is a register-based VM [12], [13]: plication. Our experimental results show an error ratio of less than 5% from ff ff the baseline tool Traceview which instruments source code. The results also di erent virtual machine architectures have very di erent show some interesting behaviors of applications and smartphones: the per- bytecode formats and processing flows, so that a VM inter- formance of some smartphones with higher hardware specifications is 1.5 ception analysis for a classical JAVA VM cannot be applied times less than the phones with lower specifications. DPA is now publicly directly to a Dalvik VM. This means that the virtual ma- available as an open source tool. chine interception techniques would not work well on An- key words: Android, Dalvik virtual machine, profiling droid systems [5]–[8]. Last, because the DVM is viewed as a single process in the kernel and each application is an exact 1. Introduction replica of the original process, a native Android application cannot be analyzed in any detail, such as method profiling. Android has been one of the most important operating sys- On the other hand, although some approaches are specific to tems (OSs) developed for handheld devices, and more users Android [4], [11], they still need the help of other tools. have become concerned about the performance of their mo- An Android system is composed of several layers, as bile devices when running an application. Thus, how to shown in Fig. 1. The Application Framework Layer pro- determine the performance of Android applications has be- vides modularized library-like functions for running appli- come one of the major issues in their design. Most Android cations. All Android applications are executed by a Dalvik applications are written in JAVA language and run on a vir- virtual machine, and in the Linux Kernel Layer, the whole tual machine (VM), and there are four profiling approaches Dalvik virtual machine is regarded as a single process, so we to assess performance of a Java application in terms of pro- cannot obtain detailed profiling information of the DVM in filing location. The first one is to instrument the application this layer. Instrumentation in a Dalvik virtual machine could source code to acquire its performance information [1]–[3]. be a feasible way of profiling the Android application. Second, one can embed profiling points in the virtual ma- In this work, we develop a novel approach to profil- chine to extract the required information through JAVAbyte- ing, Dalvik Profiler for Applications (DPA), to instrument code analysis for VM-based applications [4]–[7]. Third, one a Dalvik virtual machine to collect profiling information at can extract the native code in the system kernel or in the two levels, without application source code. In process-level memory of the physical machine and analyze the collected profiling, we can estimate the performance of the target ap- information to estimate its performance [8]–[10]. Fourth, an plication; in method-level profiling, we can further estimate emulator can be built to analyze the data collected from An- the performance distributions of all methods in the target droid to profile the system [11]. application. Figure 1 shows the layout of DPA, which con- Manuscript received July 15, 2015. sists of four components in a Dalvik virtual machine and Manuscript revised November 27, 2015. one component in the host. The method start time retriever Manuscript publicized January 25, 2016. / †The authors are with the Department of Computer Science, and method end time retriever collect the entry exit time, National Chiao Tung University, Hsinchu, Taiwan. name, and process identity (PID) of a method. The record ††The author is with the Department of Information Engineer- buffer temporarily holds the data from the retrievers and then ing and Computer Science, Feng Chia University, Taichung, Tai- passes the data on to the log file in some system storage wan. ff ††† (e.g. a flash memory) when the bu er is full. After profil- The author is with the Department of Information Manage- ing, the analyzer in the host can analyze the data stored and ment, National Taiwan University of Science and Technology, Taipei, Taiwan. retrieve the profiling results. The remainder of this paper a) E-mail: [email protected] is organized as follows. In Sect. 2, we discuss related work DOI: 10.1587/transinf.2015EDP7277 in detail. The design and implementation of the proposed Copyright c 2016 The Institute of Electronics, Information and Communication Engineers CHANG et al.: APPLICATION PERFORMANCE PROFILING IN ANDROID DALVIK VIRTUAL MACHINES 1297 Fig. 1 Android framework with proposed DPA. profiling approach in DVM are described in Sects. 3 and 4, the analysis process needs the aid of Traceview [3]. respectively, and we evaluate the profiling system by dis- Third, we can intercept the native code in the kernel or cussing its precision and granularity in Sect. 5. Finally the in the memory of the physical machine, and analyze the col- conclusion and future work are given in Sect. 6. lected information to estimate performance. Javana [8] and FIT [9] instrument the native code in the physical machine 2. Background to profile an application. *J [10] records many application runtime events and analyzes these events to profile the appli- In terms of profiling location, there are four approaches to cation offline. As a result of the offline processing, *J avoids performance profiling of an application. The first is to inter- the overhead caused by profiling. These may all be invalid cept the application source code to acquire the performance on Android because a Linux Kernel Layer regards the whole information. Heap Profiling [1] is a tool that rewrites the ap- DVM as a single process, and each application is a replica plication source code for profiling. Rewriting also allows of the DVM process. It is difficult to obtain detailed perfor- more garbage collection during application running time in mance information, such as the performance of a method in order to save memory space when profiling. Spoon [2] in- an application, by means of a traditional profiling tool. struments an application during compiling time to profile Fourth, we can build an emulator outside the Android the performance, without the need for an extra compiler and analyze the system. VPA [11] is such an emulator that or language. Traceview [3] is a debugging tool developed takes data collected from the Android and some pre-built by Google which provides precise, detailed, and compre- models, e.g. time model and power model, as input to profile hensive analysis of a running Android application. How- the whole system. It can provide a comprehensive profiling ever, Heap Profiling, Spoon, and Traceview need the sup- result, but the additional emulator is too complex for average port of an application source code. For example, Trace- consumer to use. view needs instructions, Debug.startMethodTracing() and The advantages and disadvantages of these profiling Debug.stopMethodTracing(), in the source code to activate methods are listed in Table 1. Because of the constraints on a method profiling process for an application. This may profiling without source codes and the incapacity of method- be impractical for profiling because the source code usually level profiling in kernel, a virtual machine is an ideal loca- cannot be easily obtained. tion to profile Android applications. But, as noted above, Second, one can instrument the virtual machine to ob- traditional profiling techniques in a JAVA virtual machine tain the required information for VM-based applications. may not be feasible for a Dalvik virtual machine. We thus Method-Level Phase Analysis [5] collects application work- propose DPA to profile Android applications in DVM. DPA loads in JAVA virtual machines and analyzes these work- is a source code which is independent of Dalvik VM special- loads offline to observe the method-level behavior of an ap- ized profiling tools. DPA obtains the information on pro- plication. Wave Analysis [6] profiles power consumption cesses and methods in a Dalvik VM directly and analyzes of JAVA applications on mobile devices. It plants a mon- the information off-line to avoid profiling overhead. The itor across a JAVA virtual machine and the OS, and feeds only constraint is that DPA needs the support of the Android the monitored results to external equipment.