code: def collect(self, file=sys.stderr):
          
          cur = gcstats()
          Ncur = len(cur)
          if self.stats is not None and file is not None:
              prev = self.stats
              Nprev = self.ntypes  # may be less than len(prev)
  
              if Ncur != Nprev:
                  print("# Types %d -> %d" % (Nprev, Ncur), file=file)
  
              Scur, Sprev, first = set(cur), set(prev), True
              for T in Scur - Sprev:  # new types
                  if first:
                      print('New Types', file=file)
                      first = False
                  print(' ', T, cur[T], file=file)
  
              first = True
              for T in Sprev - Scur:  # collected types
                  if first:
                      print('Cleaned Types', file=file)
                      first = False
                  print(' ', T, -prev[T], file=file)
  
              first = True
              for T in Scur & Sprev:
                  if cur[T] == prev[T]:
                      continue
                  if first:
                      print('Known Types', file=file)
                      first = False
                  print(' ', T, cur[T], 'delta', cur[T] - prev[T], file=file)
  
          else:  # first call
              print("All Types", file=file)
              for T, C in cur.items():
                  print(' ', T, C, file=file)
  
          self.stats, self.ntypes = cur, len(cur)
docs: Collect stats and print results to file
  
          :param file: A writable file-like object