Beispiel #1
0
  def test_norange(self):
    ranges = ExclusiveRangeDict(self.TestAttribute)

    result = []
    for begin, end, attr in ranges.iter_range(20, 20):
      result.append({'begin': begin, 'end':end, 'attr':attr.get()})
    expected = []
    self.assertEqual(expected, result)
Beispiel #2
0
  def test_set(self):
    ranges = ExclusiveRangeDict(self.TestAttribute)
    for begin, end, attr in ranges.iter_range(20, 30):
      attr.set(12)
    for begin, end, attr in ranges.iter_range(30, 40):
      attr.set(52)

    result = []
    for begin, end, attr in ranges.iter_range(20, 40):
      result.append({'begin': begin, 'end':end, 'attr':attr.get()})
    expected = [
        {'begin': 20, 'end': 30, 'attr': 12},
        {'begin': 30, 'end': 40, 'attr': 52},
        ]
    self.assertEqual(expected, result)
Beispiel #3
0
  def test_split(self):
    ranges = ExclusiveRangeDict(self.TestAttribute)
    for begin, end, attr in ranges.iter_range(20, 30):
      attr.set(1000)
    for begin, end, attr in ranges.iter_range(30, 40):
      attr.set(2345)
    for begin, end, attr in ranges.iter_range(40, 50):
      attr.set(3579)

    result1 = []
    for begin, end, attr in ranges.iter_range(25, 45):
      result1.append({'begin': begin, 'end':end, 'attr':attr.get()})
    expected1 = [
        {'begin': 25, 'end': 30, 'attr': 1000},
        {'begin': 30, 'end': 40, 'attr': 2345},
        {'begin': 40, 'end': 45, 'attr': 3579},
        ]
    self.assertEqual(expected1, result1)

    result2 = []
    for begin, end, attr in ranges.iter_range(20, 50):
      result2.append({'begin': begin, 'end':end, 'attr':attr.get()})
    expected2 = [
        {'begin': 20, 'end': 25, 'attr': 1000},
        {'begin': 25, 'end': 30, 'attr': 1000},
        {'begin': 30, 'end': 40, 'attr': 2345},
        {'begin': 40, 'end': 45, 'attr': 3579},
        {'begin': 45, 'end': 50, 'attr': 3579},
        ]
    self.assertEqual(expected2, result2)
Beispiel #4
0
  def test_fill(self):
    ranges = ExclusiveRangeDict(self.TestAttribute)
    for begin, end, attr in ranges.iter_range(30, 35):
      attr.set(12345)
    for begin, end, attr in ranges.iter_range(40, 45):
      attr.set(97531)

    result = []
    for begin, end, attr in ranges.iter_range(25, 50):
      result.append({'begin': begin, 'end':end, 'attr':attr.get()})
    expected = [
        {'begin': 25, 'end': 30, 'attr': 0},
        {'begin': 30, 'end': 35, 'attr': 12345},
        {'begin': 35, 'end': 40, 'attr': 0},
        {'begin': 40, 'end': 45, 'attr': 97531},
        {'begin': 45, 'end': 50, 'attr': 0},
        ]
    self.assertEqual(expected, result)
Beispiel #5
0
    def _output(dumps, bucket_set, policy, out):
        """Prints all stacktraces in a given component of given depth.

    Args:
        dumps: A list of Dump objects.
        bucket_set: A BucketSet object.
        policy: A Policy object.
        out: An IO object to output.
    """
        max_dump_count = 0
        range_dict = ExclusiveRangeDict(ListAttribute)
        for dump in dumps:
            max_dump_count = max(max_dump_count, dump.count)
            for key, value in dump.iter_map:
                for begin, end, attr in range_dict.iter_range(key[0], key[1]):
                    attr[dump.count] = value

        max_dump_count_digit = len(str(max_dump_count))
        for begin, end, attr in range_dict.iter_range():
            out.write('%x-%x\n' % (begin, end))
            if len(attr) < max_dump_count:
                attr[max_dump_count] = None
            for index, value in enumerate(attr[1:]):
                out.write('  #%0*d: ' % (max_dump_count_digit, index + 1))
                if not value:
                    out.write('None\n')
                elif value[0] == 'hooked':
                    component_match, _ = policy.find_mmap(value, bucket_set)
                    out.write('%s @ %d\n' %
                              (component_match, value[1]['bucket_id']))
                else:
                    component_match = policy.find_unhooked(value)
                    region_info = value[1]
                    size = region_info['committed']
                    out.write(
                        '%s [%d bytes] %s%s%s%s %s\n' %
                        (component_match, size, value[1]['vma']['readable'],
                         value[1]['vma']['writable'],
                         value[1]['vma']['executable'],
                         value[1]['vma']['private'], value[1]['vma']['name']))
Beispiel #6
0
  def _output(dumps, bucket_set, policy, out):
    """Prints all stacktraces in a given component of given depth.

    Args:
        dumps: A list of Dump objects.
        bucket_set: A BucketSet object.
        policy: A Policy object.
        out: An IO object to output.
    """
    max_dump_count = 0
    range_dict = ExclusiveRangeDict(ListAttribute)
    for dump in dumps:
      max_dump_count = max(max_dump_count, dump.count)
      for key, value in dump.iter_map:
        for begin, end, attr in range_dict.iter_range(key[0], key[1]):
          attr[dump.count] = value

    max_dump_count_digit = len(str(max_dump_count))
    for begin, end, attr in range_dict.iter_range():
      out.write('%x-%x\n' % (begin, end))
      if len(attr) < max_dump_count:
        attr[max_dump_count] = None
      for index, value in enumerate(attr[1:]):
        out.write('  #%0*d: ' % (max_dump_count_digit, index + 1))
        if not value:
          out.write('None\n')
        elif value[0] == 'hooked':
          component_match, _ = policy.find_mmap(value, bucket_set)
          out.write('%s @ %d\n' % (component_match, value[1]['bucket_id']))
        else:
          component_match = policy.find_unhooked(value)
          region_info = value[1]
          size = region_info['committed']
          out.write('%s [%d bytes] %s%s%s%s %s\n' % (
              component_match, size, value[1]['vma']['readable'],
              value[1]['vma']['writable'], value[1]['vma']['executable'],
              value[1]['vma']['private'], value[1]['vma']['name']))
Beispiel #7
0
    def __init__(self, path, modified_time):
        self._path = path
        matched = self._PATH_PATTERN.match(path)
        self._pid = int(matched.group(2))
        self._count = int(matched.group(3))
        self._time = modified_time
        self._map = {}
        self._procmaps = ExclusiveRangeDict(ProcMapsEntryAttribute)
        self._stacktrace_lines = []
        self._global_stats = {}  # used only in apply_policy

        self._run_id = ''
        self._pagesize = 4096
        self._pageframe_length = 0
        self._pageframe_encoding = ''
        self._has_pagecount = False

        self._version = ''
        self._lines = []