func parseAppStats(checkin *bspb.BatteryStats) []*bspb.BatteryStats_App { var as []*bspb.BatteryStats_App unknown := 1 for _, a := range checkin.GetApp() { if a.GetName() == "" { a.Name = proto.String("UNKNOWN_" + strconv.Itoa(unknown)) unknown++ } as = append(as, a) } // Sort by name so that we can display the apps in alphabetical order in the dropdown. sort.Sort(byName(as)) return as }
func parseAppStats(checkin *bspb.BatteryStats, sensors map[int32]bugreportutils.SensorInfo) []AppStat { var as []AppStat bCapMah := checkin.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah() for _, app := range checkin.GetApp() { a := AppStat{ DevicePowerPrediction: 100 * float32(app.GetPowerUseItem().GetComputedPowerMah()) / bCapMah, RawStats: app, } if app.GetName() == "" { app.Name = proto.String(fmt.Sprintf("UNKNOWN_%d", app.GetUid())) } // Only add it to AppStat if the CPU field exists and is therefore populated. if app.Cpu != nil { a.CPUPowerPrediction = 100 * (app.Cpu.GetPowerMaMs() / (1000 * 60 * 60)) / bCapMah } for _, u := range app.GetUserActivity() { a.UserActivity = append(a.UserActivity, userActivity{ Type: u.GetName().String(), Count: u.GetCount(), }) } for _, s := range app.GetSensor() { sensor, ok := sensors[s.GetNumber()] if !ok { sensor = bugreportutils.SensorInfo{ Name: fmt.Sprintf("unknown sensor (#%d)", s.GetNumber()), Number: s.GetNumber(), } } sensor.TotalTimeMs = int64(s.GetTotalTimeMsec()) sensor.Count = s.GetCount() a.Sensor = append(a.Sensor, sensor) } as = append(as, a) } // Sort by name so that we can display the apps in alphabetical order in the dropdown. sort.Sort(byName(as)) return as }
// NormalizeStats takes in a proto and normalizes it by converting // any absolute value to value/TotalTime. func NormalizeStats(p *bspb.BatteryStats) (*bspb.BatteryStats, error) { totalTimeHour := roundToTwoDecimal(float64((p.GetSystem().GetBattery().GetBatteryRealtimeMsec()) / (3600 * 1000))) if totalTimeHour == 0 { return nil, errors.New("battery real time cannot be 0") } normApp := &bspb.BatteryStats{ ReportVersion: p.ReportVersion, AggregationType: p.AggregationType, } // Normalize the app data for _, a1 := range p.GetApp() { a := normalizeApp(a1, totalTimeHour) normApp.App = append(normApp.App, a) } // Normalize system data s1 := p.GetSystem() s := &bspb.BatteryStats_System{} if norm := normalizeMessage(s1.GetBattery(), totalTimeHour); norm != nil { s.Battery = norm.(*bspb.BatteryStats_System_Battery) } if norm := normalizeMessage(s1.GetBatteryDischarge(), totalTimeHour); norm != nil { s.BatteryDischarge = norm.(*bspb.BatteryStats_System_BatteryDischarge) } s.BatteryLevel = s1.GetBatteryLevel() if norm := normalizeRepeatedMessage(s1.GetBluetoothState(), totalTimeHour); !norm.IsNil() { s.BluetoothState = norm.Interface().([]*bspb.BatteryStats_System_BluetoothState) } if norm := normalizeRepeatedMessage(s1.GetDataConnection(), totalTimeHour); !norm.IsNil() { s.DataConnection = norm.Interface().([]*bspb.BatteryStats_System_DataConnection) } if norm := normalizeMessage(s1.GetGlobalNetwork(), totalTimeHour); norm != nil { s.GlobalNetwork = norm.(*bspb.BatteryStats_System_GlobalNetwork) } if norm := normalizeRepeatedMessage(s1.GetKernelWakelock(), totalTimeHour); !norm.IsNil() { s.KernelWakelock = norm.Interface().([]*bspb.BatteryStats_System_KernelWakelock) } if norm := normalizeMessage(s1.GetMisc(), totalTimeHour); norm != nil { s.Misc = norm.(*bspb.BatteryStats_System_Misc) } if norm := normalizeRepeatedMessage(s1.GetPowerUseItem(), totalTimeHour); !norm.IsNil() { s.PowerUseItem = norm.Interface().([]*bspb.BatteryStats_System_PowerUseItem) } if norm := normalizeMessage(s1.GetPowerUseSummary(), totalTimeHour); norm != nil { s.PowerUseSummary = norm.(*bspb.BatteryStats_System_PowerUseSummary) } if norm := normalizeRepeatedMessage(s1.GetScreenBrightness(), totalTimeHour); !norm.IsNil() { s.ScreenBrightness = norm.Interface().([]*bspb.BatteryStats_System_ScreenBrightness) } if norm := normalizeMessage(s1.GetSignalScanningTime(), totalTimeHour); norm != nil { s.SignalScanningTime = norm.(*bspb.BatteryStats_System_SignalScanningTime) } if norm := normalizeRepeatedMessage(s1.GetSignalStrength(), totalTimeHour); !norm.IsNil() { s.SignalStrength = norm.Interface().([]*bspb.BatteryStats_System_SignalStrength) } if norm := normalizeRepeatedMessage(s1.GetWakeupReason(), totalTimeHour); !norm.IsNil() { s.WakeupReason = norm.Interface().([]*bspb.BatteryStats_System_WakeupReason) } if norm := normalizeRepeatedMessage(s1.GetWifiState(), totalTimeHour); !norm.IsNil() { s.WifiState = norm.Interface().([]*bspb.BatteryStats_System_WifiState) } if norm := normalizeRepeatedMessage(s1.GetWifiSupplicantState(), totalTimeHour); !norm.IsNil() { s.WifiSupplicantState = norm.Interface().([]*bspb.BatteryStats_System_WifiSupplicantState) } p.System = s p.App = normApp.App return p, nil }