Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7f17fb8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Telephony power metrics"

parents 24f2a954 a6a24806
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -44,6 +44,9 @@ message TelephonyLog {


  // The end time of this log
  // The end time of this log
  optional Time end_time = 7;
  optional Time end_time = 7;

  // Modem power stats
  optional ModemPowerStats modem_power_stats = 8;
}
}


// The time information
// The time information
@@ -1434,3 +1437,35 @@ message SmsSession {
  // Indicating some sms session events are dropped
  // Indicating some sms session events are dropped
  optional bool events_dropped = 4;
  optional bool events_dropped = 4;
}
}

// Power stats for modem
message ModemPowerStats {

  // Duration of log (ms). This is the duration of time device is
  // on battery and modem power stats are collected.
  optional int64 logging_duration_ms = 1;

  // Energy consumed by modem (mAh)
  optional double energy_consumed_mah = 2;

  // Number of packets sent (tx)
  optional int64 num_packets_tx = 3;

  // Amount of time kernel is active because of cellular data (ms)
  optional int64 cellular_kernel_active_time_ms = 4;

  // Amount of time spent in very poor rx signal level (ms)
  optional int64 time_in_very_poor_rx_signal_level_ms = 5;

  // Amount of time modem is in sleep (ms)
  optional int64 sleep_time_ms = 6;

  // Amount of time modem is in idle (ms)
  optional int64 idle_time_ms = 7;

  // Amount of time modem is in rx (ms)
  optional int64 rx_time_ms = 8;

  // Amount of time modem is in tx (ms)
  repeated int64 tx_time_ms = 9;
}
+81 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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
 *
 *      http://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.
 */
package com.android.internal.telephony.metrics;

import android.os.BatteryStats;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.connectivity.CellularBatteryStats;
import android.text.format.DateUtils;

import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats;

/**
 * ModemPowerMetrics holds the modem power metrics and converts them to ModemPowerStats proto buf.
 * This proto buf is included in the Telephony proto buf.
 */
public class ModemPowerMetrics {

    /* BatteryStats API */
    private final IBatteryStats mBatteryStats;

    public ModemPowerMetrics() {
        mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService(
            BatteryStats.SERVICE_NAME));
    }

    /**
     * Build ModemPowerStats proto
     * @return ModemPowerStats
     */
    public ModemPowerStats buildProto() {
        ModemPowerStats m = new ModemPowerStats();
        CellularBatteryStats stats = getStats();
        if (stats != null) {
            m.loggingDurationMs = stats.getLoggingDurationMs();
            m.energyConsumedMah = stats.getEnergyConsumedMaMs()
                / ((double) DateUtils.HOUR_IN_MILLIS);
            m.numPacketsTx = stats.getNumPacketsTx();
            m.cellularKernelActiveTimeMs = stats.getKernelActiveTimeMs();
            if (stats.getTimeInRxSignalStrengthLevelMs() != null
                && stats.getTimeInRxSignalStrengthLevelMs().length > 0) {
                m.timeInVeryPoorRxSignalLevelMs = stats.getTimeInRxSignalStrengthLevelMs()[0];
            }
            m.sleepTimeMs = stats.getSleepTimeMs();
            m.idleTimeMs = stats.getIdleTimeMs();
            m.rxTimeMs = stats.getRxTimeMs();
            long[] t = stats.getTxTimeMs();
            m.txTimeMs = new long[t.length];
            for (int i = 0; i < t.length; i++) {
                m.txTimeMs[i] = t[i];
            }
        }
        return m;
    }

    /**
     * Get cellular stats from batterystats
     * @return CellularBatteryStats
     */
    private CellularBatteryStats getStats() {
        try {
            return mBatteryStats.getCellularBatteryStats();
        } catch (RemoteException e) {
        }
        return null;
    }
}
+20 −1
Original line number Original line Diff line number Diff line
@@ -77,6 +77,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetu
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCallResponse
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.RilSetupDataCallResponse
        .RilDataCallFailCause;
        .RilDataCallFailCause;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyLog;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyLog;
import com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyServiceState;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyServiceState;
import com.android.internal.telephony.nano.TelephonyProto.TelephonySettings;
import com.android.internal.telephony.nano.TelephonyProto.TelephonySettings;
import com.android.internal.telephony.nano.TelephonyProto.TimeInterval;
import com.android.internal.telephony.nano.TelephonyProto.TimeInterval;
@@ -413,6 +414,21 @@ public class TelephonyMetrics {
        }
        }


        pw.decreaseIndent();
        pw.decreaseIndent();
        pw.println("Modem power stats:");
        pw.increaseIndent();
        ModemPowerStats s = new ModemPowerMetrics().buildProto();
        pw.println("Power log duration (battery time) (ms): " + s.loggingDurationMs);
        pw.println("Energy consumed by modem (mAh): " + s.energyConsumedMah);
        pw.println("Number of packets sent (tx): " + s.numPacketsTx);
        pw.println("Amount of time kernel is active because of cellular data (ms): " +
            s.cellularKernelActiveTimeMs);
        pw.println("Amount of time spent in very poor rx signal level (ms): " +
            s.timeInVeryPoorRxSignalLevelMs);
        pw.println("Amount of time modem is in sleep (ms): " + s.sleepTimeMs);
        pw.println("Amount of time modem is in idle (ms): " + s.idleTimeMs);
        pw.println("Amount of time modem is in rx (ms): " + s.rxTimeMs);
        pw.println("Amount of time modem is in tx (ms): " + Arrays.toString(s.txTimeMs));
        pw.decreaseIndent();
    }
    }


    /**
    /**
@@ -506,6 +522,9 @@ public class TelephonyMetrics {
            histogramProto.bucketCounters = rilHistogram.getBucketCounters();
            histogramProto.bucketCounters = rilHistogram.getBucketCounters();
        }
        }


        // Build modem power metrics
        log.modemPowerStats = new ModemPowerMetrics().buildProto();

        // Log the starting system time
        // Log the starting system time
        log.startTime = new TelephonyProto.Time();
        log.startTime = new TelephonyProto.Time();
        log.startTime.systemTimestampMillis = mStartSystemTimeMs;
        log.startTime.systemTimestampMillis = mStartSystemTimeMs;