battery-historian: github.com/google/battery-historian/csv Index | Files

package csv

import "github.com/google/battery-historian/csv"

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

Index

Package Files

csv.go events.go

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"
)

func ExtractEvents Uses

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.

type Entry Uses

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 Uses

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

GetKey returns the unique identifier for the entry.

func (*Entry) GetStartTime Uses

func (e *Entry) GetStartTime() int64

GetStartTime returns the start time of the entry.

func (*Entry) GetType Uses

func (e *Entry) GetType() string

GetType returns the type of the entry.

func (*Entry) GetValue Uses

func (e *Entry) GetValue() string

GetValue returns the stored value of the entry.

type EntryState Uses

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 Uses

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 Uses

func MergeEvents(events []Event) []Event

MergeEvents merges all overlapping events.

type Key Uses

type Key struct {
    Metric, Identifier string
}

Key is the unique identifier for an entry.

type RunningEvent Uses

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

RunningEvent contains the details required for printing a running event.

type State Uses

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

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

func NewState Uses

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

NewState returns a new State.

func (*State) AddEntry Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

EndWakeupReason adds the wakeup reason to the wakeup reason buffer.

func (*State) HasEvent Uses

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 Uses

func (s *State) HasRebootEvent() bool

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

func (*State) Print Uses

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 Uses

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 Uses

func (s *State) PrintAllReset(curTime int64)

PrintAllReset prints all active entries and resets the map.

func (*State) PrintEvent Uses

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

PrintEvent writes an event extracted by ExtractEvents to the writer.

func (*State) PrintInstantEvent Uses

func (s *State) PrintInstantEvent(e Entry)

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

func (*State) PrintRebootEvent Uses

func (s *State) PrintRebootEvent(curTime int64)

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

func (*State) StartEvent Uses

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 Uses

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

StartWakeupReason adds the wakeup reason to the wakeup reason buffer.

Package csv imports 10 packages (graph) and is imported by 13 packages. Updated 2018-05-03. Refresh now. Tools for package owners.