# Path: aqmt/processes.py
# def kill_known_pids():
# def add_known_pid(pid):
# def kill_pid(pid):
# def is_running(pid):
# def waitpid(pid):
# 
# Path: aqmt/plot/collectionutil.py
# def get_tree_details(tree):
#     def traverse(branch, depthnow=0):
# def get_gap(tree):
# def get_testcases(leaf):
# def get_all_testcases_folders(tree):
#     def parse_leaf(leaf, first_set, x):
# def make_xtics(tree, xoffset, x_axis):
#     def frange(start, stop, step):
# def get_testmeta_min_max_count(leaf, x_axis):
# def get_x_coordinate(leaf, value, x_axis):
# def merge_testcase_data_set_x(testcases, x_axis):
# def get_leaf_tests_stats(leaf, statsname):
# def merge_testcase_data(leaf, statsname, x_axis):
# def merge_testcase_data_group(leaf, statsname, x_axis):
# def get_xlabel(tree):
#     def fn(leaf, first_set, x):
# def pt_generator():
#     def get_val(tag):
# 
# Path: aqmt/plot/treeutil.py
# def get_depth_sizes(tree):
#     def check_node(item, x, depth):
# def walk_leaf(tree, fn):
#     def walk(branch):
# def walk_tree_reverse(tree, fn):
#     def walk(branch, depth=0):
# def walk_tree(tree, fn, include_leaf_collection=False):
#     def walk(collection, depth=0):
# def swap_levels(tree, level=0):
#         def walk(branch, depth):
#     def check_level(node, x, depth):
#     def build_swap(node, x, depth):
# def build_swap_list(level_order):
# def reorder_levels(tree, level_order=None):
# def skip_levels(tree, number_of_levels):
# 
# Path: aqmt/plot/common.py
# def add_plot(gpi):
#     """
#     Remove trailing comma from plot command because gnuplot complains about it
#     (We use the trailing comma to easier build plot commands)
#     """
#     return re.sub(r',(\s*\\?\s*\\?\s*)$', '\g<1>', gpi)
# 
# def add_scale(y_logarithmic, range_from=None, range_from_log=None,
#         range_to=None, range_to_log=None):
#     if y_logarithmic:
#         if range_from_log is None:
#             range_from_log = '1'
#         if range_to_log is None:
#             range_to_log = '*'
#         return """
#             set logscale y
#             set yrange [""" + range_from_log + """:""" + range_to_log + """]
#             """
#     else:
#         if range_from is None:
#             range_from = '0'
#         if range_to is None:
#             range_to = '1<*'
#         return """
#             set yrange [""" + range_from + """:""" + range_to + """]
#             """


