예제 #1
0
    def test_trans_top_data_to_curves(self):
        data = {1: {'a': 100, 'b': 1000},
                2: {'a': 40, 'b': 200, 'c': 300},
                3: {'a': 50, 'd': 20}}
        # Only output common part
        curves = perftest.trans_top_data_to_curves(data)
        self.assertEquals([([1, 2, 3], [100, 40, 50], 'a')], curves)

        # All fields ever occured
        expected_curves = [([1, 2, 3], [100, 40, 50], 'a'),
                           ([1, 2, 3], [1000, 200, 0], 'b'),
                           ([1, 2, 3], [0, 300, 0], 'c'),
                           ([1, 2, 3], [0, 0, 20], 'd')]
        curves = perftest.trans_top_data_to_curves(data, show_all=True)
        for curve in curves:
            self.assertTrue(curve in expected_curves)
        self.assertTrue(len(curves), len(expected_curves))
예제 #2
0
def plot_lock_result(args):
    """Plot lockstat results
    """
    def _merge_lock_data(curves_by_name, key, lc):
        if key not in curves_by_name:
            curves_by_name[key] = (lc[0], np.array(lc[1]), key)
        else:
            curves_by_name[key] = (lc[0], curves_by_name[key][1] + lc[1], key)

    outdir = output_dir(args.dir)
    files = glob.glob(args.dir + '/*_lockstat.txt')
    result = analysis.Result()
    test = ''
    for filename in files:
        fields = parse_filename(os.path.basename(filename))
        test = fields[0]
        # print(fields)
        if test == 'ncpu':
            fs = fields[2]
            workload = fields[3]
            x_value = int(fields[6])
        else:
            fs = fields[1]
            workload = fields[2]
            if test == 'multifs':
                x_value = int(fields[3])
            else:
                x_value = int(fields[5])
        lock_data = perftest.parse_lockstat_data(filename)
        result[fs, workload, x_value] = lock_data

    xlabel = '# of cores'
    ylabel = 'Samples'
    xticks = None
    ylim = None
    if test == 'multifs':
        xlabel = '# of Disks'
        xticks = [[1, 2, 3, 4], [1, 2, 3, 4]]
        xlim = (0, 5)
    output_prefix = os.path.join(outdir, os.path.basename(args.dir))
    for fs in result:
        for wl in result[fs]:
            plot_data = {}
            first_nproc = list(result[fs, wl].keys())[0]
            first_func = list(result[fs, wl, first_nproc].keys())[0]
            fields = list(result[fs, wl, first_nproc, first_func].keys())
            for nproc in result[fs, wl]:
                for field in fields:
                    if field not in plot_data:
                        plot_data[field] = {}
                    top_n = 10
                    top_lock_data = perftest.get_top_n_locks(
                        result[fs, wl, nproc], field, top_n)
                    # print(top_lock_data)
                    plot_data[field][nproc] = top_lock_data
            for field in plot_data:
                top_lock_curves = perftest.trans_top_data_to_curves(
                    plot_data[field], top_n=5)
                # if not top_lock_curves:
                #    continue
                top_curves_by_name = {}
                for lc in top_lock_curves:
                    if lc[2].startswith('cpufreq_'):
                        continue
                    if ')' in lc[2]:
                        lc = (lc[0], lc[1], lc[2].split(')')[0])

                    key = lc[2]
                    if lc[2].startswith('dentry->'):
                        key = key.split('.')[0]
                    elif lc[2].startswith('journal->j_state_lock'):
                        key = 'journal->j_state_lock'
                    elif key.startswith('type->i_mutex_dir_key'):
                        key = 'i_mutex_dir_key'
                    _merge_lock_data(top_curves_by_name, key, lc)
                top_curves = list(top_curves_by_name.values())
                # print(top_curves)
                if not top_curves:
                    continue
                outfile = output_prefix + \
                    '_%s_%s_%s_lockstat.%s' % (fs, wl, field, args.ext)
                plot.plot(top_curves, 'Lockstat (%s)' % field,
                          xlabel, ylabel, outfile, xticks=xticks, xlim=xlim)