Android: 使用 Traceview 和 Genymotion 进行分析时,.trace 文件在哪里?

Android: Where is the .trace file when Profiling with Traceview and Genymotion?

我正在阅读这篇关于 运行ning traceview on your android app 的文章:https://developer.android.com/studio/profile/traceview.html 我假设他们正在谈论的模拟器是 android 模拟器,而不是我正在使用的 Genymotion 模拟器。

它说要将跟踪文件从模拟器中拉出到您的主机上,您只需运行以下命令即可:

adb pull /sdcard/startup.trace /tmp

我 运行 它在我的 Genymotion 模拟器上,但找不到该文件。然后,我使用 Android 设备监视器查看设备内部的文件,但该位置没有保存名为 startup.trace 的文件。

我在我的代码中这样做了:

public class MyApplication extends MultiDexApplication {

    public void onCreate() {
        super.onCreate();
        Debug.startMethodTracing("startup"); 
    }
  }

然后我在 activity onResume 方法中停止跟踪以测量我的应用程序的启动时间:

@Override
protected void onResume() {
    super.onResume();
    Debug.stopMethodTracing();
}

我希望 traceview 测量我的启动时间,但不知道该文件在我的 Genymotion 模拟器上的保存位置。任何人都可以帮助我保存文件的位置吗?

因此,在使用一个简单的 android 应用程序对其进行测试后,它实际上按计划运行。

我创建了一个小回购来证明这一点:

https://github.com/Winghin2517/TraceviewTest.git

您可以下载它,运行 它在您的 genymotion 模拟器上,然后在 Android Studios 的 "Terminal" 选项卡中键入以下内容:

adb pull /sdcard/startup.trace /tmp

它将从 Genymotion 中提取跟踪文件。然后你需要打开 DDMS 并说 "File" -> "Open" 然后打开 startup.trace 文件。

我创建的 android 应用演示了将 1000 条消息注销到控制台所需的时间。你可以看到皮肤颜色条代表时间 android 用于调用我的 testCount 方法:

这是我的结果:

我的方法 testCount 需要 10 毫秒才能完成。

Log.e 方法的 隐式调用 也很有意义,因为我的代码中的循环是对 log.e 方法的 1000 次调用。

包含CPU时间为包含cpu时间。它是函数本身花费时间的总和,也是它调用的所有函数的时间总和。

排除CPU时间为独占cpu时间。这只是花在函数本身上的时间。您会注意到它始终与 "self" child 的 "incl time" 相同。

我无法从上面的示例应用程序(或任何应用程序)中找到 .trace 文件。因为 .trace 文件不位于:

/sdcard/<myTraceFile>.trace

我确实使用 find 命令来查找我的跟踪文件的位置,如下所示:-

$adb shell
$cd /sdcard
$find |grep .trace

我的文件位置在:

./Android/data/test.com.trackstartuptime/files/startup.trace

对于上面的示例应用程序。现在将此位置用于 adb pull as :-

$adb pull /sdcard/Android/data/test.com.trackstartuptime/files/startup.trace <my_location>