-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: yaofighting <siyao@zju.edu.cn>
- Loading branch information
1 parent
7fee60e
commit 2fb0620
Showing
3 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
collector/pkg/component/analyzer/cpuanalyzer/delete_tid.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cpuanalyzer | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
type tidDeleteQueue struct { | ||
queueMutex sync.Mutex | ||
queue []deleteTid | ||
} | ||
|
||
type deleteTid struct { | ||
pid uint32 | ||
tid uint32 | ||
exitTime time.Time | ||
} | ||
|
||
func (dq *tidDeleteQueue) GetFront() *deleteTid { | ||
if len(dq.queue) > 0 { | ||
return &dq.queue[0] | ||
} | ||
return nil | ||
} | ||
|
||
func (dq *tidDeleteQueue) Push(elem deleteTid) { | ||
dq.queue = append(dq.queue, elem) | ||
} | ||
|
||
func (dq *tidDeleteQueue) Pop() { | ||
if len(dq.queue) > 0 { | ||
dq.queue = dq.queue[1:len(dq.queue)] | ||
} | ||
} | ||
|
||
func (ca *CpuAnalyzer) InitTidDeleteQueue() { | ||
ca.tidExpiredQueue = &tidDeleteQueue{queue: make([]deleteTid, 0)} | ||
} | ||
|
||
//Add procexit tid | ||
func (ca *CpuAnalyzer) AddTidToDeleteCache(curTime time.Time, pid uint32, tid uint32) { | ||
defer ca.tidExpiredQueue.queueMutex.Unlock() | ||
cacheElem := deleteTid{pid: pid, tid: tid, exitTime: curTime} | ||
ca.tidExpiredQueue.queueMutex.Lock() | ||
ca.tidExpiredQueue.Push(cacheElem) | ||
} | ||
|
||
func (ca *CpuAnalyzer) TidDelete(interval time.Duration, expiredDuration time.Duration) { | ||
for { | ||
select { | ||
case <-time.After(interval): | ||
now := time.Now() | ||
ca.tidExpiredQueue.queueMutex.Lock() | ||
for { | ||
elem := ca.tidExpiredQueue.GetFront() | ||
if elem == nil { | ||
break | ||
} | ||
if elem.exitTime.Add(expiredDuration).Before(now) { | ||
tidEventsMap := ca.cpuPidEvents[elem.pid] | ||
if tidEventsMap == nil { | ||
continue | ||
} | ||
ca.telemetry.Logger.Debugf("Delete expired thread... pid=%d, tid=%d", elem.pid, elem.tid) | ||
delete(tidEventsMap, elem.tid) | ||
ca.tidExpiredQueue.Pop() | ||
} else { | ||
break | ||
} | ||
} | ||
ca.tidExpiredQueue.queueMutex.Unlock() | ||
} | ||
} | ||
} |