diff --git a/protos/perfetto/metrics/android/codec_metrics.proto b/protos/perfetto/metrics/android/codec_metrics.proto index c4e71523ba..b95dbe6985 100644 --- a/protos/perfetto/metrics/android/codec_metrics.proto +++ b/protos/perfetto/metrics/android/codec_metrics.proto @@ -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; } diff --git a/protos/perfetto/metrics/perfetto_merged_metrics.proto b/protos/perfetto/metrics/perfetto_merged_metrics.proto index 8998f37072..1d9b2199f5 100644 --- a/protos/perfetto/metrics/perfetto_merged_metrics.proto +++ b/protos/perfetto/metrics/perfetto_merged_metrics.proto @@ -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; } diff --git a/python/perfetto/trace_processor/metrics.descriptor b/python/perfetto/trace_processor/metrics.descriptor index 8fc226f4e4..672894e1a4 100644 --- a/python/perfetto/trace_processor/metrics.descriptor +++ b/python/perfetto/trace_processor/metrics.descriptor @@ -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.CodecFunctionR codecFunctionS - energy_usage ( 20.perfetto.protos.AndroidCodecMetrics.EnergyUsageR energyUsage +codec_function ( 22.perfetto.protos.AndroidCodecMetrics.CodecFunctionR codecFunctionC +energy ( 2+.perfetto.protos.AndroidCodecMetrics.EnergyRenergy Detail thread_name ( R threadName @@ -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 diff --git a/src/trace_processor/metrics/sql/android/codec_metrics.sql b/src/trace_processor/metrics/sql/android/codec_metrics.sql index 176908bfb5..21ab8593ee 100644 --- a/src/trace_processor/metrics/sql/android/codec_metrics.sql +++ b/src/trace_processor/metrics/sql/android/codec_metrics.sql @@ -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; @@ -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; @@ -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( @@ -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 + ) + ) ) ); diff --git a/test/trace_processor/diff_tests/metrics/codecs/codec-framedecoder-trace.out b/test/trace_processor/diff_tests/metrics/codecs/codec-framedecoder-trace.out index 1e0ed933a1..2873b57b70 100644 --- a/test/trace_processor/diff_tests/metrics/codecs/codec-framedecoder-trace.out +++ b/test/trace_processor/diff_tests/metrics/codecs/codec-framedecoder-trace.out @@ -81,6 +81,6 @@ codec_metrics { running_cpu_ns: 17917404 } } - energy_usage { + energy { } }