MCPcopy
hub / github.com/wavetermdev/waveterm / runLoop

Method runLoop

pkg/wshrpc/wshremote/processviewer.go:183–220  ·  view source on GitHub ↗
(firstReadyCh chan struct{})

Source from the content-addressed store, hash-verified

181}
182
183func (s *procCacheState) runLoop(firstReadyCh chan struct{}) {
184 firstDone := false
185 defer func() {
186 if panichandler.PanicHandler("procCache.runLoop", recover()) == nil {
187 return
188 }
189 s.lock.Lock()
190 defer s.lock.Unlock()
191 s.running = false
192 if !firstDone {
193 close(firstReadyCh)
194 s.ready = nil
195 }
196 }()
197
198 numCPU := max(runtime.NumCPU(), 1)
199
200 for {
201 iterStart := time.Now()
202
203 s.lastCPUEpoch++
204 result := s.collectSnapshot(numCPU)
205
206 // Remove stale entries (pids that weren't seen this epoch).
207 for pid, sample := range s.lastCPUSamples {
208 if sample.Epoch < s.lastCPUEpoch {
209 delete(s.lastCPUSamples, pid)
210 }
211 }
212
213 if s.updateCacheAndCheckIdle(result, &firstDone, firstReadyCh) {
214 return
215 }
216
217 elapsed := time.Since(iterStart)
218 time.Sleep(max(ProcCacheMinSleep, ProcCachePollInterval-elapsed))
219 }
220}
221
222// lookupUID resolves a uid to a username, using the per-run cache to avoid
223// repeated syscalls for the same uid.

Callers 1

requestAndWaitMethod · 0.95

Calls 3

collectSnapshotMethod · 0.95
PanicHandlerFunction · 0.92

Tested by

no test coverage detected