Search in sources :

Example 1 with ModemPowerStats

use of com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyMetrics method printAllMetrics.

/**
 * Print all metrics data for debugging purposes
 *
 * @param rawWriter Print writer
 */
private synchronized void printAllMetrics(PrintWriter rawWriter) {
    final IndentingPrintWriter pw = new IndentingPrintWriter(rawWriter, "  ");
    pw.println("Telephony metrics proto:");
    pw.println("------------------------------------------");
    pw.println("Telephony events:");
    pw.increaseIndent();
    for (TelephonyEvent event : mTelephonyEvents) {
        pw.print(event.timestampMillis);
        pw.print(" [");
        pw.print(event.phoneId);
        pw.print("] ");
        pw.print("T=");
        if (event.type == TelephonyEvent.Type.RIL_SERVICE_STATE_CHANGED) {
            pw.print(telephonyEventToString(event.type) + "(" + "Data RAT " + event.serviceState.dataRat + " Voice RAT " + event.serviceState.voiceRat + " Channel Number " + event.serviceState.channelNumber + " NR Frequency Range " + event.serviceState.nrFrequencyRange + " NR State " + event.serviceState.nrState + ")");
            for (int i = 0; i < event.serviceState.networkRegistrationInfo.length; i++) {
                pw.print("reg info: domain=" + event.serviceState.networkRegistrationInfo[i].domain + ", rat=" + event.serviceState.networkRegistrationInfo[i].rat);
            }
        } else {
            pw.print(telephonyEventToString(event.type));
        }
        pw.println("");
    }
    pw.decreaseIndent();
    pw.println("Call sessions:");
    pw.increaseIndent();
    for (TelephonyCallSession callSession : mCompletedCallSessions) {
        pw.print("Start time in minutes: " + callSession.startTimeMinutes);
        pw.print(", phone: " + callSession.phoneId);
        if (callSession.eventsDropped) {
            pw.println(" Events dropped: " + callSession.eventsDropped);
        }
        pw.println(" Events: ");
        pw.increaseIndent();
        for (TelephonyCallSession.Event event : callSession.events) {
            pw.print(event.delay);
            pw.print(" T=");
            if (event.type == TelephonyCallSession.Event.Type.RIL_SERVICE_STATE_CHANGED) {
                pw.println(callSessionEventToString(event.type) + "(" + "Data RAT " + event.serviceState.dataRat + " Voice RAT " + event.serviceState.voiceRat + " Channel Number " + event.serviceState.channelNumber + " NR Frequency Range " + event.serviceState.nrFrequencyRange + " NR State " + event.serviceState.nrState + ")");
            } else if (event.type == TelephonyCallSession.Event.Type.RIL_CALL_LIST_CHANGED) {
                pw.println(callSessionEventToString(event.type));
                pw.increaseIndent();
                for (RilCall call : event.calls) {
                    pw.println(call.index + ". Type = " + call.type + " State = " + call.state + " End Reason " + call.callEndReason + " Precise Disconnect Cause " + call.preciseDisconnectCause + " isMultiparty = " + call.isMultiparty);
                }
                pw.decreaseIndent();
            } else if (event.type == TelephonyCallSession.Event.Type.AUDIO_CODEC) {
                pw.println(callSessionEventToString(event.type) + "(" + event.audioCodec + ")");
            } else {
                pw.println(callSessionEventToString(event.type));
            }
        }
        pw.decreaseIndent();
    }
    pw.decreaseIndent();
    pw.println("Sms sessions:");
    pw.increaseIndent();
    int count = 0;
    for (SmsSession smsSession : mCompletedSmsSessions) {
        count++;
        pw.print("[" + count + "] Start time in minutes: " + smsSession.startTimeMinutes);
        pw.print(", phone: " + smsSession.phoneId);
        if (smsSession.eventsDropped) {
            pw.println(", events dropped: " + smsSession.eventsDropped);
        } else {
            pw.println("");
        }
        pw.println("Events: ");
        pw.increaseIndent();
        for (SmsSession.Event event : smsSession.events) {
            pw.print(event.delay);
            pw.print(" T=");
            pw.println(smsSessionEventToString(event.type));
            // Only show more info for tx/rx sms
            if (event.type == SmsSession.Event.Type.SMS_RECEIVED) {
                pw.increaseIndent();
                switch(event.smsType) {
                    case SmsSession.Event.SmsType.SMS_TYPE_SMS_PP:
                        pw.println("Type: SMS-PP");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_VOICEMAIL_INDICATION:
                        pw.println("Type: Voicemail indication");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_ZERO:
                        pw.println("Type: zero");
                        break;
                    case SmsSession.Event.SmsType.SMS_TYPE_WAP_PUSH:
                        pw.println("Type: WAP PUSH");
                        break;
                    default:
                        break;
                }
                if (event.errorCode != SmsManager.RESULT_ERROR_NONE) {
                    pw.println("E=" + event.errorCode);
                }
                pw.decreaseIndent();
            } else if (event.type == SmsSession.Event.Type.SMS_SEND || event.type == SmsSession.Event.Type.SMS_SEND_RESULT) {
                pw.increaseIndent();
                pw.println("ReqId=" + event.rilRequestId);
                pw.println("E=" + event.errorCode);
                pw.println("RilE=" + event.error);
                pw.println("ImsE=" + event.imsError);
                pw.decreaseIndent();
            } else if (event.type == SmsSession.Event.Type.INCOMPLETE_SMS_RECEIVED) {
                pw.increaseIndent();
                pw.println("Received: " + event.incompleteSms.receivedParts + "/" + event.incompleteSms.totalParts);
                pw.decreaseIndent();
            }
        }
        pw.decreaseIndent();
    }
    pw.decreaseIndent();
    pw.println("Modem power stats:");
    pw.increaseIndent();
    BatteryStatsManager batteryStatsManager = mContext == null ? null : (BatteryStatsManager) mContext.getSystemService(Context.BATTERY_STATS_SERVICE);
    ModemPowerStats s = new ModemPowerMetrics(batteryStatsManager).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("Number of bytes sent (tx): " + s.numBytesTx);
    pw.println("Number of packets received (rx): " + s.numPacketsRx);
    pw.println("Number of bytes received (rx): " + s.numBytesRx);
    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.println("Amount of time phone spent in various Radio Access Technologies (ms): " + Arrays.toString(s.timeInRatMs));
    pw.println("Amount of time phone spent in various cellular " + "rx signal strength levels (ms): " + Arrays.toString(s.timeInRxSignalStrengthLevelMs));
    pw.println("Energy consumed across measured modem rails (mAh): " + new DecimalFormat("#.##").format(s.monitoredRailEnergyConsumedMah));
    pw.decreaseIndent();
    pw.println("Hardware Version: " + SystemProperties.get("ro.boot.revision", ""));
}
Also used : TelephonyEvent(com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent) DecimalFormat(java.text.DecimalFormat) TelephonyCallSession(com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession) BatteryStatsManager(android.os.BatteryStatsManager) ModemPowerStats(com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter) RilCall(com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.RilCall) SmsSession(com.android.internal.telephony.nano.TelephonyProto.SmsSession)

