Skip to content

Commit

Permalink
Merge pull request #139 from PierreF/improve-short-lived-accuracy
Browse files Browse the repository at this point in the history
Count usage of process start-up
  • Loading branch information
ncabatoff authored May 16, 2020
2 parents 0c9fe55 + 9c9d3a7 commit 9760f38
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions proc/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type (
// procIds is a map from pid to ProcId. This is a convenience
// to allow finding the Tracked entry of a parent process.
procIds map[int]ID
// firstUpdateAt is the time the first update was run. It allows to
// count first usage of a process started between two Update() calls
firstUpdateAt time.Time
// trackChildren makes Tracker track descendants of procs the
// namer wanted tracked.
trackChildren bool
Expand Down Expand Up @@ -164,6 +167,13 @@ func (t *Tracker) track(groupName string, idinfo IDInfo) {
thr.ThreadName, thr.Counts, Delta{}, time.Time{}, thr.Wchan}
}
}

// If the process started while Tracker was running, all current counter happened
// between the last Update() and the current Update() and should be counted.
if idinfo.StartTime.After(t.firstUpdateAt) {
tproc.lastaccum = Delta(tproc.metrics.Counts)
}

t.tracked[idinfo.ID] = &tproc
}

Expand Down Expand Up @@ -397,6 +407,10 @@ func (t *Tracker) lookupUid(uid int) string {
// its metrics for existing tracked procs. Returns nonfatal errors
// and the status of all tracked procs, or an error if fatal.
func (t *Tracker) Update(iter Iter) (CollectErrors, []Update, error) {
if t.firstUpdateAt.IsZero() {
t.firstUpdateAt = time.Now()
}

newProcs, colErrs, err := t.update(iter)
if err != nil {
return colErrs, nil, err
Expand Down

0 comments on commit 9760f38

Please # to comment.