tools/cygprofile/cluster.py
def ClusterToList(self, size_map=None):
    """Merge the clusters with the smallest distances.

    Args:
      size_map ({symbol: size} or None): Map symbol names to their size. Cluster
        growth will be stopped at MAX_CLUSTER_SIZE. If None, sizes are taken to
        be zero and cluster growth is not stopped.

    Returns:
      An ordered list of symbols from AddSymbolLists, appropriately clustered.
    """
    if size_map:
      self._symbol_size = lambda s: size_map[s]
    if not self._num_lists or not self._neighbors:
      # Some sort of trivial set of symbol lists, such as all being
      # length 1. Return an empty ordering.
      return []
    logging.info('Sorting %s neighbors', len(self._neighbors))
    self._neighbors.sort(key=lambda n: (-n.dist, n.src, n.dst))
    logging.info('Clustering...')
    count = 0
    while self._neighbors:
      count += 1
      if not (count % 1e6):
        logging.info('tock')
      neighbor = self._neighbors.pop()
      src = self.ClusterOf(neighbor.src)
      dst = self.ClusterOf(neighbor.dst)
      if (src == dst or
          src.binary_size + dst.binary_size > self.MAX_CLUSTER_SIZE):
        continue
      self.Combine(src, dst)
    if size_map:
      clusters_by_size = sorted(list(set(self._cluster_map.values())),
                                key=lambda c: -c.binary_size)
    else:
      clusters_by_size = sorted(list(set(self._cluster_map.values())),
                                key=lambda c: -len(c.syms))
    logging.info('Produced %s clusters', len(clusters_by_size))
    logging.info('Top sizes: %s', ['{}/{}'.format(len(c.syms), c.binary_size)
                                   for c in clusters_by_size[:4]])
    logging.info('Bottom sizes: %s', ['{}/{}'.format(len(c.syms), c.binary_size)
                                      for c in clusters_by_size[-4:]])
    ordered_syms = []
    for c in clusters_by_size:
      ordered_syms.extend(c.syms)
    assert len(ordered_syms) == len(set(ordered_syms)), 'Duplicated symbols!'
    return ordered_syms
Merge the clusters with the smallest distances.

    Args:
      size_map ({symbol: size} or None): Map symbol names to their size. Cluster
        growth will be stopped at MAX_CLUSTER_SIZE. If None, sizes are taken to
        be zero and cluster growth is not stopped.

    Returns:
      An ordered list of symbols from AddSymbolLists, appropriately clustered.
    
Merge the clusters with the smallest distances.
Merge the clusters with the smallest distances .
def ClusterToList(self, size_map=None):
    if size_map:
      self._symbol_size = lambda s: size_map[s]
    if not self._num_lists or not self._neighbors:
      return []
    logging.info('Sorting %s neighbors', len(self._neighbors))
    self._neighbors.sort(key=lambda n: (-n.dist, n.src, n.dst))
    logging.info('Clustering...')
    count = 0
    while self._neighbors:
      count += 1
      if not (count % 1e6):
        logging.info('tock')
      neighbor = self._neighbors.pop()
      src = self.ClusterOf(neighbor.src)
      dst = self.ClusterOf(neighbor.dst)
      if (src == dst or
          src.binary_size + dst.binary_size > self.MAX_CLUSTER_SIZE):
        continue
      self.Combine(src, dst)
    if size_map:
      clusters_by_size = sorted(list(set(self._cluster_map.values())),
                                key=lambda c: -c.binary_size)
    else:
      clusters_by_size = sorted(list(set(self._cluster_map.values())),
                                key=lambda c: -len(c.syms))
    logging.info('Produced %s clusters', len(clusters_by_size))
    logging.info('Top sizes: %s', ['{}/{}'.format(len(c.syms), c.binary_size)
                                   for c in clusters_by_size[:4]])
    logging.info('Bottom sizes: %s', ['{}/{}'.format(len(c.syms), c.binary_size)
                                      for c in clusters_by_size[-4:]])
    ordered_syms = []
    for c in clusters_by_size:
      ordered_syms.extend(c.syms)
    assert len(ordered_syms) == len(set(ordered_syms)), 'Duplicated symbols!'
    return ordered_syms
def ClusterToList ( self , size_map = None ) : if size_map : self . _symbol_size = lambda s : size_map [ s ] if not self . _num_lists or not self . _neighbors : return [ ] logging . info ( 'Sorting %s neighbors' , len ( self . _neighbors ) ) self . _neighbors . sort ( key = lambda n : ( - n . dist , n . src , n . dst ) ) logging . info ( 'Clustering...' ) count = 0 while self . _neighbors : count += 1 if not ( count % 1e6 ) : logging . info ( 'tock' ) neighbor = self . _neighbors . pop ( ) src = self . ClusterOf ( neighbor . src ) dst = self . ClusterOf ( neighbor . dst ) if ( src == dst or src . binary_size + dst . binary_size > self . MAX_CLUSTER_SIZE ) : continue self . Combine ( src , dst ) if size_map : clusters_by_size = sorted ( list ( set ( self . _cluster_map . values ( ) ) ) , key = lambda c : - c . binary_size ) else : clusters_by_size = sorted ( list ( set ( self . _cluster_map . values ( ) ) ) , key = lambda c : - len ( c . syms ) ) logging . info ( 'Produced %s clusters' , len ( clusters_by_size ) ) logging . info ( 'Top sizes: %s' , [ '{}/{}' . format ( len ( c . syms ) , c . binary_size ) for c in clusters_by_size [ : 4 ] ] ) logging . info ( 'Bottom sizes: %s' , [ '{}/{}' . format ( len ( c . syms ) , c . binary_size ) for c in clusters_by_size [ - 4 : ] ] ) ordered_syms = [ ] for c in clusters_by_size : ordered_syms . extend ( c . syms ) assert len ( ordered_syms ) == len ( set ( ordered_syms ) ) , 'Duplicated symbols!' return ordered_syms
Merge the clusters with the smallest distances.
Merge the clusters with the smallest distances .
"""Merge the clusters with the smallest distances.

    Args:
      size_map ({symbol: size} or None): Map symbol names to their size. Cluster
        growth will be stopped at MAX_CLUSTER_SIZE. If None, sizes are taken to
        be zero and cluster growth is not stopped.

    Returns:
      An ordered list of symbols from AddSymbolLists, appropriately clustered.
    """ # Some sort of trivial set of symbol lists, such as all being # length 1. Return an empty ordering.
An ordered list of symbols from AddSymbolLists, appropriately clustered.
An ordered list of symbols from AddSymbolLists appropriately clustered .
self
size_map
size_map ({symbol
size} or None): Map symbol names to their size. Cluster
growth will be stopped at MAX_CLUSTER_SIZE. If None, sizes are taken to
be zero and cluster growth is not stopped.
size } or None ) : Map symbol names to their size . Cluster growth will be stopped at MAX_CLUSTER_SIZE . If None sizes are taken to be zero and cluster growth is not stopped .