Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands for Android App debugging

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the commands for Android App debugging". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what are the commands for Android App debugging.

1.logcat command

This command is the most simple and commonly used, you can check the help, I will not say much, if you need to print time, add the parameter-v time

Adb logcat-v time

2.bugreport command

This command is also very simple, but very useful in practical applications, there will be detailed dumpsys,dumpstate and logcat information after boot, is a complete log record. It is of great reference to the analysis of user behavior, abnormal information and system state. Usually we export bugreport to the computer for analysis.

1adb bugreport > xxx.log

I emphasize again that bugreport contains a wealth of system and user information, which is a record of the output of many other commands and is very useful.

3.dumpsys command

This view system information, or use more.

Dumpsys [options]

Meminfo displays memory information

Cpuinfo displays CPU information

Account displays accounts information

Activity displays information about all activities

Window displays keyboards, windows and their relationships

Wifi displays wifi information

For example, view the memory information of a program:

# View the memory usage of the application com.tianxia.test

Adb shell dumpsys meminfo com.tianxia.test

The effect picture is as follows:

The information inside is very valuable, especially for the analysis of memory leaks and memory overflows.

4.top command

It's so convenient to check cpu information.

1top-m 5-t

Let's take a look at the effect diagram, which lists five processes by cpu size.

The cpu of com.tianxia.test is too high, which can cause the phone to be hot. At the same time, with this information, you can monitor the use of the application cpu to adjust the optimized code.

5. Profile local.prop

At present, the configuration and use of local.prop has not been found on the Internet. I have only used the following in my work:

1log.tag.SQLiteStatements=VERBOSE log.tag.SQLiteTime=VERBOSE

Add the above text to / data/local.prop, if you don't have this file, create it yourself. Then restart the phone, you can see the detailed sql statement information of each application to query the database, which is very useful for debugging the database, analyzing and optimizing the database sql.

6. Analyze the hot mobile phone.

Let's practice an example, the mobile phone is too hot, how to find out the problem?

First of all, let's write a program com.tianxia.test, endless loop, the core code is as follows:

8@Override

Public void onCreate (Bundle savedInstanceState) {

Super.onCreate (savedInstanceState)

SetContentView (R.layout.main)

While (true) {

System.currentTimeMillis ()

}

}

This application will always get the system time after it is opened, because in the main thread, it will definitely lead to the application ANR, and it will always waste the system cpu, the phone will be hot, and we will run it.

Assuming we don't know the above code, let's find the problem:

(1)。 Find a hot app.

Use the top command:

1top-m 5-t

At first glance, com.tianxia.test occupies 85% of the cpu, and it turns out that this guy is messing around. The process ID is 644, which we can use later.

(2)。 Analyze what the hot application process is doing.

You need to use the strace command under linux, but android does not integrate this command, the download address of the android version:

Http://benno.id.au/android/strace

After the download is completed, upload it to the mobile phone:

If we adb push strace / system/bin, uploading to / system/bin on the simulator will report an out of memory error. We can also upload it to the / data directory. If we don't have the permission to execute, we still need chmod 777 strace.

The strace command has many parameters, and executing strace directly displays instructions for using it:

The-p parameter inputs the process number. In step * *, we find that the process ID of com.tianxia.test is 644. Let's see why this application occupies such a high cpu.

?

1strace-p 644

The output is as follows:

Its system call has always been gettimeofday, has been output this, obviously somewhere must have entered an endless loop, but to get the time of the dead loop, and then combined with logcat and code, locate this code (that is, the code we gave earlier) to solve the bug.

7. Collect the cpu operation of the mobile phone.

Sometimes it is difficult for us to get the information we want pertinently by using the log. We may need to write some of the simplest steps and put them in the phone to perform.

For example, the records occupied by the monitoring cpu cpu_log.sh:

11#! / system/bin/sh

# this step is rather rough, it means

File=/sdcard/cpu/cpu_info.log

Rm $file

Until [1-gt 10000]

Do

Echo-e "\ n\ n -" > $file

Date > > $file

Top-m 5-n 1 > > $file

Sleep 3

Done

Every 3 seconds, the cpu information of the phone will be written to the cpu_info.log file under the cpu directory of sdcard, which is convenient for our follow-up analysis.

Ps: the method is to push to the data directory, grant executable permission, and execute it under shell.

8. Collect memory data of an application

This practice is similar to the script above, except that the command is different and I list it separately, because this is sometimes useful.

For example, we need to collect the memory usage of com.tianxia.test and analyze whether it will leak memory. The steps are similar:

11#! / system/bin/sh

# this step is rather rough, it means

File=/sdcard/cpu/mem_info.log

Rm $file

Until [1-gt 10000]

Do

Echo-e "\ n\ n -" > $file

Date > > $file

Dumpsys meminfo com.tianxia.test > > $file

Sleep 3

Done

It's the same way to use it.

At this point, I believe you have a deeper understanding of "what are the commands for Android App debugging?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report