当前位置: 首页>>代码示例>>Golang>>正文


Golang batterystats_proto.BatteryStats类代码示例

本文整理汇总了Golang中github.com/google/battery-historian/pb/batterystats_proto.BatteryStats的典型用法代码示例。如果您正苦于以下问题:Golang BatteryStats类的具体用法?Golang BatteryStats怎么用?Golang BatteryStats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BatteryStats类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: printResults

func printResults(outputProto *bspb.BatteryStats, fileName string, dir string) {
	if outputProto == nil {
		fmt.Println("Inputs were identical.")
		return
	}

	fmt.Printf("\n################\n")
	fmt.Printf("Partial Wakelocks\n")
	fmt.Printf("################\n\n")
	var pwl []*checkinparse.WakelockInfo
	for _, app := range outputProto.App {
		for _, pw := range app.Wakelock {
			pwl = append(pwl, &checkinparse.WakelockInfo{
				Name:     fmt.Sprintf("%s : %s", app.GetName(), pw.GetName()),
				UID:      app.GetUid(),
				Duration: time.Duration(pw.GetPartialTimeMsec()) * time.Millisecond,
			})
		}
	}

	checkinparse.SortByAbsTime(pwl)
	for _, pw := range pwl[:min(10, len(pwl))] {
		fmt.Printf("%s (File1 uid=%d) %s\n", pw.Duration, pw.UID, pw.Name)
	}

	fmt.Printf("\n################\n")
	fmt.Printf("Kernel Wakelocks\n")
	fmt.Printf("################\n\n")
	var kwl []*checkinparse.WakelockInfo
	for _, kw := range outputProto.GetSystem().KernelWakelock {
		if kw.GetName() != "PowerManagerService.WakeLocks" {
			kwl = append(kwl, &checkinparse.WakelockInfo{
				Name:     kw.GetName(),
				Duration: time.Duration(kw.GetTimeMsec()) * time.Millisecond,
			})
		}
	}
	checkinparse.SortByAbsTime(kwl)
	for _, kw := range kwl[:min(10, len(kwl))] {
		fmt.Printf("%s %s\n", kw.Duration, kw.Name)
	}

	data, err := proto.Marshal(outputProto)
	if err != nil {
		log.Fatalf("Cannot marshal output proto: %v", err)
	}
	ioutil.WriteFile(fileName+".proto", data, 0600)
	ioutil.WriteFile(dir+"/"+fileName+".proto", data, 0600)
}
开发者ID:mike69d,项目名称:battery-historian,代码行数:49,代码来源:local_checkin_delta.go

示例2: parseAppStats

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
}
开发者ID:Guojian-Chen,项目名称:battery-historian,代码行数:16,代码来源:presenter.go

示例3: parseAppStats

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
}
开发者ID:mike69d,项目名称:battery-historian,代码行数:45,代码来源:presenter.go

示例4: ParseCheckinData

