Skip to content

Commit

Permalink
Merge "stdlib: Add Duration type" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aMayzner authored and Gerrit Code Review committed Nov 22, 2024
2 parents 56a2514 + d007277 commit 14aebfb
Show file tree
Hide file tree
Showing 77 changed files with 374 additions and 353 deletions.
10 changes: 10 additions & 0 deletions include/perfetto/ext/base/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <algorithm>
#include <string>
#include <vector>

#include "perfetto/base/build_config.h"
#include "perfetto/base/logging.h"
Expand Down Expand Up @@ -120,6 +121,15 @@ class StringView {
#endif
}

bool CaseInsensitiveOneOf(const std::vector<StringView>& others) const {
for (const StringView& other : others) {
if (CaseInsensitiveEq(other)) {
return true;
}
}
return false;
}

bool StartsWith(const StringView& other) const {
if (other.size() == 0)
return true;
Expand Down
3 changes: 2 additions & 1 deletion python/generators/sql_processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
'BYTES',

# Special types
'TIMESTAMP'
'TIMESTAMP',
'DURATION'
]

MACRO_ARG_TYPES = ['TABLEORSUBQUERY', 'EXPR', 'COLUMNNAME']
Expand Down
4 changes: 4 additions & 0 deletions src/base/string_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ TEST(StringViewTest, BasicCases) {
EXPECT_FALSE(x.CaseInsensitiveEq("ab"));
EXPECT_FALSE(x.CaseInsensitiveEq("abcd"));
EXPECT_FALSE(x.CaseInsensitiveEq(""));
EXPECT_FALSE(x.CaseInsensitiveOneOf({}));
EXPECT_FALSE(x.CaseInsensitiveOneOf({"AbCd", "ab", "abcd"}));
EXPECT_TRUE(x.CaseInsensitiveOneOf({"aBc", "AbC"}));
EXPECT_TRUE(x.CaseInsensitiveOneOf({"AbCd", "aBc"}));
}

