blob: e01926a8f17e362c48cacf70dc14f7a9fe30d1a2 [file] [log] [blame]
package metrics
import (
"time"
"fidl/fuchsia/cobalt"
)
type metricID uint32
const (
_ metricID = iota
metricSystemUpToDate
metricOtaStart
metricOtaResult
)
// Log synchronously submits the given metric to cobalt
func Log(metric Metric) {
metric.log()
}
// Metric is a cobalt metric that can be submitted to cobalt
type Metric interface {
log()
}
type SystemUpToDate struct {
Initiator Initiator
Version string
When time.Time
}
func (m SystemUpToDate) log() {
logCustomEvent(metricSystemUpToDate, []cobalt.CustomEventValue{
newIndexValue("initiator", uint32(m.Initiator)),
newStringValue("version", m.Version),
newIndexValue("when", uint32(m.When.Local().Hour())),
})
}
type OtaStart struct {
Initiator Initiator
Source string
Target string
When time.Time
}
func (m OtaStart) log() {
logCustomEvent(metricOtaStart, []cobalt.CustomEventValue{
newIndexValue("initiator", uint32(m.Initiator)),
newStringValue("source", m.Source),
newStringValue("target", m.Target),
newIndexValue("when", uint32(m.When.Local().Hour())),
})
}
type OtaResult struct {
Initiator Initiator
Source string
Target string
Attempt int64
FreeSpaceStart int64
FreeSpaceEnd int64
When time.Time
Duration time.Duration
Phase Phase
ErrorSource string
ErrorText string
ErrorCode int64
}
func (m OtaResult) log() {
durationInMilliseconds := m.Duration.Nanoseconds() / time.Millisecond.Nanoseconds()
logCustomEvent(metricOtaResult, []cobalt.CustomEventValue{
newIndexValue("initiator", uint32(m.Initiator)),
newStringValue("source", m.Source),
newStringValue("target", m.Target),
newIntValue("attempt", m.Attempt),
newIntValue("free_space_start", m.FreeSpaceStart),
newIntValue("free_space_end", m.FreeSpaceEnd),
newIndexValue("when", uint32(m.When.Local().Hour())),
newIntValue("duration", durationInMilliseconds),
newIndexValue("phase", uint32(m.Phase)),
newStringValue("error_source", m.ErrorSource),
newStringValue("error_text", m.ErrorText),
newIntValue("error_code", m.ErrorCode),
})
}