// ParseCheckinData creates a Checkin struct from the given aggregated battery stats.
func ParseCheckinData(c *bspb.BatteryStats) Checkin {
	if c == nil {
		return Checkin{}
	}

	realtime := time.Duration(c.System.Battery.GetBatteryRealtimeMsec()) * time.Millisecond

	out := Checkin{
		Device:           c.Build.GetDevice(),
		Build:            c.Build.GetBuildId(),
		BuildFingerprint: c.Build.GetFingerprint(),
		ReportVersion:    c.GetReportVersion(),

		Realtime:          realtime,
		ScreenOffRealtime: time.Duration(c.System.Battery.GetScreenOffRealtimeMsec()) * time.Millisecond,

		ScreenOffDischargePoints: c.System.BatteryDischarge.GetScreenOff(),
		ScreenOnDischargePoints:  c.System.BatteryDischarge.GetScreenOn(),

		EstimatedDischarge: c.System.PowerUseSummary.GetComputedPowerMah(),
		ActualDischarge:    (c.System.PowerUseSummary.GetMinDrainedPowerMah() + c.System.PowerUseSummary.GetMaxDrainedPowerMah()) / 2,

		// Uptime is the same as screen-off uptime + screen on time
		Uptime: MDuration{
			V: (time.Duration(c.System.Battery.GetBatteryUptimeMsec()) * time.Millisecond),
		},

		ScreenOffUptime: MDuration{
			V: (time.Duration(c.System.Battery.GetScreenOffUptimeMsec()) * time.Millisecond),
		},

		ScreenOnTime: MDuration{
			V: (time.Duration(c.System.Misc.GetScreenOnTimeMsec()) * time.Millisecond),
		},

		PartialWakelockTime: MDuration{
			V: (time.Duration(c.System.Misc.GetPartialWakelockTimeMsec()) * time.Millisecond),
		},

		KernelOverheadTime: MDuration{
			V: (time.Duration(c.System.Battery.GetScreenOffUptimeMsec()-c.System.Misc.GetPartialWakelockTimeMsec()) * time.Millisecond),
		},

		SignalScanningTime: MDuration{
			V: (time.Duration(c.System.SignalScanningTime.GetTimeMsec()) * time.Millisecond),
		},

		MobileActiveTime: MDuration{
			V: (time.Duration(c.System.Misc.GetMobileActiveTimeMsec()) * time.Millisecond),
		},

		PhoneCallTime: MDuration{
			V: (time.Duration(c.System.Misc.GetPhoneOnTimeMsec()) * time.Millisecond),
		},

		WifiOnTime: MDuration{
			V: (time.Duration(c.System.Misc.GetWifiOnTimeMsec()) * time.Millisecond),
		},

		DeviceIdleModeEnabledTime: MDuration{
			V: (time.Duration(c.System.Misc.GetDeviceIdleModeEnabledTimeMsec()) * time.Millisecond),
		},

		DeviceIdlingTime: MDuration{
			V: (time.Duration(c.System.Misc.GetDeviceIdlingTimeMsec()) * time.Millisecond),
		},

		FullWakelockTime: MDuration{
			V: (time.Duration(c.System.Misc.GetFullWakelockTimeMsec()) * time.Millisecond),
		},

		InteractiveTime: MDuration{
			V: (time.Duration(c.System.Misc.GetInteractiveTimeMsec()) * time.Millisecond),
		},

		BluetoothOnTime: MDuration{
			V: (time.Duration(c.System.Misc.GetBluetoothOnTimeMsec()) * time.Millisecond),
		},

		LowPowerModeEnabledTime: MDuration{
			V: (time.Duration(c.System.Misc.GetLowPowerModeEnabledTimeMsec()) * time.Millisecond),
		},
		ConnectivityChanges: c.System.Misc.GetConnectivityChanges(),
	}
	out.ScreenOffUptimePercentage = (float32(out.ScreenOffUptime.V) / float32(realtime)) * 100
	out.ScreenOnTimePercentage = (float32(out.ScreenOnTime.V) / float32(realtime)) * 100
	out.PartialWakelockTimePercentage = (float32(out.PartialWakelockTime.V) / float32(realtime)) * 100
	out.KernelOverheadTimePercentage = (float32(out.KernelOverheadTime.V) / float32(realtime)) * 100
	out.SignalScanningTimePercentage = (float32(out.SignalScanningTime.V) / float32(realtime)) * 100
	out.MobileActiveTimePercentage = (float32(out.MobileActiveTime.V) / float32(realtime)) * 100
	out.FullWakelockTimePercentage = (float32(out.FullWakelockTime.V) / float32(realtime)) * 100
	out.PhoneCallTimePercentage = (float32(out.PhoneCallTime.V) / float32(realtime)) * 100
	out.DeviceIdleModeEnabledTimePercentage = (float32(out.DeviceIdleModeEnabledTime.V) / float32(realtime)) * 100
	out.DeviceIdlingTimePercentage = (float32(out.DeviceIdlingTime.V) / float32(realtime)) * 100
	out.InteractiveTimePercentage = (float32(out.InteractiveTime.V) / float32(realtime)) * 100

	out.BluetoothOnTimePercentage = (float32(out.BluetoothOnTime.V) / float32(realtime)) * 100
	out.LowPowerModeEnabledTimePercentage = (float32(out.LowPowerModeEnabledTime.V) / float32(realtime)) * 100

//.........这里部分代码省略.........
开发者ID:mike69d,项目名称:battery-historian,代码行数:101,代码来源:aggregated_stats.go

示例5: NormalizeStats

// 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
}
开发者ID:mike69d,项目名称:battery-historian,代码行数:73,代码来源:checkin_normalize.go

示例6: parseCheckinData