// Test find(char).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ CREATE PERFETTO TABLE android_app_process_starts(
-- Timestamp the process start was dispatched from system_server.
proc_start_ts TIMESTAMP,
-- Duration to dispatch the process start from system_server.
proc_start_dur LONG,
proc_start_dur DURATION,
-- Timestamp the bindApplication started in the app.
bind_app_ts TIMESTAMP,
-- Duration to complete bindApplication in the app.
bind_app_dur LONG,
bind_app_dur DURATION,
-- Timestamp the Intent was received in the app.
intent_ts TIMESTAMP,
-- Duration to handle intent in the app.
intent_dur LONG,
intent_dur DURATION,
-- Total duration from proc_start dispatched to intent completed.
total_dur LONG
) AS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE PERFETTO TABLE android_charging_states(
-- Timestamp at which the device charging state began.
ts TIMESTAMP,
-- Duration of the device charging state.
dur LONG,
dur DURATION,
-- Device charging state, one of: Charging, Discharging, Not charging
-- (when the charger is present but battery is not charging),
-- Full, Unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ SELECT
-- by BatteryStats as a bitmap where each 'category' has a unique value at any
-- given time.
CREATE PERFETTO VIEW android_battery_stats_state(
-- Timestamp in nanoseconds.
-- Start of the new barrary state.
ts TIMESTAMP,
-- The duration the state was active, may be negative for incomplete slices.
dur LONG,
-- 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 LONG,
safe_dur DURATION,
-- The name of the counter track.
track_name STRING,
-- The counter value as a number.
Expand Down Expand Up @@ -161,12 +161,12 @@ WHERE counter_track.name GLOB 'battery_stats.*';
-- str_value='com.google.android.apps.nexuslauncher'
-- int_value=10215
CREATE PERFETTO VIEW android_battery_stats_event_slices(
-- Timestamp in nanoseconds.
-- Start of a new battery state.
ts TIMESTAMP,
-- The duration the state was active, may be negative for incomplete slices.
dur LONG,
-- 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 LONG,
safe_dur DURATION,
-- The name of the counter track.
track_name STRING,
-- String value.
Expand Down
14 changes: 7 additions & 7 deletions src/trace_processor/perfetto_sql/stdlib/android/binder.sql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ CREATE PERFETTO VIEW android_sync_binder_thread_state_by_txn(
-- a thread_state that occurred in the txn
thread_state STRING,
-- aggregated dur of the |thread_state| in the txn
thread_state_dur LONG,
thread_state_dur DURATION,
-- aggregated count of the |thread_state| in the txn
thread_state_count LONG
) AS
Expand Down Expand Up @@ -285,7 +285,7 @@ CREATE PERFETTO VIEW android_sync_binder_blocked_functions_by_txn(
-- blocked kernel function in a thread state
blocked_function STRING,
-- aggregated dur of the |blocked_function| in the txn
blocked_function_dur LONG,
blocked_function_dur DURATION,
-- aggregated count of the |blocked_function| in the txn
blocked_function_count LONG
) AS
Expand Down Expand Up @@ -405,7 +405,7 @@ CREATE PERFETTO TABLE android_binder_txns(
-- Timestamp the binder interface name was emitted. Proxy to 'ts' and 'dur' for async txns.
aidl_ts TIMESTAMP,
-- Duration of the binder interface name. Proxy to 'ts' and 'dur' for async txns.
aidl_dur LONG,
aidl_dur DURATION,
-- slice id of the binder txn.
binder_txn_id LONG,
-- name of the client process.
Expand All @@ -425,7 +425,7 @@ CREATE PERFETTO TABLE android_binder_txns(
-- timestamp of the client txn.
client_ts TIMESTAMP,
-- wall clock dur of the client txn.
client_dur LONG,
client_dur DURATION,
-- slice id of the binder reply.
binder_reply_id LONG,
-- name of the server process.
Expand All @@ -443,17 +443,17 @@ CREATE PERFETTO TABLE android_binder_txns(
-- timestamp of the server txn.
server_ts TIMESTAMP,
-- wall clock dur of the server txn.
server_dur LONG,
server_dur DURATION,
-- oom score of the client process at the start of the txn.
client_oom_score LONG,
-- oom score of the server process at the start of the reply.
server_oom_score LONG,
-- whether the txn is synchronous or async (oneway).
is_sync BOOL,
-- monotonic clock dur of the client txn.
client_monotonic_dur LONG,
client_monotonic_dur DURATION,
-- monotonic clock dur of the server txn.
server_monotonic_dur LONG,
server_monotonic_dur DURATION,
-- Client package version_code.
client_package_version_code LONG,
-- Server package version_code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ CREATE PERFETTO TABLE android_binder_server_breakdown(
-- Timestamp of an exclusive interval during the binder reply with a single reason.
ts TIMESTAMP,
-- Duration of an exclusive interval during the binder reply with a single reason.
dur LONG,
dur DURATION,
-- Cause of delay during an exclusive interval of the binder reply.
reason STRING
)
Expand All @@ -198,7 +198,7 @@ CREATE PERFETTO TABLE android_binder_client_breakdown(
-- Timestamp of an exclusive interval during the binder txn with a single latency reason.
ts TIMESTAMP,
-- Duration of an exclusive interval during the binder txn with a single latency reason.
dur LONG,
dur DURATION,
-- Cause of delay during an exclusive interval of the binder txn.
reason STRING
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CREATE PERFETTO TABLE _android_broadcasts_minsdk_u(
-- Timestamp the broadcast was dispatched.
ts TIMESTAMP,
-- Duration to dispatch the broadcast.
dur LONG,
dur DURATION,
-- Track id the broadcast was dispatched from.
track_id LONG
) AS
Expand Down
24 changes: 12 additions & 12 deletions src/trace_processor/perfetto_sql/stdlib/android/desktop_mode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ include perfetto module android.statsd;

-- Desktop Windows with durations they were open.
CREATE PERFETTO TABLE android_desktop_mode_windows (
-- Window add timestamp; NULL if no add event in the trace.
raw_add_ts TIMESTAMP,
-- Window remove timestamp; NULL if no remove event in the trace.
raw_remove_ts TIMESTAMP,
-- timestamp that the window was added; or trace_start() if no add event in the trace.
ts TIMESTAMP,
-- duration the window was open; or until trace_end() if no remove event in the trace.
dur LONG,
-- Desktop Window instance ID - unique per window.
instance_id LONG,
-- UID of the app running in the window.
uid LONG
-- Window add timestamp; NULL if no add event in the trace.
raw_add_ts TIMESTAMP,
-- Window remove timestamp; NULL if no remove event in the trace.
raw_remove_ts TIMESTAMP,
-- Timestamp that the window was added; or trace_start() if no add event in the trace.
ts TIMESTAMP,
-- Furation the window was open; or until trace_end() if no remove event in the trace.
dur DURATION,
-- Desktop Window instance ID - unique per window.
instance_id LONG,
-- UID of the app running in the window.
uid LONG
) AS
WITH
atoms AS (
Expand Down
6 changes: 3 additions & 3 deletions src/trace_processor/perfetto_sql/stdlib/android/dvfs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE PERFETTO VIEW android_dvfs_counters(
-- Counter value.
value DOUBLE,
-- Counter duration.
dur LONG
dur DURATION
) AS
SELECT
counter_track.name,
Expand Down Expand Up @@ -72,7 +72,7 @@ CREATE PERFETTO TABLE android_dvfs_counter_stats(
-- Min of all counter values for the counter name.
min DOUBLE,
-- Duration between the first and last counter value for the counter name.
dur LONG,
dur DURATION,
-- Weighted avergate of all the counter values for the counter name.
wgt_avg DOUBLE
) AS
Expand All @@ -94,7 +94,7 @@ CREATE PERFETTO VIEW android_dvfs_counter_residency(
-- Counter value.
value DOUBLE,
-- Counter duration.
dur LONG,
dur DURATION,
-- Counter duration as a percentage of total duration.
pct DOUBLE
) AS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ CREATE PERFETTO TABLE android_cpu_time_per_frame(
-- `Choreographer#doFrame`. See `android_app_vsync_delay_per_frame` table for more details.
app_vsync_delay LONG,
-- Duration of `Choreographer#doFrame` slice.
do_frame_dur LONG,
do_frame_dur DURATION,
-- Duration of `DrawFrame` slice. Summed duration of all `DrawFrame`
-- slices, if more than one. See `android_frames_draw_frame` for more details.
draw_frame_dur LONG,
draw_frame_dur DURATION,
-- CPU time across the UI Thread + RenderThread.
cpu_time LONG
) AS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ CREATE PERFETTO TABLE android_frames(
-- Duration of the frame, as defined by the duration of the corresponding
-- `actual_frame_timeline_slice` or, if not present the time between the
-- `ts` and the end of the final `DrawFrame`.
dur LONG,
dur DURATION,
-- `slice.id` of "Choreographer#doFrame" slice.
do_frame_id LONG,
-- `slice.id` of "DrawFrame" slice.
Expand Down Expand Up @@ -221,7 +221,7 @@ RETURNS TABLE (
-- Start of the frame, the timestamp of the "Choreographer#doFrame" slice.
ts TIMESTAMP,
-- Duration of the frame.
dur LONG,
dur DURATION,
-- `slice.id` of "Choreographer#doFrame" slice.
do_frame_id LONG,
-- `slice.id` of "DrawFrame" slice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CREATE PERFETTO TABLE _frames_maxsdk_28(
ts TIMESTAMP,
-- Duration of the frame, defined as the duration until the last
-- "DrawFrame" of this frame finishes.
dur LONG,
dur DURATION,
-- `slice.id` of "Choreographer#doFrame" slice.
do_frame_id LONG,
-- `slice.id` of "DrawFrame" slice. Fetched as one of the "DrawFrame"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CREATE PERFETTO TABLE android_freezer_events (
-- Timestamp process was frozen.
ts TIMESTAMP,
-- Duration process was frozen for.
dur LONG,
dur DURATION,
-- Unfreeze reason Integer.
unfreeze_reason_int LONG,
-- Unfreeze reason String.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ CREATE PERFETTO TABLE android_garbage_collection_events (
-- Garbage collection timestamp.
gc_ts TIMESTAMP,
-- Garbage collection wall duration.
gc_dur LONG,
gc_dur DURATION,
-- Garbage collection duration spent executing on CPU.
gc_running_dur LONG,
gc_running_dur DURATION,
-- Garbage collection duration spent waiting for CPU.
gc_runnable_dur LONG,
gc_runnable_dur DURATION,
-- Garbage collection duration spent waiting in the Linux kernel on IO.
gc_unint_io_dur LONG,
gc_unint_io_dur DURATION,
-- Garbage collection duration spent waiting in the Linux kernel without IO.
gc_unint_non_io_dur LONG,
gc_unint_non_io_dur DURATION,
-- Garbage collection duration spent waiting in interruptible sleep.
gc_int_dur LONG
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CREATE PERFETTO TABLE android_gpu_frequency(
-- Timestamp
ts TIMESTAMP,
-- Duration
dur LONG,
dur DURATION,
-- GPU id. Joinable with `gpu_counter_track.gpu_id`.
gpu_id LONG,
-- GPU frequency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE PERFETTO TABLE android_gpu_memory_per_process(
-- Timestamp
ts TIMESTAMP,
-- Duration
dur LONG,
dur DURATION,
-- Upid of the process
upid LONG,
-- GPU memory
Expand Down
14 changes: 7 additions & 7 deletions src/trace_processor/perfetto_sql/stdlib/android/input.sql
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ JOIN _input_read_time
-- 4. Input ACk event received in OS.
CREATE PERFETTO TABLE android_input_events (
-- Duration from input dispatch to input received.
dispatch_latency_dur LONG,
dispatch_latency_dur DURATION,
-- Duration from input received to input ACK sent.
handling_latency_dur LONG,
handling_latency_dur DURATION,
-- Duration from input ACK sent to input ACK recieved.
ack_latency_dur LONG,
ack_latency_dur DURATION,
-- Duration from input dispatch to input event ACK received.
total_latency_dur LONG,
total_latency_dur DURATION,
-- Duration from input read to frame present time. Null if an input event has no associated frame event.
end_to_end_latency_dur LONG,
end_to_end_latency_dur DURATION,
-- Tid of thread receiving the input event.
tid LONG,
-- Name of thread receiving the input event.
Expand All @@ -214,13 +214,13 @@ CREATE PERFETTO TABLE android_input_events (
-- Timestamp input event was dispatched.
dispatch_ts TIMESTAMP,
-- Duration of input event dispatch.
dispatch_dur LONG,
dispatch_dur DURATION,
-- Thread track id of input event receiving thread.
receive_track_id LONG,
-- Timestamp input event was received.
receive_ts TIMESTAMP,
-- Duration of input event receipt.
receive_dur LONG,
receive_dur DURATION,
-- Vsync Id associated with the input. Null if an input event has no associated frame event.
frame_id LONG
)
Expand Down
2 changes: 1 addition & 1 deletion src/trace_processor/perfetto_sql/stdlib/android/io.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CREATE PERFETTO VIEW _android_io_f2fs_counter_stats(
-- Min of all counter values for the counter name.
min DOUBLE,
-- Duration between the first and last counter value for the counter name.
dur LONG,
dur DURATION,
-- Count of all the counter values for the counter name.
count LONG,
-- Avergate of all the counter values for the counter name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CREATE PERFETTO TABLE android_job_scheduler_events (
-- Timestamp the job was scheduled.
ts TIMESTAMP,
-- Duration of the scheduled job.
dur LONG
dur DURATION
) AS
SELECT
cast_int!(STR_SPLIT(slice.name, '#', 1)) AS job_id,
Expand Down
Loading

0 comments on commit 14aebfb

Please sign in to comment.