Ejemplo n.º 1
0
 def run(self, cores, perf_log, with_pt, with_tthread):
     def format_arg(arg):
         if issubclass(type(arg), NCores):
             return str(arg.to_param(cores))
         return str(arg)
     args = list(map(format_arg, self.args))
     os.chdir(test_path(self.name))
     cmd = ["./" + self.command] + args
     durations = []
     log_sizes = []
     if with_tthread:
         libtthread = inspector.default_tthread_path()
     else:
         libtthread = None
     for c in cmd:
         assert type(c) is not None
     for i in range(6):
         print("$ " + " ".join(cmd) +
               (" pt" if with_pt else "") +
               (" tthread" if with_tthread else ""))
         if os.path.exists(perf_log):
             os.remove(perf_log)
         proc = inspector.run(cmd,
                              perf_command=self.perf_command,
                              processor_trace=with_pt,
                              tthread_path=libtthread,
                              perf_log=perf_log)
         status = proc.wait()
         if status.exit_code != 0:
             raise OSError("command: %s\nfailed with: %d" %
                           (" ".join(cmd), status.exit_code))
         durations.append(status.duration)
         log_sizes.append(os.path.getsize(perf_log))
     return durations, log_sizes, self.args(cores)
Ejemplo n.º 2
0
    def test_run_without_pt(self):
        sample_app = os.path.join(TEST_ROOT, "../../test/usage-test")

        with tempfile.NamedTemporaryFile() as log_file:
            process = inspector.run([sample_app],
                                    perf_command=perf_cmd(),
                                    perf_log=log_file.name,
                                    processor_trace=False)
            status = process.wait()
            self.assertEqual(0, status.exit_code)
Ejemplo n.º 3
0
    def test_run_without_pt(self):
        sample_app = os.path.join(TEST_ROOT, "../../test/usage-test")

        with tempfile.NamedTemporaryFile() as log_file:
            process = inspector.run([sample_app],
                                    perf_command=perf_cmd(),
                                    perf_log=log_file.name,
                                    processor_trace=False)
            status = process.wait()
            self.assertEqual(0, status.exit_code)
Ejemplo n.º 4
0
    def test_run(self):
        sample_app = os.path.join(TEST_ROOT, "../../test/usage-test")

        with tempfile.NamedTemporaryFile() as log_file:
            process = inspector.run([sample_app],
                                    perf_command=perf_cmd(),
                                    perf_log=log_file.name)
            status = process.wait()
            self.assertEqual(0, status.exit_code)
            self.assertEqual(-15, status.perf_exit_code)  # SIGTERM == 15
            self.assertGreater(os.path.getsize(log_file.name), 1000)
            self.assertGreater(status.duration, 0)
Ejemplo n.º 5
0
    def test_run(self):
        sample_app = os.path.join(TEST_ROOT, "../../test/usage-test")

        with tempfile.NamedTemporaryFile() as log_file:
            process = inspector.run([sample_app],
                                    perf_command=perf_cmd(),
                                    perf_log=log_file.name)
            status = process.wait()
            self.assertEqual(0, status.exit_code)
            self.assertEqual(-15, status.perf_exit_code)  # SIGTERM == 15
            self.assertGreater(os.path.getsize(log_file.name), 1000)
            self.assertGreater(status.duration, 0)
Ejemplo n.º 6
0
def main():
    if sys.version_info < (3, 0):
        abort("this script requires Python 3.x, not Python 2.x")
    args = parse_arguments()
    command = args.command + args.arguments
    try:
        process = inspector.run(command,
                                args.libtthread_path,
                                perf_command=args.perf_command,
                                perf_log=args.perf_log,
                                user=args.set_user,
                                group=args.set_group,
                                processor_trace=not args.no_processor_trace,
                                snapshot_mode=args.snapshot_mode)
        status = process.wait()
        if not args.quiet:
            msg = "%s %.7fms total" % \
                    (args.command[0], status.duration * 1000)
            print(msg)
    except Error as e:
        print("[inspector] Error while tracing: %s" % e, file=sys.stderr)
Ejemplo n.º 7
0
def main():
    if sys.version_info < (3, 0):
        abort("this script requires Python 3.x, not Python 2.x")
    args = parse_arguments()
    command = args.command + args.arguments
    try:
        process = inspector.run(command,
                                args.libtthread_path,
                                perf_command=args.perf_command,
                                perf_log=args.perf_log,
                                user=args.set_user,
                                group=args.set_group,
                                processor_trace=not args.no_processor_trace,
                                snapshot_mode=args.snapshot_mode)
        status = process.wait()
        if not args.quiet:
            msg = "%s %.7fms total" % \
                    (args.command[0], status.duration * 1000)
            print(msg)
    except Error as e:
        print("[inspector] Error while tracing: %s" % e, file=sys.stderr)
Ejemplo n.º 8
0
    def run(self, cores, perf_log, with_pt, with_tthread):
        os.chdir(test_path(self.name))
        cmd = ["./" + self.command] + self.args(cores)
        if with_tthread:
            libtthread = inspector.default_tthread_path()
        else:
            libtthread = None
        for c in cmd:
            assert type(c) is not None
        print("$ " + " ".join(cmd) +
              (" pt" if with_pt else "") +
              (" tthread" if with_tthread else ""))
        if os.path.exists(perf_log):
            os.remove(perf_log)
        cgroup_name = "inspector-%d" % os.getpid()

        with cgroups.cpuacct(cgroup_name) as cpuacct, \
                cgroups.perf_event(cgroup_name) as perf_event:
            perf = PerfStat(perf_event.name, perf_command=self.perf_command)
            perf.run()
            proc = inspector.run(cmd,
                                 perf_command=self.perf_command,
                                 processor_trace=with_pt,
                                 tthread_path=libtthread,
                                 perf_log=perf_log,
                                 perf_event_cgroup=perf_event,
                                 additional_cgroups=[cpuacct],
                                 env=self.env)
            status = proc.wait()
            if status.exit_code != 0:
                raise OSError("command: %s\nfailed with: %d" %
                              (" ".join(cmd), status.exit_code))
            perf_stats = perf.result()
            r = Result(wall_time=status.duration,
                       args=self.args(cores),
                       log_size=os.path.getsize(perf_log),
                       perf_stats=perf_stats)
            r.read_cpuacct_cgroup(cpuacct)
            r.calculate_compressed_logsize(perf_log)
        return r