代码之家  ›  专栏  ›  技术社区  ›  Mahdi

Android studio合并Trace.beginSection()和endSection()以获取总时间

  •  0
  • Mahdi  · 技术社区  · 7 年前

    我想改进我的应用程序的某些部分,并将 Trace.beginSection("MyLable"); Trace.endSection(); 查看包装方法的时间。

    但我遇到了这些问题:

    1. 首先,无法在探查器中查看我的自定义标签。
    2. Trace.beginSection Trace.endSection

    enter image description here

    我试过这个 通话表

    0 回复  |  直到 7 年前
        1
  •  0
  •   Martin Zeitler    7 年前

    测量跟踪的持续时间如何?

    long startMs = System.currentTimeMillis();
    Trace.beginSection("someLabel");
    
    /* do stuff */
    
    long endMs = System.currentTimeMillis();
    Trace.endSection();
    
    Log.d(LOG_TAG, "trace duration: " + (endMs - startMs) + "ms");
    

    也看到 systrace Generate Trace Logs by Instrumenting Your App .

    Android Q为其添加了四种新方法 Trace ,但没有任何东西能说明持续时间。

    systrace on device 可用。

    推荐文章