Documentation ¶
Overview ¶
Package csv contains functions to store battery history events and convert them to and from CSV format.
Index ¶
- Constants
- func ExtractEvents(csvInput string, metrics []string) (map[string][]Event, []error)
- type Entry
- type EntryState
- type Event
- type Key
- type RunningEvent
- type State
- func (s *State) AddEntry(desc string, newState EntryState, curTime int64)
- func (s *State) AddEntryWithOpt(desc string, newState EntryState, curTime int64, opt string)
- func (s *State) AddOptToEntry(desc string, state EntryState, opt string)
- func (s *State) AddRebootEvent(curTime int64)
- func (s *State) EndEvent(metric, eventIdentifier string, curTime int64)
- func (s *State) EndWakeupReason(service string, curTime int64) error
- func (s *State) HasEvent(metric, eventIdentifier string) bool
- func (s *State) HasRebootEvent() bool
- func (s *State) Print(desc, metricType string, start, end int64, value, opt string)
- func (s *State) PrintActiveEvent(metric string, endMs int64)
- func (s *State) PrintAllReset(curTime int64)
- func (s *State) PrintEvent(metric string, e Event)
- func (s *State) PrintInstantEvent(e Entry)
- func (s *State) PrintRebootEvent(curTime int64)
- func (s *State) StartEvent(e Entry)
- func (s *State) StartWakeupReason(service string, curTime int64)
Constants ¶
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 ¶
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) GetStartTime ¶
GetStartTime returns the start time 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 ¶
MergeEvents merges all overlapping events.
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 (*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 ¶
AddRebootEvent stores the entry for the reboot event, using the given curTime as the start time.
func (*State) EndEvent ¶
EndEvent marks an event as finished at the given timestamp. Does nothing if the event is not currently active.
func (*State) EndWakeupReason ¶
EndWakeupReason adds the wakeup reason to the wakeup reason buffer.
func (*State) HasEvent ¶
HasEvent returns whether an event for the metric with the given identifier is currently active.
func (*State) HasRebootEvent ¶
HasRebootEvent returns true if a reboot event is currently stored, false otherwise.
func (*State) PrintActiveEvent ¶
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 ¶
PrintAllReset prints all active entries and resets the map.
func (*State) PrintEvent ¶
PrintEvent writes an event extracted by ExtractEvents to the writer.
func (*State) PrintInstantEvent ¶
PrintInstantEvent converts the given data to CSV format and writes it to the writer.
func (*State) PrintRebootEvent ¶
PrintRebootEvent prints out the stored reboot event, using the given curTime as the end time.
func (*State) StartEvent ¶
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 ¶
StartWakeupReason adds the wakeup reason to the wakeup reason buffer.