예제 #1
0
파일: perftest.py 프로젝트: eddyxu/pyro
def parse_lockstat_data(filepath):
    """
    @param before_file
    @param after_file
    @return delta values of each lock contetions
    """
    def _fetch_data(fname):
        """Read a lock stat file and extract data
        """
        result = {}
        with open(fname) as fobj:
            for line in fobj:
                match = re.match(r'.+:', line)
                if match:
                    last_colon = line.rfind(':')
                    key = line[:last_colon].strip(' \t&()')
                    values = line[last_colon + 1:].strip()
                    result[key] = np.array(
                        [float(x) for x in values.split()])
        return result

    results = {}
    raw_data = _fetch_data(filepath)
    fields = ['con-bounces', 'contentions',
              'waittime-min', 'waittime-max', 'waittime-total',
              'acq-bounces', 'acquisitions',
              'holdtime-min', 'holdtime-max', 'holdtime-total']
    for k, v in raw_data.items():
        if are_all_zeros(v):
            continue
        if len(v) < len(fields):
            v = list(v)
            v.extend([0] * (len(fields) - len(v)))
        results[k] = dict(zip(fields, v))
    return results
예제 #2
0
    def test_are_all_zeros(self):
        # test list
        self.assertTrue(analysis.are_all_zeros([0, 0, 0, 0]))
        self.assertFalse(analysis.are_all_zeros([0, 1, 0, 0]))
        self.assertFalse(analysis.are_all_zeros([1, 2, 3, 4]))

        # test dict
        self.assertTrue(analysis.are_all_zeros({1: 0, 2: 0, 0: 0, 3: 0}))
        self.assertFalse(analysis.are_all_zeros({1: 0, 2: 2, 0: 0, 3: 0}))
        self.assertFalse(analysis.are_all_zeros({1: 1, 2: 2, 3: 3, 4: 4}))