Skip to content

Commit

Permalink
codec_metrics: Adding power data to metric
Browse files Browse the repository at this point in the history
Bug: 361349204
Change-Id: I389cf4cc5bdd94c21a7539fdae3d28b5788fd799
  • Loading branch information
Arun Johnson committed Oct 21, 2024
1 parent 133ab6a commit b9535cc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 95 deletions.
26 changes: 17 additions & 9 deletions protos/perfetto/metrics/android/codec_metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,34 @@ message AndroidCodecMetrics {
repeated AndroidCpuMetric.CoreTypeData core_data = 5;
}

// Shows energy breakdown base on subsystem
message EnergyBreakdown {
// name of subsystem
optional string subsystem = 1;
// energy consumed by this system
optional double energy = 2;
// Rail details
message Rail {
// name of rail
optional string name = 1;
// energy and power details of this rail
message Info {
// energy from this rail for codec use
optional double energy = 1;
// power consumption in this rail for codec use
optional double power_mw = 2;
}
optional Info info = 2;
}

// have the energy usage for the codec running time
message EnergyUsage {
message Energy {
// total energy taken by the system during this time
optional double total_energy = 1;
// total time for this energy is calculated
optional int64 duration = 2;
// for this session
optional double power_mw = 3;
// enery breakdown by subsystem
repeated EnergyBreakdown subsystem = 3;
repeated Rail rail = 4;
}

repeated CpuUsage cpu_usage = 1;
repeated CodecFunction codec_function = 2;
optional EnergyUsage energy_usage = 3;
optional Energy energy = 3;

}
26 changes: 17 additions & 9 deletions protos/perfetto/metrics/perfetto_merged_metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -891,27 +891,35 @@ message AndroidCodecMetrics {
repeated AndroidCpuMetric.CoreTypeData core_data = 5;
}

// Shows energy breakdown base on subsystem
message EnergyBreakdown {
// name of subsystem
optional string subsystem = 1;
// energy consumed by this system
optional double energy = 2;
// Rail details
message Rail {
// name of rail
optional string name = 1;
// energy and power details of this rail
message Info {
// energy from this rail for codec use
optional double energy = 1;
// power consumption in this rail for codec use
optional double power_mw = 2;
}
optional Info info = 2;
}

// have the energy usage for the codec running time
message EnergyUsage {
message Energy {
// total energy taken by the system during this time
optional double total_energy = 1;
// total time for this energy is calculated
optional int64 duration = 2;
// for this session
optional double power_mw = 3;
// enery breakdown by subsystem
repeated EnergyBreakdown subsystem = 3;
repeated Rail rail = 4;
}

repeated CpuUsage cpu_usage = 1;
repeated CodecFunction codec_function = 2;
optional EnergyUsage energy_usage = 3;
optional Energy energy = 3;

}

Expand Down
26 changes: 15 additions & 11 deletions python/perfetto/trace_processor/metrics.descriptor
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ avgFreqKhze
threads ( 2(.perfetto.protos.AndroidCpuMetric.ThreadRthreads>
core ( 2*.perfetto.protos.AndroidCpuMetric.CoreDataRcoreK
core_type ( 2..perfetto.protos.AndroidCpuMetric.CoreTypeDataRcoreTypeJ
3protos/perfetto/metrics/android/codec_metrics.protoperfetto.protos0protos/perfetto/metrics/android/cpu_metric.proto"�
3protos/perfetto/metrics/android/codec_metrics.protoperfetto.protos0protos/perfetto/metrics/android/cpu_metric.proto"�
AndroidCodecMetricsJ
cpu_usage ( 2-.perfetto.protos.AndroidCodecMetrics.CpuUsageRcpuUsageY
codec_function ( 22.perfetto.protos.AndroidCodecMetrics.CodecFunctionRcodecFunctionS
energy_usage ( 20.perfetto.protos.AndroidCodecMetrics.EnergyUsageR energyUsage�
codec_function ( 22.perfetto.protos.AndroidCodecMetrics.CodecFunctionRcodecFunctionC
energy ( 2+.perfetto.protos.AndroidCodecMetrics.EnergyRenergy�
Detail
thread_name ( R
threadName
Expand All @@ -385,14 +385,18 @@ threadName"
thread_cpu_ns (R threadCpuNs
num_threads (R
numThreadsK
core_data ( 2..perfetto.protos.AndroidCpuMetric.CoreTypeDataRcoreDataJG
EnergyBreakdown
subsystem ( R subsystem
energy (Renergy�
EnergyUsage!
core_data ( 2..perfetto.protos.AndroidCpuMetric.CoreTypeDataRcoreDataJ�
Rail
name ( RnameB
info ( 2..perfetto.protos.AndroidCodecMetrics.Rail.InfoRinfo9
Info
energy (Renergy
power_mw (RpowerMw�
Energy!
total_energy (R totalEnergy
duration (RdurationR
subsystem ( 24.perfetto.protos.AndroidCodecMetrics.EnergyBreakdownR subsystem
duration (Rduration
power_mw (RpowerMw=
rail ( 2).perfetto.protos.AndroidCodecMetrics.RailRrail
�
3protos/perfetto/metrics/android/camera_metric.protoperfetto.protos"�
AndroidCameraMetricQ
Expand Down
87 changes: 22 additions & 65 deletions src/trace_processor/metrics/sql/android/codec_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ INCLUDE PERFETTO MODULE slices.with_context;
INCLUDE PERFETTO MODULE slices.cpu_time;

SELECT RUN_METRIC('android/android_cpu.sql');
SELECT RUN_METRIC('android/power_drain_in_watts.sql');
SELECT RUN_METRIC('android/android_powrails.sql');

-- Attaching thread proto with media thread name
DROP VIEW IF EXISTS core_type_proto_per_thread_name;
Expand Down Expand Up @@ -137,60 +137,15 @@ JOIN thread_slice_cpu_time ct ON(sid = ct.id)
GROUP BY codec_slice_idx, cc.thread_name, cc.process_name;

-- POWER consumed during codec use.
-- Create a map for the distinct power names.
DROP TABLE IF EXISTS power_rail_name_mapping;
CREATE PERFETTO TABLE power_rail_name_mapping AS
SELECT DISTINCT name,
ROW_NUMBER() OVER() AS idx
FROM drain_in_watts GROUP by name;

-- Extract power data for the codec running duration.
DROP TABLE IF EXISTS mapped_drain_in_watts;
CREATE PERFETTO TABLE mapped_drain_in_watts AS
WITH
start_ts AS (
SELECT MIN(ts) AS ts
FROM codec_slice_cpu_running
WHERE codec_string glob "CCodecBufferChannel::queue" || '*'
),
end_ts AS (
SELECT MAX(max_ts) as ts
FROM codec_slice_cpu_running
WHERE codec_string glob "CCodecBufferChannel::onWorkDone" || '*'
)
SELECT d.name, d.ts, dur, drain_w, idx
FROM drain_in_watts d
JOIN power_rail_name_mapping p ON (d.name = p.name)
JOIN start_ts
JOIN end_ts
WHERE d.ts >= start_ts.ts AND d.ts <= end_ts.ts;

-- Get the total energy for the time of run.
CREATE OR REPLACE PERFETTO FUNCTION get_energy_duration()
RETURNS DOUBLE AS
SELECT CAST(((MAx(ts + dur) - MIN(ts)) / 1e6) AS INT64) AS total_duration_ms
FROM mapped_drain_in_watts;

-- Get the subssytem based power breakdown
DROP TABLE IF EXISTS mapped_drain_in_watts_with_subsystem;
CREATE PERFETTO TABLE mapped_drain_in_watts_with_subsystem AS
WITH
total_duration_ms AS (
SELECT CAST(((MAx(ts + dur) - MIN(ts)) / 1e6) AS INT64) AS total_dur FROM mapped_drain_in_watts
),
total_energy AS (
SELECT cast_double!(SUM((dur * drain_w) / 1e9)) AS total_joules FROM mapped_drain_in_watts
)
DROP VIEW IF EXISTS codec_power_mw;
CREATE PERFETTO VIEW codec_power_mw AS
SELECT
SUM((dur * drain_w) / 1e9) AS joules_subsystem,
total_dur,
total_joules,
subsystem
FROM mapped_drain_in_watts
JOIN total_duration_ms
JOIN total_energy
JOIN power_counters USING(name)
GROUP BY subsystem;
AndroidCodecMetrics_Rail_Info (
'energy', tot_used_power,
'power_mw', tot_used_power / (powrail_end_ts - powrail_start_ts)
) AS proto,
name
FROM avg_used_powers;

-- Generate proto for the trace
DROP VIEW IF EXISTS metrics_per_slice_type;
Expand All @@ -209,7 +164,7 @@ FROM codec_slice_cpu_running;
-- Generating codec framework cpu metric
DROP VIEW IF EXISTS codec_metrics_output;
CREATE PERFETTO VIEW codec_metrics_output AS
SELECT AndroidCodecMetrics(
SELECT AndroidCodecMetrics (
'cpu_usage', (
SELECT RepeatedField(
AndroidCodecMetrics_CpuUsage(
Expand All @@ -229,17 +184,19 @@ SELECT AndroidCodecMetrics(
)
) FROM metrics_per_slice_type
),
'energy_usage',
AndroidCodecMetrics_EnergyUsage(
'total_energy', (SELECT total_joules FROM mapped_drain_in_watts_with_subsystem),
'duration', (SELECT total_dur FROM mapped_drain_in_watts_with_subsystem),
'subsystem', (
'energy', (
AndroidCodecMetrics_Energy(
'total_energy', (SELECT SUM(tot_used_power) FROM avg_used_powers),
'duration', (SELECT MAX(powrail_end_ts) - MIN(powrail_start_ts) FROM avg_used_powers),
'power_mw', (SELECT SUM(tot_used_power) / (MAX(powrail_end_ts) - MIN(powrail_start_ts)) FROM avg_used_powers),
'rail', (
SELECT RepeatedField (
AndroidCodecMetrics_EnergyBreakdown (
'subsystem', subsystem,
'energy', CAST((joules_subsystem) AS DOUBLE)
AndroidCodecMetrics_Rail (
'name', name,
'info', codec_power_mw.proto
)
) FROM mapped_drain_in_watts_with_subsystem
)
) FROM codec_power_mw
)
)
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ codec_metrics {
running_cpu_ns: 17917404
}
}
energy_usage {
energy {
}
}

0 comments on commit b9535cc

Please sign in to comment.