code: def annotate_snapshot(self, snapshot):
          
          if hasattr(snapshot, 'classes'):
              return
  
          snapshot.classes = {}
  
          for classname in list(self.index.keys()):
              total = 0
              active = 0
              merged = Asized(0, 0)
              for tobj in self.index[classname]:
                  _merge_objects(snapshot.timestamp, merged, tobj)
                  total += tobj.get_size_at_time(snapshot.timestamp)
                  if tobj.birth < snapshot.timestamp and \
                      (tobj.death is None or tobj.death > snapshot.timestamp):
                      active += 1
  
              try:
                  pct = total * 100.0 / snapshot.total
              except ZeroDivisionError: # pragma: no cover
                  pct = 0
              try:
                  avg = total / active
              except ZeroDivisionError:
                  avg = 0
  
              snapshot.classes[classname] = dict(sum=total,
                                                 avg=avg,
                                                 pct=pct,
                                                 active=active)
              snapshot.classes[classname]['merged'] = merged
docs: Store additional statistical data in snapshot.