from plumbum.cmd import dstat, bash
from aqmt import processes
from aqmt.plot import collectionutil, treeutil
from aqmt.plot.common import add_plot, add_scale
import os
                with open(testcase_folder + '/dstat.log') as f:
                    for line in f:
                        if skip > 0:
                            skip -= 1
                            continue

                        line = line.split(',')
                        for i, field in enumerate(fields):
                            items[i].append(float(line[field]))

                # for simplicity we take the second half of the list
                items = [x[int(len(x)/2):] for x in items]
                return ' '.join([str(sum(x)/len(x)) for x in items])

            gpi += """
                $data_int_csw""" + str(x) + """ << EOD
                """ + collectionutil.merge_testcase_data(subtree, parse_int_csw, plotdef.x_axis) + """
                EOD
                """

            xpos = '($1+%s)' % str(x)
            xtic = "" if plotdef.custom_xtics else ":xtic(2)"
            plot_gpi += ("""\\
                %s   using """ + xpos + """:3%s  with linespoints lc 1 pt 7 ps 0.4 lw 1.5 """ + ("title 'interrupts'       " if add_title else 'notitle') + """, \\
                ''   using """ + xpos + """:4    with linespoints lc 2 pt 7 ps 0.4 lw 1.5 """ + ("title 'context switches' " if add_title else 'notitle') + """, \\
                """) % ("$data_int_csw" + str(x), xtic)

        treeutil.walk_leaf(tree, leaf)
        gpi += """
            plot \\

# Path: aqmt/processes.py
# def kill_known_pids():
# def add_known_pid(pid):
# def kill_pid(pid):
# def is_running(pid):
# def waitpid(pid):
# 
# Path: aqmt/plot/collectionutil.py
# def get_tree_details(tree):
#     def traverse(branch, depthnow=0):
# def get_gap(tree):
# def get_testcases(leaf):
# def get_all_testcases_folders(tree):
#     def parse_leaf(leaf, first_set, x):
# def make_xtics(tree, xoffset, x_axis):
#     def frange(start, stop, step):
# def get_testmeta_min_max_count(leaf, x_axis):
# def get_x_coordinate(leaf, value, x_axis):
# def merge_testcase_data_set_x(testcases, x_axis):
# def get_leaf_tests_stats(leaf, statsname):
# def merge_testcase_data(leaf, statsname, x_axis):
# def merge_testcase_data_group(leaf, statsname, x_axis):
# def get_xlabel(tree):
#     def fn(leaf, first_set, x):
# def pt_generator():
#     def get_val(tag):
# 
# Path: aqmt/plot/treeutil.py
# def get_depth_sizes(tree):
#     def check_node(item, x, depth):
# def walk_leaf(tree, fn):
#     def walk(branch):
# def walk_tree_reverse(tree, fn):
#     def walk(branch, depth=0):
# def walk_tree(tree, fn, include_leaf_collection=False):
#     def walk(collection, depth=0):
# def swap_levels(tree, level=0):
#         def walk(branch, depth):
#     def check_level(node, x, depth):
#     def build_swap(node, x, depth):
# def build_swap_list(level_order):
# def reorder_levels(tree, level_order=None):
# def skip_levels(tree, number_of_levels):
# 
# Path: aqmt/plot/common.py
# def add_plot(gpi):
#     """
#     Remove trailing comma from plot command because gnuplot complains about it
#     (We use the trailing comma to easier build plot commands)
#     """
#     return re.sub(r',(\s*\\?\s*\\?\s*)$', '\g<1>', gpi)
# 
# def add_scale(y_logarithmic, range_from=None, range_from_log=None,
#         range_to=None, range_to_log=None):
#     if y_logarithmic:
#         if range_from_log is None:
#             range_from_log = '1'
#         if range_to_log is None:
#             range_to_log = '*'
#         return """
#             set logscale y
#             set yrange [""" + range_from_log + """:""" + range_to_log + """]
#             """
#     else:
#         if range_from is None:
#             range_from = '0'
#         if range_to is None:
#             range_to = '1<*'
#         return """
#             set yrange [""" + range_from + """:""" + range_to + """]
#             """


# Path: aqmt/plugins/dstat.py
from plumbum.cmd import dstat, bash
from aqmt import processes
from aqmt.plot import collectionutil, treeutil
from aqmt.plot.common import add_plot, add_scale
import os

                with open(testcase_folder + '/dstat.log') as f:
                    for line in f:
                        if skip > 0:
                            skip -= 1
                            continue

                        line = line.split(',')
                        for i, field in enumerate(fields):
                            items[i].append(float(line[field]))

                # for simplicity we take the second half of the list
                items = [x[int(len(x)/2):] for x in items]
                return ' '.join([str(sum(x)/len(x)) for x in items])

            gpi += """
                $data_int_csw""" + str(x) + """ << EOD
                """ + collectionutil.merge_testcase_data(subtree, parse_int_csw, plotdef.x_axis) + """
                EOD
                """

            xpos = '($1+%s)' % str(x)
            xtic = "" if plotdef.custom_xtics else ":xtic(2)"
            plot_gpi += ("""\\
                %s   using """ + xpos + """:3%s  with linespoints lc 1 pt 7 ps 0.4 lw 1.5 """ + ("title 'interrupts'       " if add_title else 'notitle') + """, \\
                ''   using """ + xpos + """:4    with linespoints lc 2 pt 7 ps 0.4 lw 1.5 """ + ("title 'context switches' " if add_title else 'notitle') + """, \\
                """) % ("$data_int_csw" + str(x), xtic)

        treeutil.walk_leaf(tree, leaf)
        gpi += """
            plot \\

            """ + add_plot(plot_gpi)