parameters: (self, mmap)
docstring: Updates the |Allocation|.|resident_size|s by looking at mmap stats.
  
      Not all the allocated memory is always used (read: resident). This function
      estimates the resident size of an allocation intersecting the mmaps dump.
docstring_summary: Updates the |Allocation|.|resident_size|s by looking at mmap stats.
docstring_tokens: Updates the |Allocation| . |resident_size|s by looking at mmap stats .
function: def CalculateResidentSize(self, mmap):
      """Updates the |Allocation|.|resident_size|s by looking at mmap stats.
  
      Not all the allocated memory is always used (read: resident). This function
      estimates the resident size of an allocation intersecting the mmaps dump.
      """
      assert(isinstance(mmap, memory_map.Map))
      for alloc in self.allocations:
        # This function loops over all the memory pages that intersect, partially
        # or fully, with each allocation. For each of them, the allocation  is
        # attributed a resident size equal to the size of intersecting range iff
        # the page is resident.
        # The tricky part is that, in the general case, an allocation can span
        # over multiple (contiguous) mmaps. See the chart below for a reference:
        #
        # VA space:  |0    |4k   |8k   |12k  |16k  |20k  |24k  |28k  |32k  |
        # Mmaps:     [   mm 1   ][ mm2 ]           [          map 3        ]
        # Allocs:      <a1>  <  a2  >                       <      a3      >
        #
        # Note: this accounting technique is not fully correct but is generally a
        # good tradeoff between accuracy and speed of profiling. The OS provides
        # resident information with the page granularity (typ. 4k). Finer values
        # would require more fancy techniques based, for instance, on run-time
        # instrumentation tools like Valgrind or *sanitizer.
        cur_start = alloc.start
        mm = None
        while cur_start < alloc.end:
          if not mm or not mm.Contains(cur_start):
            mm = mmap.Lookup(cur_start)
          if mm:
            page, page_off = mm.GetRelativeMMOffset(cur_start)
            if mm.IsPageResident(page):
              page_end = mm.start + page * PAGE_SIZE + PAGE_SIZE - 1
              alloc_memory_in_current_page = PAGE_SIZE - page_off
              if alloc.end < page_end:
                alloc_memory_in_current_page -= page_end - alloc.end
              alloc.resident_size += alloc_memory_in_current_page
          # Move to the next page boundary.
          cur_start = (cur_start + PAGE_SIZE) & ~(PAGE_SIZE - 1)
function_tokens: def CalculateResidentSize ( self , mmap ) : assert ( isinstance ( mmap , memory_map . Map ) ) for alloc in self . allocations : # This function loops over all the memory pages that intersect, partially # or fully, with each allocation. For each of them, the allocation  is # attributed a resident size equal to the size of intersecting range iff # the page is resident. # The tricky part is that, in the general case, an allocation can span # over multiple (contiguous) mmaps. See the chart below for a reference: # # VA space:  |0    |4k   |8k   |12k  |16k  |20k  |24k  |28k  |32k  | # Mmaps:     [   mm 1   ][ mm2 ]           [          map 3        ] # Allocs:      <a1>  <  a2  >                       <      a3      > # # Note: this accounting technique is not fully correct but is generally a # good tradeoff between accuracy and speed of profiling. The OS provides # resident information with the page granularity (typ. 4k). Finer values # would require more fancy techniques based, for instance, on run-time # instrumentation tools like Valgrind or *sanitizer. cur_start = alloc . start mm = None while cur_start < alloc . end : if not mm or not mm . Contains ( cur_start ) : mm = mmap . Lookup ( cur_start ) if mm : page , page_off = mm . GetRelativeMMOffset ( cur_start ) if mm . IsPageResident ( page ) : page_end = mm . start + page * PAGE_SIZE + PAGE_SIZE - 1 alloc_memory_in_current_page = PAGE_SIZE - page_off if alloc . end < page_end : alloc_memory_in_current_page -= page_end - alloc . end alloc . resident_size += alloc_memory_in_current_page # Move to the next page boundary. cur_start = ( cur_start + PAGE_SIZE ) & ~ ( PAGE_SIZE - 1 )