class_docstr: This class asynchronously reads the performance counters to calculate
  the system load on Windows.  A "raw" thread is used here to prevent
  interference with the test suite's cases for the threading module.
class_docstr_tok: ["This","class","asynchronously","reads","the","performance","counters","to","calculate","the","system","load","on","Windows",".","A","``","raw","''","thread","is","used","here","to","prevent","interference","with","the","test","suite","'s","cases","for","the","threading","module","."]
code: def _calculate_load(
      self,
      # localize module access to prevent shutdown errors
      _query=winreg.QueryValueEx,
      _hkey=winreg.HKEY_PERFORMANCE_DATA,
      _unpack=struct.unpack_from,
  ):
      # get the 'System' object
      data, _ = _query(_hkey, "2")
      # PERF_DATA_BLOCK {
      #   WCHAR Signature[4]      8 +
      #   DWOWD LittleEndian      4 +
      #   DWORD Version           4 +
      #   DWORD Revision          4 +
      #   DWORD TotalByteLength   4 +
      #   DWORD HeaderLength      = 24 byte offset
      #   ...
      # }
      (obj_start,) = _unpack("L", data, 24)
      # PERF_OBJECT_TYPE {
      #   DWORD TotalByteLength
      #   DWORD DefinitionLength
      #   DWORD HeaderLength
      #   ...
      # }
      data_start, defn_start = _unpack("4xLL", data, obj_start)
      data_base = obj_start + data_start
      defn_base = obj_start + defn_start
      # find the 'Processor Queue Length' counter (index=44)
      while defn_base < data_base:
          # PERF_COUNTER_DEFINITION {
          #   DWORD ByteLength
          #   DWORD CounterNameTitleIndex
          #   ... [7 DWORDs/28 bytes]
          #   DWORD CounterOffset
          # }
          size, idx, offset = _unpack("LL28xL", data, defn_base)
          defn_base += size
          if idx == 44:
              counter_offset = data_base + offset
              # the counter is known to be PERF_COUNTER_RAWCOUNT (DWORD)
              (processor_queue_length,) = _unpack(
                  "L", data, counter_offset
              )
              break
      else:
          return
  
      # We use an exponentially weighted moving average, imitating the
      # load calculation on Unix systems.
      # https://en.wikipedia.org/wiki/Load_(computing)#Unix-style_load_calculation
      # https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
      if self._load is not None:
          self._load = (
              self._load * LOAD_FACTOR_1
              + processor_queue_length * (1.0 - LOAD_FACTOR_1)
          )
      elif len(self._values) < NVALUE:
          self._values.append(processor_queue_length)
      else:
          self._load = sum(self._values) / len(self._values)
  
file_path: cpython/Lib/test/libregrtest/win_utils.py
imports: import _overlapped
  import _thread
  import _winapi
  import math
  import struct
  import winreg
label_desc: Use image node_id 3 for calling the WindowsLoadTracker obj's underlying member method code with example usage: obj._calculate_load(_query, _hkey, _unpack) without return types