From b83d76309f3f9ad9d6d7125df0ae640d9e297b6d Mon Sep 17 00:00:00 2001 From: Kevin Pouget <kevin.pouget@imag.fr> Date: Fri, 19 Feb 2016 16:44:55 +0100 Subject: [PATCH] add breakpoint creating time to benchmarks --- __init__.py | 16 ++++++-- mcgdb_testing/native_gdb.py | 74 ++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/__init__.py b/__init__.py index f31efd0..dc82c4b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,7 @@ import pkgutil, importlib, difflib # standard lib packages import sys, subprocess, shlex, fcntl, os, time, errno # standard lib packages import logging; log = logging.getLogger(__name__) +import traceback EXPECTED_FILE_PREFIX = "file://" @@ -38,7 +39,8 @@ def all_subpackages(pkg_prefix, verbose, what_to_run, parent, prefix=""): run_module(verbose, modname, mod, getattr(mod, what)) except Exception as e: log.warn("{} failed {}".format(modname, e)) - + #traceback.print_exc() + def main(pkg_prefix, module=None, benchmark=True, test=True, verbose=False, help=False): what_to_run = [] @@ -276,21 +278,27 @@ class GDB_Instance: output = self.execute("python print({})".format(name)) - + value = output.out[:-1] if GDB_Instance.CSV_mode: - print(output.out[:-1], end=", ", flush=True) + print(value, end=", ", flush=True) else: output.print_all() + + return value + def save_value(self, name, format, unit): if GDB_Instance.CSV_header: return output = self.execute('printf "{format}{unit}\\n", {name}'.format( name=name, format=format, unit=unit)) + value = output.out[:-1] if GDB_Instance.CSV_mode: - print(output.out[:-1], end=", ", flush=True) + print(value, end=", ", flush=True) else: output.print_all() + + return value def _read_til_prompt(self, command): if command is not None: diff --git a/mcgdb_testing/native_gdb.py b/mcgdb_testing/native_gdb.py index b6cb324..13a2395 100644 --- a/mcgdb_testing/native_gdb.py +++ b/mcgdb_testing/native_gdb.py @@ -1,5 +1,4 @@ from gdb_tester import * -import mcgdb gdb = None @@ -9,7 +8,7 @@ def run(what, run="run"): gdb.execute(run) gdb.execute("up") - gdb.save_value("us_busy_once", "%1.f", "us") + return gdb.save_value("us_busy_once", "%1.f", "us") def nominal_time(): run("Nominal time") @@ -39,6 +38,7 @@ PARAMETERS = [ 'int(gdb.parse_and_eval("it"))', 'int(gdb.newest_frame().older().read_var("i"))' ] + def gdb_py_breakpoint_parameter(params_choice): params = [par for i, par in enumerate(PARAMETERS) if params_choice & (1 << i)] @@ -56,17 +56,81 @@ class TestBP(gdb.Breakpoint): TestBP() end """.format(params="\n ".join(params))) + run("Py BP param {:02b}".format(params_choice)[2:]) return to_run + +ref_time_set_bp = None +def do_nothing(): + global ref_time_set_bp + + assert ref_time_set_bp is None + ref_time_set_bp = set_breakpoints(nb_bp=0) + ref_time_set_bp = float(ref_time_set_bp[:-2]) + +def set_breakpoints(nb_bp=1000): + assert not (ref_time_set_bp is None and nb_bp != 0) + gdb.execute("py import sys; sys.path.append('/home/kevin/travail/Python')") + gdb.execute("py import mcgdb") + + gdb.execute("""python +class VoidBP(gdb.Breakpoint): + def __init__(self, addr): + gdb.Breakpoint.__init__(self, "*{{}}".format(addr), internal=True) + #self.silent=True + +class TestBP(mcgdb.capture.FunctionBreakpoint): + def __init__(self): + mcgdb.capture.FunctionBreakpoint.__init__(self, "action") + + def prepare_before (self): + NB_BP = {np_bp} + print("create breakpoints") + start_addr = int(gdb.parse_and_eval("main").address) + + bps = [] + for addr in range(start_addr, start_addr+NB_BP): + bps.append(VoidBP(addr)) + + return (False, True, bps) + + def prepare_after(self, bps): + print("delete all") + for bp in bps: + bp.delete() + return False + +TestBP() +end +""".format(np_bp=nb_bp)) + gdb.execute("start") + gdb.execute("set var it_count = 10") + + exec_time = run("set {} breakpoints".format(nb_bp), run="continue") + + if nb_bp != 0: + gdb.execute('pi bp_create_time = float(gdb.parse_and_eval("us_busy_once"))') + + + gdb.execute('pi bp_create_time -= {}'.format(ref_time_set_bp)) + + print(gdb.execute('pi print("Soit {:.2f}us".format(bp_create_time))')[1]) + gdb.execute("pi bp_create_time /= {}".format(nb_bp)) + + print(gdb.execute('pi print("Soit {:.2f}us/bpt".format(bp_create_time))')[1]) + + return exec_time + def benchmark(_gdb, what=None, no_mcgdb=True): global gdb gdb = _gdb - if what is None: - what = [nominal_time, gdb_breakpoint, gdb_watchpoint] + \ - list(map(lambda x: gdb_py_breakpoint_parameter(x), (0b0, 0b1, 0b10, 0b11))) + # if what is None: + # what = [nominal_time, gdb_breakpoint, gdb_watchpoint] + \ + # list(map(lambda x: gdb_py_breakpoint_parameter(x), (0b0, 0b1, 0b10, 0b11))) + what = [do_nothing, set_breakpoints] gdb.start(CSource("benchmark.c"), None if no_mcgdb else mcgdb.testing.gdb__init_mcgdb) for prepare_and_run in what: -- GitLab