用atrace(systrace)查看exo起播

2019-06-09  本文已影响0人  1700

没法用Android systrace的话,也可以直接用atrace命令来抓取数据,再转换成html格式。

  1. 平台命令行输入atrace命令,仅抓取exoplayer的trace数据
    atrace -a com.google.android.exoplayer2.demo -o /data/1.atrace -t 10

其中-a 指定只看exoplayer,-t 10秒,-o 输出文件路径

  1. 转换成html格式
    在android目录external/chromium-trace/下执行命令转换
X:Android_top/external/chromium-trace$ ./systrace.py --from-file 1.atrace
 Reading results from file.
 Tracing completed. Collecting output...
 Outputting Systrace results...
 Tracing complete, writing results
 Wrote trace HTML file: [file://X/Android_top/external/chromium-trace/1.html](file:///mnt/nfsroot/username/q0522/external/chromium-trace/1.html)
  1. 用chrome浏览器打开1.html

3.1 查看dash起播耗时


image.png

3.2 SmoothStreaming起播耗时


image.png

3.3 HTTP起播耗时


image.png
  1. exoplayer封装了traceutil,调用android trace
package com.google.android.exoplayer2.util;
import android.annotation.TargetApi;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
/**
* Calls through to {@link android.os.Trace} methods on supported API levels.
*/
public final class TraceUtil {
  private TraceUtil() {}
  /**
   * Writes a trace message to indicate that a given section of code has begun.
   *
   * @see android.os.Trace#beginSection(String)
   * @param sectionName The name of the code section to appear in the trace. This may be at most 127
   *     Unicode code units long.
   */
  public static void beginSection(String sectionName) {
    if (ExoPlayerLibraryInfo.TRACE_ENABLED && Util.SDK_INT >= 18) {
      beginSectionV18(sectionName);
    }
  }
  /**
   * Writes a trace message to indicate that a given section of code has ended.
   *
   * @see android.os.Trace#endSection()
   */
  public static void endSection() {
    if (ExoPlayerLibraryInfo.TRACE_ENABLED && Util.SDK_INT >= 18) {
      endSectionV18();
    }
  }
  @TargetApi(18)
  private static void beginSectionV18(String sectionName) {
    android.os.Trace.beginSection(sectionName);
  }
  @TargetApi(18)
  private static void endSectionV18() {
    android.os.Trace.endSection();
  }
}
  1. 添加traceutil调用
import com.google.android.exoplayer2.util.TraceUtil;
TraceUtil.beginSection("start");
func();
TraceUtil.endSection();

上一篇下一篇

猜你喜欢

热点阅读