dumpsys tools,Systrace (Android System Trace) captures and shows execution instances of your app’s tactics and other Android system techniques, which helps you analyze the overall performance of your app. The tool combines facts from the Android kernel together with the CPU scheduler, disk hobby, and app threads. The device makes use of this records to generate an HTML report that shows an ordinary photograph of an Android-powered device’s machine strategies for a given time period.
Systrace is especially beneficial in diagnosing display problems while an app is slow to draw or stutters even as displaying motion or animation.
Dumpsys is an Android device that runs at the tool and dumps interesting facts about the repute of gadget services.
Both of these powerful tools assist you to take an in depth have a look at what’s occurring while your app runs. They produce a large quantity of targeted data approximately the device and apps. This information facilitates you create, debug, and improve the overall performance of your apps.
This realistic will help you get began, however completely reading Systrace and dumpsys output takes quite a few experience and is past the scope of this practical.
dumpsys tools,What you should already KNOW
Systrace and dumpsys,You should be able to:
- Create apps with Android Studio and run them on a mobile device.
- Work with Developer Options on a mobile device.
dumpsys tools,What you will LEARN
You will learn how to:
- Use Systrace to collect data about your app and view its reports.
- Run
dumpsys
to get a snapshot of information about app performance.
dumpsys tools,What you will DO
- Use Systrace to seize statistics about the WordListSQL app to your tool.
- View and navigate the trace output for WordLIstSQL.
- Find the Frames section in the Systrace output and get extra facts about particular frames.
- Examine the indicators, which show capacity overall performance problems together with your code.
- Run a trace of the LargeImages app and discover a problem with the app. Correlate what you find with the sooner Profile GPU Rendering device output.
- Run the dumpsys device to get extra records about frames.
dumpsys tools,App overview
dumpsys tools,You will not build a new app in this practical. Instead you will use apps from other practicals.
- You need the WordListSQL app. Use the version of the WordListSQL app which you constructed within the Android Fundamentals Course, or download the app from the WordListSql_finished folder from GitHub.
- You additionally want the LargeImages app from a preceding realistic, or you may down load the route model of the app from GitHub.
dumpsys tools,Run the Systrace tool to analyze the WordListSQL app
dumpsys tools,Systrace (Android System Trace) enables you examine how the execution of your app suits into the numerous strolling structures on an Android tool. It places collectively device and application thread execution on a commonplace timeline.
To analyze your app with Systrace, you first acquire a hint log of your app and the machine hobby. The generated trace allows you to view enormously unique, interactive reports showing everything happening in the device for the traced period.
You can run the Systrace tool from one of the Android SDK’s graphical person interface equipment, or from the command line. The following sections describe how to run the tool using either of those techniques.
Prerequisites
To run Systrace, you need:
- Android SDK Tools 20.0.Zero or higher, which you have already got in case you’ve followed this course.
- A cellular tool running at the least Android 4.1 with USB Debugging enabled in Developer Options. You have already got this, if you’ve accompanied this direction.
You can run on an emulator for exercise, but your hint facts won’t be correct. Some gadgets do not have Systrace enabled on the kernel they are jogging, and you may get an blunders while generating the hint. In this case, you may want to apply an emulator. See this Stack Overflow put up if you want to explore deeper.
- Python language mounted and protected on your improvement laptop’s execution direction. Check your Python set up from a command-line window:
- Mac and Linux: python -v Windows: python
If you do no longer have Python established, observe the commands for your platform at python.Org. You can also discover commands on this Check for Python documentation.
Run Systrace from Android Device Monitor
The following commands are for Android 4.2 and higher. If you are running on an older version of Android, follow the commands at the Analyze UI Performance with Systrace web page.
- If you do not have already got the WordListSQL app, down load the WordListSQL app from the WordListSql_finished folder on GitHub. Open the app in Android Studio and run it in your tool.
- From Android Studio, pick Tools > Android > Android Device Monitor. If you’ve got immediate run enabled, you will be requested to Disable ADB Integration. Click Yes.
Android Device Monitor launches in a separate window.
Important:If you run your app on an emulator, you have to restart adb as root on the way to get a hint. Type adb root at the command line.
Follow the steps as illustrated in the screenshot below:
- Click Android Device Monitor tool icon DDMS if it is not already selected. (1) in the screenshot below.
- Select your app through bundle call inside the Devices tab. (2) within the screenshot under.
- Click the Systrace button Systrace tool icon to initiate the trace. (three) inside the screenshot underneath.
- In the Systrace (Android System Trace) pop-up, choose your settings for the trace.
- Destination File: Where the trace is stored as an HTML file. Default is in your home directory with the filename trace.Html.
- Trace length: Default is 5 seconds, and 15-30 seconds is a great time to pick.
- Trace Buffer Size: Start with the default.
- Enable Application Traces from: Make positive your app is seen and decided on.
- Now pick tags to allow. Choose all the Commonly Used Tags. In the Advanced Options, select Power Management and Database. Use fewer tags to restrict the dimensions and complexity of the trace output.
- Click OK to start tracing. A pop-up appears, indicating that tracing is lively.
- Interact with the WordListSQL app to your tool. Create, edit, and delete an object.
- When time is up, the pop-up closes, and your hint is completed.
[Optional] Run Systrace from the command line
If you pick, you can run Systrace from the command line of any terminal window in Android Studio or to your computer. The following steps use a terminal in Android Studio.
The following commands are for Android 4.Three and better. If you are strolling on an older version of Android, follow the instructions within the systrace user guide.
To run Systrace from the command line:
- In Android Studio, open the Terminal pane, as an example, by using choosing View > Tool Windows > Terminal.
- In the terminal, alternate listing to wherein Systrace is positioned within the Android SDK: cd < android-sdk >/platform-gear/systrace
If you want to find the listing in which the Android SDK is hooked up: In Android Studio, choose Android Studio > Preferences and search for “sdk”. Alternatively, open Tools > Android > SDK Manager. The top of the pane has a text subject that shows the Android SDK area.
- Start Systrace: python systrace.Py –time=10
- This runs systrace for 10 seconds, with default class tags, and saves the output HTML document to the systrace listing, that is the current directory.
- Systrace is written inside the Python language.
- The time argument is the time to run, in seconds.
- See the Systrace documentation for versions and alternatives.
- If you get an mistakes approximately serial not being established, set up serial the usage of this command: sudo pip install pyserial
- Interact with the WordListSQL app to your tool till the hint stops, which occurs when time is up. Create, edit, and delete an object. If you want more time to carry out these moves, run the command with –time=30, as you probably did with the Android Device Monitor example above.
Here is an example command-line command and outcomes:
$ cd android-sdk/platform-tools/systrace
$python systrace.py --time=10
These categories are unavailable: disk
Starting tracing (10 seconds)
Tracing completed. Collecting output...
Outputting Systrace results...
Tracing complete, writing results
Wrote trace HTML file: file:///Users/<you>/sdk/platform-tools/systrace/trace.html
View and explore the Systrace output
Analyzing the whole hint report is beyond the scope of this practical. Systrace is a powerful tool, and the high-quality manner to study is through the use of it loads, by spending time looking at all the outputs. In this venture, you discover ways to navigate the trace output and look at the Frames phase.
The file generated for WordListSQL is large, and for a greater complicated app can be even larger. Practice navigating around the report to discover statistics approximately your app.
- Open one of your saved hint.Html documents for your Chrome browser. At this time, you must use Chrome. Using a unique browser may additionally display a clean page. The document ought to appearance similar to the one shown under.
The groupings are in the order Kernel, SurfaceFlinger (the Android compositor manner), observed by means of apps, each categorized via package deal call. Each app manner contains all the tracing indicators from each thread it includes, such as a hierarchy of high level tracing events based totally on the enabled tracing classes.
You can navigate the file the usage of these keyboard controls:
- W—Zoom into the trace timeline.
- S—Zoom out of the hint timeline.
- A—Pan left at the trace timeline.
- D—Pan right at the hint timeline.
- E—Center the hint timeline on the contemporary mouse location.
- G—Show grid on the start of the presently selected mission.
- Shift+g—Show grid on the give up of the currently selected assignment.
- Right Arrow—Select the next occasion at the presently decided on timeline.
- Left Arrow—Select the previous event on the currently decided on timeline.
- M—Mark this region with a vertical line so you can have a look at concurrent events within the trace.
The image shows part of the Systrace output for WordListSQL. The numbers have the following meanings:
- Section for each procedure
- Frames segment
- Frame indicator for body that rendered successfully
- Frame indicator for body that did no longer whole rendering
- Method calls for rendering selected body
To explore the Systrace output:
- The page has one section for every procedure that changed into going for walks while the hint was recorded. Scroll via the very lengthy document and find the segment for the WordListSQL app, that is referred to as ple.Wordlistsql (pid …. The outcomes will appearance different relying on how you interacted along with your app, what tool you used, and what configuration you used. You may additionally want to scroll down quite a chunk. If you wander away, close the tab and reopen the report to start afresh. Tip: Instead of scrolling, you could use the search function of your browser to look for Frames till you discover an appropriate one.
- Inside the ple.Wordlistsql phase, locate Frames.
- In the Frames line, within the graph to the right, you need to see circles which might be either inexperienced or red and are categorised with the letter F for Frame. You may additionally need to zoom in (w at the keyboard) and pan proper (d at the keyboard) to look man or woman, classified circles.
- Select a inexperienced circle. This frame is green as it completed rendering in the allotted 16 milliseconds in step with body.
- Select a crimson circle. This frame is pink because it did now not entire rendering inside 16 milliseconds.
- In the left-hand pane, scroll down if necessary till you find Render Thread. On gadgets strolling Android 5.0 (API stage 21) or higher, this work is cut up among the UI Thread and RenderThread. On prior versions, all paintings in developing a body is carried out at the UI thread. If you do now not see Render Thread, pick UI Thread instead.
- Click at the black triangle to the proper of Render Thread to enlarge the graph. This expands the bars that show you how plenty time turned into spent in every gadget motion worried in rendering this body.
- Click on a system motion to expose greater timing information inside the pane beneath the graph. Systrace analyzes the occasions inside the hint and highlights many performance issues as alerts, suggesting what to do subsequent. Below is an example of a body that turned into now not scheduled, possibly because the body changed into awaiting different paintings to be completed.
- Open the Alerts tab at the right edge of the hint window. Click on an Alert type to peer a listing of all alerts inside the bottom pane. Click an alert to peer info, an outline of what may be the hassle, and links to in addition sources.
Think of the signals panel as a listing of insects to be fixed. Often a tiny exchange or development in one location can remove a whole class of alerts out of your app!
Run the Systrace tool to analyze the LargeImages app
Run Systrace on the LargeImages app
LargeImages is a smaller demo app and the Systrace output will be less difficult to research. In the preceding realistic, Profile GPU Rendering identified a hassle with rendering a number of the frames for this app. Use Systrace to get greater facts about viable causes of the problem. In this case, you could have already got guessed what the hassle can be. When doing performance analysis, guessing is a valid approach of narrowing down your first technique. Be open to having guessed wrong!
- Open the LargeImages app in Android Studio and run it to your connected device.
- Start a Systrace trace that is 10 seconds lengthy both from the command line or Android Device Monitor.
- Flip some times between the pictures of the running LargeImages app, going through at least cycles.
- When it has finished, open the trace in your Chrome browser. This trace have to be less complicated to navigate than the hint from the WordListSQL, because this hint is a lot smaller.
- Find the section for the largeimages manner.
- Find the Frames phase for LargeImages and make bigger the UI Thread.
- If essential, zoom (w and s keys at the keyboard) and pan (a and d keys on the keyboard) to see individual frames.
- Notice the pattern of inexperienced and red frames. This pattern corresponds with the pattern of tall and short bars shown by using Profile GPU Rendering within the Profile GPU Rendering realistic. Turn on Profile GPU Rendering to refresh your reminiscence, if vital.
- Click the crimson circle frame to get more records.
- Looking on the alert records does no longer let you know specifics approximately possible reasons.
- In the Frames section, zoom in so you can see the machine movements on the UI thread which are involved in displaying this body.
- Notice
decodeBitmap
and above it, the name of the resource that is being decoded. Decoding the image is taking up all the time AND this decoding is being done on the UI Thread.
Now you know the cause of the problem. In a real app, you could address this problem by, for example, using a smaller or lower resolution image.
Important:Your hint may additionally appearance extraordinary, and you may want to discover to discover the records you need. Use the above steps as a guiding principle.
Important:Systrace is a effective device that gathers huge quantities of systems information that you may use to study more about the Android system and your app’s performance. See the systrace documentation. Explore for your own!
Run the dumpsys tool
Dumpsys is an Android tool that runs at the tool and dumps facts approximately the fame of gadget offerings since the app commenced. You can use dumpsys to generate diagnostic output for all device services going for walks on a related device. Passing the gfxinfo command to dumpsys gives output in Android Studio’s logcat pane. The output consists of performance facts that relates to frames of animation.
The motive of this practical is to get you started with this effective device. The dumpsys tool has many other alternatives that you could explore within the dumpsys developer documentation.
Run dumpsys from the command line
- Run the following command to get information about frames.
adb shell dumpsys gfxinfo <PACKAGE_NAME>
For example:
adb shell dumpsys gfxinfo com.example.android.largeimages
- Starting with Android 6.0, you could get even more distinctive records the use of the framestats command with dumpsys. For instance, run the subsequent command in opposition to a tool with Android 6.0 or later:
adb shell dumpsys gfxinfo com.example.android.largeimages framestats
Learn extra approximately how to use the information generated by this command in the Testing UI Performance and dumpsys documentation.
Important:This practical has most effective given you the primary steps in the use of Systrace and dumpsys. Systrace and dumpsys are powerful debugging tools that offer you with quite a few records. Making efficient use of this records takes exercise.
Coding challenge
- The tracing indicators defined via the gadget do now not have visibility into the whole lot your app is doing, so you may want to add your very own signals. In Android four.3 (API degree 18) and better, you may use the techniques of the Trace elegance to add alerts to your code. This approach will let you see what paintings your app’s threads are doing at any given time. Learn more at Instrument your app code.
Summary
- Systrace is a powerful tool for collection runtime statistics approximately your app, for a slice of time. Use alerts generated with the aid of the device to find capacity overall performance problems. Use the following command. The output is saved in trace.Html in the systrace listing.
$cd android-sdk/platform-tools/systrace
$python systrace.py --time=10
- The dumpsys device collects comprehensive facts approximately your app in view that its begin time, inclusive of frame rendering statistics. Use these commands:
adb shell dumpsys gfxinfo <PACKAGE_NAME> adb shell dumpsys gfxinfo <PACKAGE_NAME> framestats