func parseCheckinData(c *bspb.BatteryStats) checkin {
	if c == nil {
		return checkin{}
	}

	realtime := time.Duration(c.System.Battery.GetBatteryRealtimeMsec()) * time.Millisecond

	out := checkin{
		Device:           c.Build.GetDevice(),
		Build:            c.Build.GetBuildId(),
		BuildFingerprint: c.Build.GetFingerprint(),
		ReportVersion:    c.GetReportVersion(),

		Realtime:          realtime,
		ScreenOffRealtime: time.Duration(c.System.Battery.GetScreenOffRealtimeMsec()) * time.Millisecond,

		ScreenOffDischargePoints: c.System.BatteryDischarge.GetScreenOff(),
		ScreenOnDischargePoints:  c.System.BatteryDischarge.GetScreenOn(),

		BatteryCapacity:    c.System.PowerUseSummary.GetBatteryCapacityMah(),
		EstimatedDischarge: c.System.PowerUseSummary.GetComputedPowerMah(),
		ActualDischarge:    (c.System.PowerUseSummary.GetMinDrainedPowerMah() + c.System.PowerUseSummary.GetMaxDrainedPowerMah()) / 2,

		// Uptime is the same as screen-off uptime + screen on time
		Uptime: mDuration{
			V: (time.Duration(c.System.Battery.GetBatteryUptimeMsec()) * time.Millisecond),
		},

		ScreenOffUptime: mDuration{
			V: (time.Duration(c.System.Battery.GetScreenOffUptimeMsec()) * time.Millisecond),
		},

		ScreenOnTime: mDuration{
			V: (time.Duration(c.System.Misc.GetScreenOnTimeMsec()) * time.Millisecond),
		},

		PartialWakelockTime: mDuration{
			V: (time.Duration(c.System.Misc.GetPartialWakelockTimeMsec()) * time.Millisecond),
		},

		KernelOverheadTime: mDuration{
			V: (time.Duration(c.System.Battery.GetScreenOffUptimeMsec()-c.System.Misc.GetPartialWakelockTimeMsec()) * time.Millisecond),
		},

		SignalScanningTime: mDuration{
			V: (time.Duration(c.System.SignalScanningTime.GetTimeMsec()) * time.Millisecond),
		},

		MobileActiveTime: mDuration{
			V: (time.Duration(c.System.Misc.GetMobileActiveTimeMsec()) * time.Millisecond),
		},
	}

	out.MiscPercentage = 100 * (out.ActualDischarge - out.EstimatedDischarge) / out.BatteryCapacity

	out.MobileKiloBytesPerHr = mFloat32{V: (c.System.GlobalNetwork.GetMobileBytesRx() + c.System.GlobalNetwork.GetMobileBytesTx()) / (1024 * float32(realtime.Hours()))}
	out.WifiKiloBytesPerHr = mFloat32{V: (c.System.GlobalNetwork.GetWifiBytesRx() + c.System.GlobalNetwork.GetWifiBytesTx()) / (1024 * float32(realtime.Hours()))}

	if c.GetReportVersion() >= 14 {
		out.WifiOnTime = mDuration{V: time.Duration(c.System.GlobalWifi.GetWifiOnTimeMsec()) * time.Millisecond}
		out.WifiIdleTime = mDuration{V: time.Duration(c.System.GlobalWifi.GetWifiIdleTimeMsec()) * time.Millisecond}
		out.WifiTransmitTime = mDuration{V: time.Duration(c.System.GlobalWifi.GetWifiRxTimeMsec()+c.System.GlobalWifi.GetWifiTxTimeMsec()) * time.Millisecond}
		out.WifiDischargePoints = 100 * c.System.GlobalWifi.GetWifiPowerMah() / c.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah()
		out.WifiDischargeRatePerHr = mFloat32{
			V: 100 * c.System.GlobalWifi.GetWifiPowerMah() / c.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah() / float32(realtime.Hours()),
		}

		out.BluetoothIdleTime = mDuration{V: time.Duration(c.System.GlobalBluetooth.GetBluetoothIdleTimeMsec()) * time.Millisecond}
		out.BluetoothTransmitTime = mDuration{V: time.Duration(c.System.GlobalBluetooth.GetBluetoothRxTimeMsec()+c.System.GlobalBluetooth.GetBluetoothTxTimeMsec()) * time.Millisecond}
		out.BluetoothDischargePoints = 100 * c.System.GlobalBluetooth.GetBluetoothPowerMah() / c.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah()
		out.BluetoothDischargeRatePerHr = mFloat32{
			V: 100 * c.System.GlobalBluetooth.GetBluetoothPowerMah() / c.GetSystem().GetPowerUseSummary().GetBatteryCapacityMah() / float32(realtime.Hours()),
		}
	}

	if s := c.System.Battery.GetScreenOffRealtimeMsec(); s > 0 {
		out.ScreenOffDichargeRatePerHr = mFloat32{V: 60 * 60 * 1000 * c.System.BatteryDischarge.GetScreenOff() / s}
	}
	if s := c.System.Misc.GetScreenOnTimeMsec(); s > 0 {
		out.ScreenOnDichargeRatePerHr = mFloat32{V: 60 * 60 * 1000 * c.System.BatteryDischarge.GetScreenOn() / s}
	}

	// Top Partial Wakelocks by time and count
	var pwl []*checkinparse.WakelockInfo
	for _, app := range c.App {
		for _, pw := range app.Wakelock {
			if pw.GetPartialTimeMsec() >= 0.01 {
				pwl = append(pwl, &checkinparse.WakelockInfo{
					Name:     fmt.Sprintf("%s : %s", app.GetName(), pw.GetName()),
					UID:      app.GetUid(),
					Duration: time.Duration(pw.GetPartialTimeMsec()) * time.Millisecond,
					Count:    pw.GetPartialCount(),
				})
			}
		}
	}

	// Top Partial Wakelocks by time
	checkinparse.SortByTime(pwl)
	for _, pw := range pwl {
//.........这里部分代码省略.........
开发者ID:Guojian-Chen,项目名称:battery-historian,代码行数:101,代码来源:presenter.go


注:本文中的github.com/google/battery-historian/pb/batterystats_proto.BatteryStats类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。