QueryWorkingSet returns working set information for a set of addresses.
(proc windows.Handle, ws []sys.MemoryWorkingSetExInformation)
| 267 | |
| 268 | // QueryWorkingSet returns working set information for a set of addresses. |
| 269 | func QueryWorkingSet(proc windows.Handle, ws []sys.MemoryWorkingSetExInformation) []sys.MemoryWorkingSetExInformation { |
| 270 | poolOnce.Do(func() { |
| 271 | var err error |
| 272 | p, err = newPool(poolSize()) |
| 273 | if err != nil { |
| 274 | log.Errorf("unable to create working set pool: %v", err) |
| 275 | } |
| 276 | }) |
| 277 | |
| 278 | if p == nil { |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | // acquire a worker and don't wait forever if pool is exhausted |
| 283 | w := p.acquire(50 * time.Millisecond) |
| 284 | if w == nil { |
| 285 | return nil // pool exhausted |
| 286 | } |
| 287 | |
| 288 | // post work to the thread |
| 289 | w.submit(proc, ws) |
| 290 | |
| 291 | // wait for completion |
| 292 | start := time.Now() |
| 293 | wait, err := w.wait() |
| 294 | if err != nil { |
| 295 | return nil |
| 296 | } |
| 297 | |
| 298 | switch wait { |
| 299 | case windows.WAIT_OBJECT_0: |
| 300 | workingsetOpsCount.Add(1) |
| 301 | // feed successful durations back |
| 302 | w.jitter.record(time.Since(start)) |
| 303 | defer p.release(w, false) |
| 304 | |
| 305 | if atomic.LoadUint32(&w.ctx.done) == 0 { |
| 306 | return nil |
| 307 | } |
| 308 | return w.ctx.ws |
| 309 | |
| 310 | case sys.WaitTimeout: |
| 311 | workingsetTimeoutCount.Add(1) |
| 312 | // thread is stalled inside the kernel syscall. |
| 313 | // Safe to terminate: no user-mode locks held, |
| 314 | // no Go runtime state to corrupt. |
| 315 | p.release(w, true) |
| 316 | return nil |
| 317 | |
| 318 | default: |
| 319 | p.release(w, true) |
| 320 | return nil |
| 321 | } |
| 322 | } |