bugreportutils

package
v0.0.0-...-53aec40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package bugreportutils is a library of common bugreport parsing functions.

Index

Constants

View Source
const (
	// GPSSensorNumber is the hard-coded sensor number defined in frameworks/base/core/java/android/os/BatteryStats.Sensor
	GPSSensorNumber = -10000

	// TimeLayout is the timestamp layout commonly printed in bug reports.
	TimeLayout = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	// BugReportSectionRE is a regular expression to match the beginning of a bug report section.
	BugReportSectionRE = regexp.MustCompile(`------\s+(?P<section>.*)\s+-----`)

	// TimeZoneRE is a regular expression to match the timezone string in a bug report.
	TimeZoneRE = regexp.MustCompile(`^\[persist.sys.timezone\]:\s+\[` + `(?P<timezone>\S+)\]`)

	// DumpstateRE is a regular expression that matches the time information from the dumpstate line at the start of a bug report.
	DumpstateRE = regexp.MustCompile(`==\sdumpstate:\s(?P<timestamp>\d+-\d+-\d+\s\d+:\d+:\d+)`)
)

Functions

func Contents

func Contents(fname string, b []byte) (map[string][]byte, error)

Contents returns a map of the contents of each file from the given bytes slice, with the key being the file name. Supported file formats are text/plain and application/zip. For zipped files, each file name will be prepended by the zip file's name. An error will be non-nil for processing issues.

func DumpState

func DumpState(contents string) (time.Time, error)

DumpState returns the parsed dumpstate information as a time object.

func ExtractBatterystatsCheckin

func ExtractBatterystatsCheckin(input string) string

ExtractBatterystatsCheckin extracts and returns only the lines in input that are included in the "CHECKIN BATTERYSTATS" section.

func ExtractBugReport

func ExtractBugReport(fname string, contents []byte) (string, string, error)

ExtractBugReport extracts and returns only the first valid bug report data in the given contents. The second returned parameter will be the determined file name.

func ExtractPIDMappings

func ExtractPIDMappings(contents string) (map[string][]AppInfo, []string)

ExtractPIDMappings returns mappings from PID to app names and UIDs extracted from the bug report.

func IsBugReport

func IsBugReport(b []byte) bool

IsBugReport tries to determine if the given bytes resembles a bug report.

func SecFractionAsMs

func SecFractionAsMs(fr string) (int64, error)

SecFractionAsMs converts the fraction of a second to milliseconds. e.g. "123456" from "27.123456" corresponds to 123ms (and 27 seconds).

func TimeStampToMs

func TimeStampToMs(timestamp, remainder string, loc *time.Location) (int64, error)

TimeStampToMs converts a timestamp in the TimeLayout format, combined with the fraction of a second, to a unix ms timestamp based on the location.

func TimeZone

func TimeZone(contents string) (*time.Location, error)

TimeZone extracts the time zone from a bug report.

Types

type AppInfo

type AppInfo struct {
	Name string
	UID  string
}

AppInfo holds the name and UID for an app.

type MetaInfo

type MetaInfo struct {
	DeviceID         string
	SdkVersion       int
	BuildFingerprint string
	ModelName        string
	Sensors          map[int32]SensorInfo
}

MetaInfo contains metadata about the device being analyzed

func ParseMetaInfo

func ParseMetaInfo(input string) (*MetaInfo, error)

ParseMetaInfo extracts the device ID, build fingerprint and model name from the bug report.

type SensorInfo

type SensorInfo struct {
	Name, Type      string
	Version, Number int32
	TotalTimeMs     int64 // time.Duration in Golang is converted to nanoseconds in JS, so using int64 and naming convention to be clear in$
	Count           float32
}

SensorInfo contains basic information about a device's sensor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL