aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Zuklie <rzuklie@google.com>2023-05-15 22:01:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-05-15 22:01:19 +0000
commitf18d5dceede0c5bc68675a4fbf964b467c919511 (patch)
tree364db306011b73f4294f4bc8a0d35828a6f0ed8f
parent287c9bfb7d7107806ee430453f2e8db09fe9ed8a (diff)
parent71ce4ce705b02e608de9298748fa8ee2665ddfc1 (diff)
downloadperfetto-f18d5dceede0c5bc68675a4fbf964b467c919511.tar.gz
Merge changes I0c58b59d,Iaa57d6d5
* changes: Add a template metric for network activity query. Fix battery stats function name and consistency
-rw-r--r--Android.bp1
-rw-r--r--BUILD1
-rw-r--r--src/trace_processor/metrics/sql/android/BUILD.gn1
-rw-r--r--src/trace_processor/metrics/sql/android/network_activity_template.sql74
-rw-r--r--src/trace_processor/stdlib/android/battery_stats.sql12
-rw-r--r--test/trace_processor/diff_tests/android/android_battery_stats_state.out4
-rw-r--r--test/trace_processor/diff_tests/android/android_network_activity.out4
-rw-r--r--test/trace_processor/diff_tests/android/tests.py103
8 files changed, 194 insertions, 6 deletions
diff --git a/Android.bp b/Android.bp
index 2196b7128..91b7f78e0 100644
--- a/Android.bp
+++ b/Android.bp
@@ -10038,6 +10038,7 @@ genrule {
"src/trace_processor/metrics/sql/android/java_heap_histogram.sql",
"src/trace_processor/metrics/sql/android/java_heap_stats.sql",
"src/trace_processor/metrics/sql/android/mem_stats_priority_breakdown.sql",
+ "src/trace_processor/metrics/sql/android/network_activity_template.sql",
"src/trace_processor/metrics/sql/android/p_state.sql",
"src/trace_processor/metrics/sql/android/power_drain_in_watts.sql",
"src/trace_processor/metrics/sql/android/power_profile_data.sql",
diff --git a/BUILD b/BUILD
index 0f0551bab..195292f90 100644
--- a/BUILD
+++ b/BUILD
@@ -1787,6 +1787,7 @@ perfetto_filegroup(
"src/trace_processor/metrics/sql/android/java_heap_histogram.sql",
"src/trace_processor/metrics/sql/android/java_heap_stats.sql",
"src/trace_processor/metrics/sql/android/mem_stats_priority_breakdown.sql",
+ "src/trace_processor/metrics/sql/android/network_activity_template.sql",
"src/trace_processor/metrics/sql/android/p_state.sql",
"src/trace_processor/metrics/sql/android/power_drain_in_watts.sql",
"src/trace_processor/metrics/sql/android/power_profile_data.sql",
diff --git a/src/trace_processor/metrics/sql/android/BUILD.gn b/src/trace_processor/metrics/sql/android/BUILD.gn
index bf54d4454..a56666136 100644
--- a/src/trace_processor/metrics/sql/android/BUILD.gn
+++ b/src/trace_processor/metrics/sql/android/BUILD.gn
@@ -82,6 +82,7 @@ perfetto_sql_source_set("android") {
"java_heap_histogram.sql",
"java_heap_stats.sql",
"mem_stats_priority_breakdown.sql",
+ "network_activity_template.sql",
"p_state.sql",
"power_drain_in_watts.sql",
"power_profile_data.sql",
diff --git a/src/trace_processor/metrics/sql/android/network_activity_template.sql b/src/trace_processor/metrics/sql/android/network_activity_template.sql
new file mode 100644
index 000000000..2dcfa31a2
--- /dev/null
+++ b/src/trace_processor/metrics/sql/android/network_activity_template.sql
@@ -0,0 +1,74 @@
+--
+-- Copyright 2023 The Android Open Source Project
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+SELECT IMPORT('android.network_packets');
+
+-- Creates a view of aggregated network activity. It is common among networking
+-- to have the interface active for some time after network use. For example, in
+-- mobile networking, it is common to have the cellular interface active for 10
+-- or more seconds after the last packet was sent or received. This view takes
+-- raw packet timing and aggregates it into something that approximates the
+-- activity of the underlying interface.
+--
+-- @arg view_name The name of the output view.
+-- @arg group_by Expression to group by (set to 'null' for no grouping).
+-- @arg filter Expression on `android_network_packets` to filter by.
+-- @arg idle_ns The amount of time before considering the network idle.
+-- @arg quant_ns Quantization value, to group rows before the heavy
+-- part of the query. This should be smaller than idle_ns.
+--
+-- @column group_by The group_by columns are all present in the output.
+-- @column ts The timestamp indicating the start of the segment.
+-- @column dur The duration of the current segment.
+-- @column packet_count The total number of packets in this segment.
+-- @column packet_length The total number of bytes for packets in this segment.
+CREATE VIEW {{view_name}} AS
+WITH quantized AS (
+ SELECT
+ {{group_by}},
+ MIN(ts) AS ts,
+ MAX(ts+dur)-MIN(ts) AS dur,
+ SUM(packet_count) AS packet_count,
+ SUM(packet_length) AS packet_length
+ FROM android_network_packets
+ WHERE {{filter}}
+ GROUP BY CAST(ts / {{quant_ns}} AS INT64), {{group_by}}
+),
+with_last AS (
+ SELECT
+ *,
+ LAG(ts) OVER (
+ PARTITION BY {{group_by}}
+ ORDER BY ts
+ ) AS last_ts
+ FROM quantized
+),
+with_group AS (
+ SELECT
+ *,
+ COUNT(IIF(ts-last_ts>{{idle_ns}}, 1, null)) OVER (
+ PARTITION BY {{group_by}}
+ ORDER BY ts
+ ) AS group_id
+ FROM with_last
+)
+SELECT
+ {{group_by}},
+ MIN(ts) AS ts,
+ MAX(ts+dur)-MIN(ts)+{{idle_ns}} AS dur,
+ SUM(packet_count) AS packet_count,
+ SUM(packet_length) AS packet_length
+FROM with_group
+GROUP BY group_id, {{group_by}}
diff --git a/src/trace_processor/stdlib/android/battery_stats.sql b/src/trace_processor/stdlib/android/battery_stats.sql
index 753fd61f2..2507cb1fa 100644
--- a/src/trace_processor/stdlib/android/battery_stats.sql
+++ b/src/trace_processor/stdlib/android/battery_stats.sql
@@ -21,7 +21,7 @@ SELECT IMPORT('common.timestamps');
-- @arg value LONG The counter value.
-- @ret STRING The human-readable name for the counter value.
SELECT CREATE_FUNCTION(
- 'BATTERY_STATS_COUNTER_TO_STRING(track STRING, value LONG)',
+ 'BATTERY_STATS_COUNTER_TO_STRING(track STRING, value FLOAT)',
'STRING',
'
SELECT
@@ -125,16 +125,16 @@ SELECT CREATE_FUNCTION(
--
-- @column ts Timestamp in nanoseconds.
-- @column dur The duration the state was active.
--- @column name The name of the counter track.
+-- @column track_name The name of the counter track.
-- @column value The counter value as a number.
-- @column value_name The counter value as a human-readable string.
CREATE VIEW android_battery_stats_state AS
SELECT
ts,
- name,
- value,
- BATTERY_STATS_VALUE_TO_STRING(name, value) AS value_name,
- LEAD(ts, 1, TRACE_END()) OVER (PARTITION BY track_id ORDER BY ts) - ts AS dur
+ name AS track_name,
+ CAST(value AS INT64) AS value,
+ BATTERY_STATS_COUNTER_TO_STRING(name, value) AS value_name,
+ IFNULL(LEAD(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts, -1) AS dur
FROM counter
JOIN counter_track
ON counter.track_id = counter_track.id
diff --git a/test/trace_processor/diff_tests/android/android_battery_stats_state.out b/test/trace_processor/diff_tests/android/android_battery_stats_state.out
new file mode 100644
index 000000000..04ea9533d
--- /dev/null
+++ b/test/trace_processor/diff_tests/android/android_battery_stats_state.out
@@ -0,0 +1,4 @@
+"ts","track_name","value","value_name","dur"
+1000,"battery_stats.audio",1,"active",-1
+1000,"battery_stats.data_conn",13,"lte",3000
+4000,"battery_stats.data_conn",20,"nr",-1
diff --git a/test/trace_processor/diff_tests/android/android_network_activity.out b/test/trace_processor/diff_tests/android/android_network_activity.out
new file mode 100644
index 000000000..14418e4cd
--- /dev/null
+++ b/test/trace_processor/diff_tests/android/android_network_activity.out
@@ -0,0 +1,4 @@
+"package_name","ts","dur","packet_count","packet_length"
+"uid=123",1000,1010,2,100
+"uid=123",3000,2500,4,200
+"uid=456",1005,1010,2,300
diff --git a/test/trace_processor/diff_tests/android/tests.py b/test/trace_processor/diff_tests/android/tests.py
index cec98ae26..84bafc1d1 100644
--- a/test/trace_processor/diff_tests/android/tests.py
+++ b/test/trace_processor/diff_tests/android/tests.py
@@ -159,6 +159,109 @@ class Android(TestSuite):
""",
out=Path('android_battery_stats_event_slices.out'))
+ def test_android_battery_stats_counters(self):
+ return DiffTestBlueprint(
+ trace=TextProto(r"""
+ packet {
+ ftrace_events {
+ cpu: 1
+ event {
+ timestamp: 1000
+ pid: 1
+ print {
+ buf: "C|1000|battery_stats.data_conn|13\n"
+ }
+ }
+ event {
+ timestamp: 4000
+ pid: 1
+ print {
+ buf: "C|1000|battery_stats.data_conn|20\n"
+ }
+ }
+ event {
+ timestamp: 1000
+ pid: 1
+ print {
+ buf: "C|1000|battery_stats.audio|1\n"
+ }
+ }
+ }
+ }
+ """),
+ query="""
+ SELECT IMPORT('android.battery_stats');
+ SELECT * FROM android_battery_stats_state
+ ORDER BY ts, track_name;
+ """,
+ out=Path('android_battery_stats_state.out'))
+
+ def test_android_network_activity(self):
+ # The following should have three activity regions:
+ # * uid=123 from 1000 to 2010 (note: end is max(ts)+idle_ns)
+ # * uid=456 from 1005 to 2015 (note: doesn't group with above due to name)
+ # * uid=123 from 3000 to 5500 (note: gap between 1010 to 3000 > idle_ns)
+ # Note: packet_timestamps are delta encoded from the base timestamp.
+ return DiffTestBlueprint(
+ trace=TextProto(r"""
+ packet {
+ timestamp: 0
+ network_packet_bundle {
+ ctx {
+ direction: DIR_EGRESS
+ interface: "wlan"
+ uid: 123
+ }
+ packet_timestamps: [
+ 1000, 1010,
+ 3000, 3050, 4000, 4500
+ ],
+ packet_lengths: [
+ 50, 50,
+ 50, 50, 50, 50
+ ],
+ }
+ }
+ packet {
+ timestamp: 0
+ network_packet_bundle {
+ ctx {
+ direction: DIR_EGRESS
+ interface: "wlan"
+ uid: 456
+ }
+ packet_timestamps: [1005, 1015]
+ packet_lengths: [100, 200]
+ }
+ }
+ packet {
+ timestamp: 0
+ network_packet_bundle {
+ ctx {
+ direction: DIR_INGRESS
+ interface: "loopback"
+ uid: 123
+ }
+ packet_timestamps: [6000]
+ packet_lengths: [100]
+ }
+ }
+ """),
+ query="""
+ SELECT RUN_METRIC(
+ 'android/network_activity_template.sql',
+ 'view_name', 'android_network_activity',
+ 'group_by', 'package_name',
+ 'filter', 'iface = "wlan"',
+ 'idle_ns', '1000',
+ 'quant_ns', '100'
+ );
+
+ SELECT * FROM android_network_activity
+ ORDER BY package_name, ts;
+ """,
+ out=Path('android_network_activity.out'))
+
def test_binder_sync_binder_metrics(self):
return DiffTestBlueprint(
trace=DataPath('android_binder_metric_trace.atr'),