Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Count usage of process start-up #139

Merged
merged 2 commits into from
May 16, 2020
Merged
Changes from 1 commit
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
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 to Update()
PierreF marked this conversation as resolved.
Show resolved Hide resolved
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