Add support for unidentified/system processes/profiles

This commit is contained in:
Daniel
2020-04-17 21:52:06 +02:00
parent 10ee7fd7db
commit 033dceab5b
16 changed files with 243 additions and 67 deletions

View File

@@ -1,7 +1,14 @@
package profile
import (
"context"
"sync"
"time"
)
const (
activeProfileCleanerTickDuration = 10 * time.Minute
activeProfileCleanerThreshold = 1 * time.Hour
)
var (
@@ -38,7 +45,34 @@ func markActiveProfileAsOutdated(scopedID string) {
profile, ok := activeProfiles[scopedID]
if ok {
profile.oudated.Set()
profile.outdated.Set()
delete(activeProfiles, scopedID)
}
}
func cleanActiveProfiles(ctx context.Context) error { //nolint:param // need to conform to interface
for {
select {
case <-time.After(activeProfileCleanerTickDuration):
threshold := time.Now().Add(-activeProfileCleanerThreshold)
activeProfilesLock.Lock()
for id, profile := range activeProfiles {
// get last used
profile.Lock()
lastUsed := profile.lastUsed
profile.Unlock()
// remove if not used for a while
if lastUsed.Before(threshold) {
profile.outdated.Set()
delete(activeProfiles, id)
}
}
activeProfilesLock.Unlock()
case <-ctx.Done():
return nil
}
}
}