csv

package
v0.0.0-...-d2356ba Latest Latest
Warning

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

Go to latest
Published: May 19, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package csv contains functions to store battery history events and convert them to and from CSV format.

Index

Constants

View Source
const (
	// FileHeader is outputted as the first line in csv files.
	FileHeader = "metric,type,start_time,end_time,value,opt"

	// UnknownWakeup is emitted for running events if no wake up reason is set for it.
	UnknownWakeup = "Unknown wakeup reason"

	// CPURunning is the string outputted for CPU Running events.
	CPURunning = "CPU running"

	// Reboot is the string outputted for reboot events.
	Reboot = "Reboot"
)

Variables

This section is empty.

Functions

func ExtractEvents

func ExtractEvents(csvInput string, metrics []string) (map[string][]Event, []error)

ExtractEvents returns all events matching any of the given metrics names. If a metric has no matching events, the map will contain a nil slice for that metric. If the metrics slice is nil, all events will be extracted. Errors encountered during parsing will be collected into an errors slice and will continue parsing remaining events.

Types

type Entry

type Entry struct {
	Desc  string
	Start int64
	Type  string
	Value string
	// Additional data associated with the entry.
	// Currently this is used to hold the UID (string) of a service (ServiceUID),
	// and is an empty string for other types.
	Opt string

	// Unique identifier for the event. e.g. The name of the app that triggered the event.
	Identifier string
}

Entry contains the details of the start of a state.

func (*Entry) GetKey

func (e *Entry) GetKey(desc string) Key

GetKey returns the unique identifier for the entry.

func (*Entry) GetStartTime

func (e *Entry) GetStartTime() int64

GetStartTime returns the start time of the entry.

func (*Entry) GetType

func (e *Entry) GetType() string

GetType returns the type of the entry.

func (*Entry) GetValue

func (e *Entry) GetValue() string

GetValue returns the stored value of the entry.

type EntryState

type EntryState interface {
	// GetStartTime returns the start time of the entry.
	GetStartTime() int64
	// GetType returns the type of the entry:
	// "string", "bool", "float", "group", "int", "service", or "summary".
	GetType() string
	// GetValue returns the stored value of the entry.
	GetValue() string
	// GetKey returns the unique identifier for the entry.
	GetKey(string) Key
}

EntryState is a commmon interface for the various types, so the Entries can access them the same way.

type Event

type Event struct {
	Type       string
	Start, End int64
	Value      string
	Opt        string
	AppName    string // For populating from package info.
}

Event stores the details contained in a CSV line.

func MergeEvents

func MergeEvents(events []Event) []Event

MergeEvents merges all overlapping events.

type Key

type Key struct {
	Metric, Identifier string
}

Key is the unique identifier for an entry.

type RunningEvent

type RunningEvent struct {
	// contains filtered or unexported fields
}

RunningEvent contains the details required for printing a running event.

type State

type State struct {
	// contains filtered or unexported fields
}

State holds the csv writer, and the map from metric key to active entry.

func NewState

func NewState(csvWriter io.Writer, printHeader bool) *State

NewState returns a new State.

func (*State) AddEntry

func (s *State) AddEntry(desc string, newState EntryState, curTime int64)

AddEntry adds the given entry into the existing map. If the entry already exists, it prints out the entry and deletes it.

func (*State) AddEntryWithOpt

func (s *State) AddEntryWithOpt(desc string, newState EntryState, curTime int64, opt string)

AddEntryWithOpt adds the given entry into the existing map, with the optional value set. If the entry already exists, it prints out the entry and deletes it.

func (*State) AddOptToEntry

func (s *State) AddOptToEntry(desc string, state EntryState, opt string)

AddOptToEntry adds the given optional value to an existing entry in the map. No changes are made if the entry doesn't already exist.

func (*State) AddRebootEvent

func (s *State) AddRebootEvent(curTime int64)

AddRebootEvent stores the entry for the reboot event, using the given curTime as the start time.

func (*State) EndEvent

func (s *State) EndEvent(metric, eventIdentifier string, curTime int64)

EndEvent marks an event as finished at the given timestamp. Does nothing if the event is not currently active.

func (*State) EndWakeupReason

func (s *State) EndWakeupReason(service string, curTime int64) error

EndWakeupReason adds the wakeup reason to the wakeup reason buffer.

func (*State) HasEvent

func (s *State) HasEvent(metric, eventIdentifier string) bool

HasEvent returns whether an event for the metric with the given identifier is currently active.

func (*State) HasRebootEvent

func (s *State) HasRebootEvent() bool

HasRebootEvent returns true if a reboot event is currently stored, false otherwise.

func (*State) Print

func (s *State) Print(desc, metricType string, start, end int64, value, opt string)

Print directly prints a csv entry to CSV format and writes it to the writer.

func (*State) PrintActiveEvent

func (s *State) PrintActiveEvent(metric string, endMs int64)

PrintActiveEvent prints out all active entries for the given metric name with the given end time, and deletes those entries from the map.

func (*State) PrintAllReset

func (s *State) PrintAllReset(curTime int64)

PrintAllReset prints all active entries and resets the map.

func (*State) PrintEvent

func (s *State) PrintEvent(metric string, e Event)

PrintEvent writes an event extracted by ExtractEvents to the writer.

func (*State) PrintInstantEvent

func (s *State) PrintInstantEvent(e Entry)

PrintInstantEvent converts the given data to CSV format and writes it to the writer.

func (*State) PrintRebootEvent

func (s *State) PrintRebootEvent(curTime int64)

PrintRebootEvent prints out the stored reboot event, using the given curTime as the end time.

func (*State) StartEvent

func (s *State) StartEvent(e Entry)

StartEvent marks an event as beginning at the given timestamp. Does nothing if the event is already active. For events without a duration, PrintInstantEvent should be used instead.

func (*State) StartWakeupReason

func (s *State) StartWakeupReason(service string, curTime int64)

StartWakeupReason adds the wakeup reason to the wakeup reason buffer.

Jump to

Keyboard shortcuts

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