Java 如何分析我的 Android 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3871311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 06:09:31  来源:igfitidea点击:

How can I profile my Android app?

javaandroidperformanceprofiling

提问by teedyay

I need to find where the bottlenecks are in my Android app.

我需要找到我的 Android 应用程序中的瓶颈在哪里。

What profiling tools or techniques can I use?

我可以使用哪些分析工具或技术?

采纳答案by cement

You can use Traceview. It is far from ideal, but works. This articledescribes how to use it.

您可以使用跟踪视图。它远非理想,但有效。 本文介绍如何使用它。

回答by Shahul3D

DDMS is the best for Android. By default it get included with the ADT plugin.

DDMS 最适合安卓。默认情况下,它包含在 ADT 插件中。

Thisdocument with detailed example should help you to deal with DDMS.

这份带有详细示例的文档应该可以帮助您处理 DDMS。



For memory Analysis, try Eclipse MAT

对于内存分析,请尝试 Eclipse MAT

回答by David

It depends what're you going to test.

这取决于你要测试什么。

In case you develop applications for Android you should try out the TimingLogger class. Take a look at this articledescribing the usage of the TimingLogger helper class.

如果您为 Android 开发应用程序,您应该尝试使用 TimingLogger 类。看看这篇文章,描述了 TimingLogger 助手类的用法。

A very good tool is JMeterand there is a plugin for Androidas well.

一个非常好的工具是JMeter,还有一个适用于 Android插件

if you don't want to use external tools, but a very standard way, to measure elapsed time, you must use System.nanoTime(). You shouldn't use currentTimeMillis, because it measures wall-clock time ans, as no computer's clock is perfect (them all occasionally needs to be corrected) there's a process that runs and continually issues small corrections to the system clock. Not to mention the leap second correction.

如果您不想使用外部工具,而是一种非常标准的方法来测量经过的时间,则必须使用 System.nanoTime()。您不应该使用 currentTimeMillis,因为它测量挂钟时间,因为没有计算机的时钟是完美的(它们偶尔都需要更正),有一个进程会运行并不断向系统时钟发出小的更正。更不用说闰秒校正了。

Although currentTimeMillis is often used, it's still incorrect to measure elapsed time and timing. Anyhow, as the invocation takes some time, you should not expect to correctly time very very small intervals. But that shouldn't be an issue working with Android.

尽管经常使用 currentTimeMillis,但测量经过的时间和计时仍然是不正确的。无论如何,由于调用需要一些时间,因此您不应期望正确计时非常非常小的时间间隔。但这不应该是与 Android 一起使用的问题。

I'll show you an example:

我给你看一个例子:

long startTime = System.nanoTime();

// run/call the method

long endTime = System.nanoTime();
long diff = endTime - startTime ;
System.out.println("Elapsed milliseconds: " + diff /1000000);

You could have a look at this free library as well: http://jetm.void.fm/.

你也可以看看这个免费库:http: //jetm.void.fm/

You can also find tutorial for JMeteras well.

您还可以找到JMeter 的教程。

回答by Erhannis

Another tool recommended in http://developer.android.com/training/articles/perf-tips.htmlis Caliper: https://code.google.com/p/caliper/. (I haven't used it, so I don't know much about it.)

http://developer.android.com/training/articles/perf-tips.html 中推荐的另一个工具是 Caliper:https: //code.google.com/p/caliper/。(我没用过,所以不太了解。)