class_docstr: A simple counter object that can periodically sync with a parent.
class_docstr_tok: ["A","simple","counter","object","that","can","periodically","sync","with","a","parent","."]
docstr: Return all counts tracked by this counter.
docstr_tok: ["Return","all","counts","tracked","by","this","counter","."]
code: def get_counts(self) -> Dict[str, Number]:
      """Return all counts tracked by this counter."""
      now = time.time()
      # TODO(b/144421838): use futures instead of blocking.
      if (
          self._parent
          and (now - self._last_sync_time) > self._time_delta
      ):
          with self._lock:
              counts = _prefix_keys(self._counts, self._prefix)
              # Reset the local counts, as they will be merged into the parent and the
              # cache.
              self._counts = {}
          self._cache = self._parent.increment(**counts)
          self._last_sync_time = now
  
      # Potentially prefix the keys in the counts dictionary.
      counts = _prefix_keys(self._counts, self._prefix)
  
      # If there's no prefix make a copy of the dictionary so we don't modify the
      # internal self._counts.
      if not self._prefix:
          counts = dict(counts)
  
      # Combine local counts with any parent counts.
      for key, value in self._cache.items():
          counts[key] = counts.get(key, 0) + value
  
      if self._prefix and self._return_only_prefixed:
          counts = dict(
              [
                  (key[len(self._prefix) + 1 :], value)
                  for key, value in counts.items()
                  if key.startswith(f"{self._prefix}_")
              ]
          )
      return counts
  
file_path: acme/acme/utils/counting.py
imports: import threading
  import time
  from typing import Dict, Mapping, Optional, Union
  from acme import core
label_desc: Use image node_id 3 for calling the Counter obj's underlying member method code with example usage: obj.get_counts() and returns: counts