Example 2 with ModemPowerStats

use of com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats in project android_frameworks_opt_telephony by LineageOS.

the class ModemPowerMetrics method buildProto.

/**
 * Build ModemPowerStats proto
 * @return ModemPowerStats
 */
public ModemPowerStats buildProto() {
    ModemPowerStats m = new ModemPowerStats();
    CellularBatteryStats stats = getStats();
    if (stats != null) {
        m.loggingDurationMs = stats.getLoggingDurationMillis();
        m.energyConsumedMah = stats.getEnergyConsumedMaMillis() / ((double) DateUtils.HOUR_IN_MILLIS);
        m.numPacketsTx = stats.getNumPacketsTx();
        m.cellularKernelActiveTimeMs = stats.getKernelActiveTimeMillis();
        long timeInVeryPoorRxSignalLevelMs = stats.getTimeInRxSignalStrengthLevelMicros(CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
        if (timeInVeryPoorRxSignalLevelMs >= 0) {
            m.timeInVeryPoorRxSignalLevelMs = timeInVeryPoorRxSignalLevelMs;
        }
        m.sleepTimeMs = stats.getSleepTimeMillis();
        m.idleTimeMs = stats.getIdleTimeMillis();
        m.rxTimeMs = stats.getRxTimeMillis();
        List<Long> txTimeMillis = new ArrayList<>();
        for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) {
            long t = stats.getTxTimeMillis(i);
            if (t >= 0) {
                txTimeMillis.add(t);
            }
        }
        m.txTimeMs = txTimeMillis.stream().mapToLong(Long::longValue).toArray();
        m.numBytesTx = stats.getNumBytesTx();
        m.numPacketsRx = stats.getNumPacketsRx();
        m.numBytesRx = stats.getNumBytesRx();
        List<Long> timeInRatMicros = new ArrayList<>();
        for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; i++) {
            long tr = stats.getTimeInRatMicros(i);
            if (tr >= 0) {
                timeInRatMicros.add(tr);
            }
        }
        m.timeInRatMs = timeInRatMicros.stream().mapToLong(Long::longValue).toArray();
        List<Long> rxSignalStrengthLevelMicros = new ArrayList<>();
        for (int i = 0; i < CellSignalStrength.getNumSignalStrengthLevels(); i++) {
            long rx = stats.getTimeInRxSignalStrengthLevelMicros(i);
            if (rx >= 0) {
                rxSignalStrengthLevelMicros.add(rx);
            }
        }
        m.timeInRxSignalStrengthLevelMs = rxSignalStrengthLevelMicros.stream().mapToLong(Long::longValue).toArray();
        m.monitoredRailEnergyConsumedMah = stats.getMonitoredRailChargeConsumedMaMillis() / ((double) DateUtils.HOUR_IN_MILLIS);
    }
    return m;
}
Also used : ArrayList(java.util.ArrayList) ModemPowerStats(com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats) CellularBatteryStats(android.os.connectivity.CellularBatteryStats)

Aggregations

ModemPowerStats (com.android.internal.telephony.nano.TelephonyProto.ModemPowerStats)2 BatteryStatsManager (android.os.BatteryStatsManager)1 CellularBatteryStats (android.os.connectivity.CellularBatteryStats)1 SmsSession (com.android.internal.telephony.nano.TelephonyProto.SmsSession)1 TelephonyCallSession (com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession)1 RilCall (com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.RilCall)1 TelephonyEvent (com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent)1 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1