Mobile Development 9 min read

Android Method Tracing: Implementation and Principles

Android method tracing, a Google‑provided Java‑level profiling tool, captures function‑level execution times via sampling or explicit enter/exit hooks, outlines its startup flow and collection categories, and describes recent Android advances such as JIT‑generated hooks and instrument‑based replacement of trace‑odex support.

OPPO Kernel Craftsman
OPPO Kernel Craftsman
OPPO Kernel Craftsman
Android Method Tracing: Implementation and Principles

一、method tracing介绍

概述

这个是谷歌提供的对java的函数级trace工具,和systrace只支持打点不同,method tracing能支持到函数,看到具体的函数执行时间,准确的分析出来执行的时间短板。

1.生成trace的方式

sampling方式:

采样方式采用sample任务,定期抓取各个线程的调用栈,采集精度和采集的频次正相关,同时由于java stack采集的时候需要做suspend,因此还是有一部分的效率损失。

trace方式:

通过在执行流程插入enter-exit来观测:

2.trace启动流程

我们从trace方式的启动入口开始看起

3.trace采集的分类

从前面的代码流程中,我们能发现,分成了两个类型。

4.安卓最新的演进

1.演进概述

2.谷歌最新变更相关合入:

1.jit code中直接生成enter/exit hook调用

2.instrument替换掉trace odex的支持

method tracing介绍

概述

1.生成trace的方式

2.trace启动流程

3.trace采集的分类

4.安卓最新的演进

1.演进概述

2.谷歌最新变更相关合入:

1.jit code中直接生成enter/exit hook调用

2.instrument替换掉trace odex的支持

InstrumentationandroidAndroid DevelopmentPerformance analysisMethod Tracing
OPPO Kernel Craftsman
Written by

OPPO Kernel Craftsman

Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.