PerfettoSQL

​​​​# Device State: Top App

# select id, ts, dur, name from (__query_slice_track__long_battery_tracing_Device_State_Top_app)

--> 简便方法
"""
INCLUDE PERFETTO MODULE android.battery_stats;
select * from android_battery_stats_event_slices where track_name='battery_stats.top';
"""

--> 原始数据
"""
CREATE PERFETTO VIEW android_battery_stats_event_slices (
  -- Start of a new battery state.
  ts TIMESTAMP,
  -- The duration the state was active, -1 for incomplete slices.
  dur DURATION,
  -- The same as `dur`, but extends to trace end for incomplete slices.
  safe_dur DURATION,
  -- The name of the counter track.
  track_name STRING,
  -- String value.
  str_value STRING,
  -- Int value.
  int_value LONG
) AS
WITH
  event_markers AS (
    SELECT
      ts,
      track.name AS track_name,
      str_split(slice.name, '=', 1) AS key,
      substr(slice.name, 1, 1) = '+' AS start
    FROM slice
    JOIN track
      ON slice.track_id = track.id
    WHERE
      track_name GLOB 'battery_stats.*' AND substr(slice.name, 1, 1) IN ('+', '-')
  ),
  with_neighbors AS (
    SELECT
      *,
      lag(ts) OVER (PARTITION BY track_name, key ORDER BY ts) AS last_ts,
      lead(ts) OVER (PARTITION BY track_name, key ORDER BY ts) AS next_ts
    FROM event_markers
  ),
  -- Note: query performance depends on the ability to push down filters on
  -- the track_name. It would be more clear below to have two queries and union
  -- them, but doing so prevents push down through the above window functions.
  event_spans AS (
    SELECT
      track_name,
      key,
      iif(start, ts, trace_start()) AS ts,
      iif(start, next_ts, ts) AS end_ts
    FROM with_neighbors
    -- For the majority of events, we take the `start` event and compute the dur
    -- based on next_ts. In the off chance we get an end event with no prior
    -- start (matched by the second half of this where), we can create an event
    -- starting from the beginning of the trace ending at the current event.
    WHERE
      (
        start OR last_ts IS NULL
      )
  )
SELECT
  ts,
  coalesce(end_ts - ts, -1) AS dur,
  coalesce(end_ts, trace_end()) - ts AS safe_dur,
  track_name,
  str_split(key, '"', 1) AS str_value,
  cast_int!(str_split(key, ':', 0)) AS int_value
FROM event_spans;

select * from android_battery_stats_event_slices where track_name='battery_stats.top';
"""

# Android APP Startups

# select id, ts, dur, name from (__query_slice_track__android_startups)

-->
"""
INCLUDE PERFETTO MODULE android.startup.startups;
SELECT * FROM android_startups;
"""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值