欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 游戏 > PerfettoSQL

PerfettoSQL

2025/4/27 1:51:28 来源:https://blog.csdn.net/weixin_41693437/article/details/147427676  浏览:    关键词: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
WITHevent_markers AS (SELECTts,track.name AS track_name,str_split(slice.name, '=', 1) AS key,substr(slice.name, 1, 1) = '+' AS startFROM sliceJOIN trackON slice.track_id = track.idWHEREtrack_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_tsFROM 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 (SELECTtrack_name,key,iif(start, ts, trace_start()) AS ts,iif(start, next_ts, ts) AS end_tsFROM 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))
SELECTts,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;
"""

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词