美文网首页
System Tracing 概览Google 官方教程

System Tracing 概览Google 官方教程

作者: 程序员Android1 | 来源:发表于2020-05-19 12:31 被阅读0次

和你一起终身学习,这里是程序员 Android

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

一、前言
二、System traceing introduce
三、System tracing guides

一、前言

首先不要抗拒英文文章,本文是转载Google 官方文档,故英文偏多,只有阅读原汁原味的内容,才可以真正提升自己。

二、System traceing introduce

Recording device activity over a short period of time is known as system tracing. System tracing produces a trace file that can be used to generate a system report. This report helps you identify how best to improve your app or game's performance.

The Android platform provides several different options for capturing traces:

  • Android Studio CPU profiler
  • System Tracing app
  • Systrace command-line tool
  • Perfetto command-line tool

The Android Studio CPU profiler inspects your app’s CPU usage and thread activity in real time while you interact with your app. You can also inspect the details in recorded method traces, function traces, and system traces.

The System Tracing app is an Android tool that saves device activity to a trace file. On a device running Android 10 (API level 29) or later, trace files are saved in Perfetto format (see below). On a device running an earlier version of Android, trace files are saved in the Systrace format.

Systrace is a legacy platform-provided command-line tool that records device activity over a short period of time in a compressed text file. The tool produces a report that combines data from the Android kernel, such as the CPU scheduler, disk activity, and app threads.

Perfetto is the new platform-wide tracing tool introduced in Android 10. It is a more general and sophisticated open-source tracing project for Android, Linux, and Chrome. It offers a superset of data sources compared to Systrace and allows you to record arbitrarily long traces in a protobuf-encoded binary stream. You can open these traces in the Perfetto UI: https://ui.perfetto.dev/#!/.

Figure 1. A sample Perfetto trace view, which shows about 20 seconds of interaction with an app Figure 2. A sample Systrace HTML report, which shows 5 seconds of interaction with an app

Both reports provide an overall picture of an Android device's system processes for a given period of time. The report also inspects the captured tracing information to highlight problems that it observes, such as UI jank or high power consumption.

Perfetto and Systrace are interoperable:

Note: Systrace and Perfetto don't collect detailed information about code execution within your app process. For more detailed information about which methods your app is executing and how many CPU resources it's using, use the CPU profiler:https://developer.android.com/studio/profile/cpu-profiler in Android Studio.

三、System tracing guides

To learn more about system tracing tools, see the following guides:

1.Inspect CPU activity with CPU Profiler

Inspect CPU activity with CPU Profiler:
https://developer.android.com/studio/profile/cpu-profiler

Shows how to profile your app’s CPU usage and thread activity in Android Studio.

2.System Tracing system app

System Tracing system app:
https://developer.android.com/topic/performance/tracing/on-device

Explains how to capture a system trace directly on any device running Android 9 (API level 28) or higher.

3.Systrace command-line reference

Systrace command-line reference:
https://developer.android.com/topic/performance/tracing/command-line

Defines the different options and flags that you can pass into the command-line interface for Systrace.

4.Running Perfetto using ADB

Running Perfetto using ADB :https://developer.android.com/studio/command-line/perfetto

Describes how to run the perfetto command-line tool to capture traces.

5.Running Perfetto

Running Perfetto: https://perfetto.dev/#/running.md

External documentation that describes how to build and run the perfetto command-line tool to capture traces.

6.Perfetto UI

Perfetto UI: https://perfetto.dev/#/running.md

The Perfetto Web-based trace viewer opens Perfetto traces and displays a complete report. You can also open Systrace traces in this viewer using the legacy UI option.

7.Navigate a Systrace report

Navigate a Systrace report:https://developer.android.com/topic/performance/tracing/navigate-report

Lists the elements of a typical report, presents keyboard shortcuts for navigating through the report, and describes how to identify types of performance problems.

8.Define custom events

Define custom events:https://developer.android.com/topic/performance/tracing/custom-events

Describes how you can apply custom labels to specific sections of your code, allowing for easier root-cause analysis in Systrace or Perfetto.

原文链接:

Overview of system tracing:
https://developer.android.com/topic/performance/tracing

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

相关文章

网友评论

      本文标题:System Tracing 概览Google 官方教程

      本文链接:https://www.haomeiwen.com/subject/xodvohtx.html