def sar()

in perfrunbook/utilities/measure_and_plot_basic_sysstat_stats.py [0:0]


def sar(time):
    """
    Measure sar into a buffer for parsing
    """
    try:
        env = dict(os.environ, S_TIME_FORMAT="ISO", LC_TIME="ISO")
        res = subprocess.run(["sar", "-o", "out.dat", "-A", "1", f"{time}"], timeout=time+5, env=env,
                             check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        res = subprocess.run(["sar", "-f", "out.dat", "-A", "1"], env=env, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        os.remove("out.dat")
        return io.StringIO(res.stdout.decode('utf-8'))
    except subprocess.CalledProcessError:
        print("Failed to measure statistics with sar.")
        print("Please check that sar is installed using install_perfrunbook_dependencies.sh and is in your PATH")
        return None