tools/dump_process_memory/analyze_dumps.py
def _GetStatsFromFileDump(filename):
  """Computes per-dump statistics.

  Args:
    filename: (str) Path to the dump.

  Returns:
    MappingStats for the mapping.
  """
  # Dump integrity checks.
  metadata_filename = filename + '.metadata'
  pid_start_end = os.path.basename(filename)[:-len('.dump')]
  (_, start, end) = [int(x, 10) for x in pid_start_end.split('-')]
  file_stat = os.stat(filename)
  assert start % PAGE_SIZE == 0
  assert end % PAGE_SIZE == 0
  assert file_stat.st_size == (end - start)
  metadata_file_stat = os.stat(metadata_filename)
  result = MappingStats(filename, start, end)
  # each line is [01]{2}\n, eg '10\n', 1 line per page.
  assert metadata_file_stat.st_size == 3 * result.pages

  with open(filename, 'r') as f, open(metadata_filename, 'r') as metadata_f:
    for i in range(result.pages):
      page = _ReadPage(f)
      assert len(page) == 1024
      for x in page:
        if x in FREED_PATTERNS:
          result.freed[FREED_PATTERNS[x]] += 4
      is_zero = max(page) == 0
      present, swapped = (bool(int(x)) for x in metadata_f.readline().strip())
      # Not present, not swapped private anonymous == lazily initialized zero
      # page.
      if not present and not swapped:
        assert is_zero
      result.is_zero[i] = is_zero
      result.is_present[i] = present
      result.is_swapped[i] = swapped
      if not is_zero:
        sha1 = hashlib.sha1()
        sha1.update(page)
        page_hash = sha1.digest()
        result.hashes[i] = page_hash
        compressed = zlib.compress(page, 1)
        result.compressed_size[i] = len(compressed)
  return result
Computes per-dump statistics.

  Args:
    filename: (str) Path to the dump.

  Returns:
    MappingStats for the mapping.
  
Computes per-dump statistics.
Computes per - dump statistics .
def _GetStatsFromFileDump(filename):
  metadata_filename = filename + '.metadata'
  pid_start_end = os.path.basename(filename)[:-len('.dump')]
  (_, start, end) = [int(x, 10) for x in pid_start_end.split('-')]
  file_stat = os.stat(filename)
  assert start % PAGE_SIZE == 0
  assert end % PAGE_SIZE == 0
  assert file_stat.st_size == (end - start)
  metadata_file_stat = os.stat(metadata_filename)
  result = MappingStats(filename, start, end)
  assert metadata_file_stat.st_size == 3 * result.pages
  with open(filename, 'r') as f, open(metadata_filename, 'r') as metadata_f:
    for i in range(result.pages):
      page = _ReadPage(f)
      assert len(page) == 1024
      for x in page:
        if x in FREED_PATTERNS:
          result.freed[FREED_PATTERNS[x]] += 4
      is_zero = max(page) == 0
      present, swapped = (bool(int(x)) for x in metadata_f.readline().strip())
      if not present and not swapped:
        assert is_zero
      result.is_zero[i] = is_zero
      result.is_present[i] = present
      result.is_swapped[i] = swapped
      if not is_zero:
        sha1 = hashlib.sha1()
        sha1.update(page)
        page_hash = sha1.digest()
        result.hashes[i] = page_hash
        compressed = zlib.compress(page, 1)
        result.compressed_size[i] = len(compressed)
  return result
def _GetStatsFromFileDump ( filename ) : metadata_filename = filename + '.metadata' pid_start_end = os . path . basename ( filename ) [ : - len ( '.dump' ) ] ( _ , start , end ) = [ int ( x , 10 ) for x in pid_start_end . split ( '-' ) ] file_stat = os . stat ( filename ) assert start % PAGE_SIZE == 0 assert end % PAGE_SIZE == 0 assert file_stat . st_size == ( end - start ) metadata_file_stat = os . stat ( metadata_filename ) result = MappingStats ( filename , start , end ) assert metadata_file_stat . st_size == 3 * result . pages with open ( filename , 'r' ) as f , open ( metadata_filename , 'r' ) as metadata_f : for i in range ( result . pages ) : page = _ReadPage ( f ) assert len ( page ) == 1024 for x in page : if x in FREED_PATTERNS : result . freed [ FREED_PATTERNS [ x ] ] += 4 is_zero = max ( page ) == 0 present , swapped = ( bool ( int ( x ) ) for x in metadata_f . readline ( ) . strip ( ) ) if not present and not swapped : assert is_zero result . is_zero [ i ] = is_zero result . is_present [ i ] = present result . is_swapped [ i ] = swapped if not is_zero : sha1 = hashlib . sha1 ( ) sha1 . update ( page ) page_hash = sha1 . digest ( ) result . hashes [ i ] = page_hash compressed = zlib . compress ( page , 1 ) result . compressed_size [ i ] = len ( compressed ) return result
Computes per-dump statistics.
Computes per - dump statistics .
"""Computes per-dump statistics.

  Args:
    filename: (str) Path to the dump.

  Returns:
    MappingStats for the mapping.
  """ # Dump integrity checks. # each line is [01]{2}\n, eg '10\n', 1 line per page. # Not present, not swapped private anonymous == lazily initialized zero # page.
MappingStats for the mapping.
MappingStats for the mapping .
filename
(str) Path to the dump.
( str ) Path to the dump .