Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Increment metric duration #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func ParseHeader(input string) (*Header, error) {

// NewMetric creates a new Metric and adds it to this header.
func (h *Header) NewMetric(name string) *Metric {
for i := range h.Metrics {
if h.Metrics[i].Name == name {
return h.Metrics[i]
}
}

return h.Add(&Metric{Name: name})
}

Expand Down
2 changes: 1 addition & 1 deletion metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *Metric) Start() *Metric {
func (m *Metric) Stop() *Metric {
// Only record if we have a start time set with Start()
if !m.startTime.IsZero() {
m.Duration = time.Since(m.startTime)
m.Duration += time.Since(m.startTime)
}

return m
Expand Down