SQL statement in Perfetto, a performance analysis tool

        Built-in SQLite in Perfetto, you can analyze the performance of each part of the trace through SQL query, and collect the data together for comparative analysis, which is very convenient and convenient.

        This article is based on the common SQL statements in Perfetto, without going deep into the SQL language itself.

        You can also pay attention to the "Moyu IT" public account, which will also release relevant technical documents and technical information--

how to query performance data quickly and easily

1. UI display

        On Perfetto's visual display webpage:   Import the captured trace file into Perfetto UI , and after loading, click Query (SQL) in the sidebar. This location is the entry point for the SQL query provided by Perfetto.

        After clicking Query (SQL), you can see two parts. The upper part is the editing area of ​​the SQL statement. After entering the query statement, press Ctrl + Enter to end.

        In the following part, the query SQL statement history before the trace will be displayed before the statement is entered. When the new SQL statement is entered with Ctrl + Enter , this part will display the query result.

        In this section we can demonstrate a simple query method.

        For example, query the occurrence time and duration of each event on the slice in the trace.

 select dur,ts,name from slice

//ts: display timestamp timestamp

//dur: Indicates the duration of the event that needs to be asked

//name: Indicates the object name of the query

//slice: Indicates the collection of events for a period of time on the trace

2. Basic usage of SQL

2.1 Common syntax for conditional search

       The most used in perfetto is the conditional query SQL, and the running order is: ①from statement ②where statement ③select statement.

select <column name 1>,<column name 2>,<column name 3>,...

from <table name>

where condition

        Set an alias for the column name—as, change the name column name in the table table1 to "name"

select name as 'name'

from table1

         Arithmetic calculations can be performed in the select statement, such as changing the time under the dur column into seconds (dividing micron by 10 6 times).

select (dur/1e6),ts,name from slice

        Support string fuzzy search in where conditional statement, use keyword: LIKE

        _ means any character; % means any character string. For example, it takes time to look up a thread whose name is probably doTraversals.

        Note: When using like to search, try to add % before and after the string. If you do not add % at a certain position, the position will be used as an exact search by default, which may cause the search to fail.

select (dur/1e6) from slice where name like "%doTraversals%" 

2.2 Schematic use case

        Usage scenario: Find the time spent by HAL in the trace to take pictures, and get the average time.

select (dur/1e6) from slice where name like "%still%" order by dur desc

         Use %still% to fuzzily find the time-consuming of the still capture thread, and use order by dur desc to sort in descending order. However, if you need to obtain the average time, you can use arithmetic calculations in the select statement, using the keyword avg.

select avg(dur/1e6) from slice where name like "%still%" order by dur desc

         The above can achieve the desired search results.

3. Summary

        Using SQL query statements in Perfetto can efficiently obtain the required data in the entire trace and improve the efficiency of performance analysis. And through the combination of SQL statement and python statement, by loading trace, it can automatically analyze the performance of a certain fixed scene, and through the combination of perfetto, SQL and python, it can realize automatic analysis of performance scene, greatly improve the efficiency of technicians, and reduce unnecessary repeated analysis work.

Guess you like

Origin blog.csdn.net/qrx941017/article/details/131057809