diff --git a/__init__.py b/__init__.py index c8794b002a7276d095cc9c57452486400381ae30..ac892a10e771f664dfbef8167c9c9f03025cbb24 100644 --- a/__init__.py +++ b/__init__.py @@ -193,7 +193,7 @@ class GDB_Instance: source.package = self.package source.compile() - command_line = "/usr/bin/gdb -nx" + command_line = "gdb -nx" self._gdb = subprocess.Popen(shlex.split(command_line), stdin=subprocess.PIPE, stdout=subprocess.PIPE, diff --git a/gdb_testing/native_gdb.py b/gdb_testing/native_gdb.py index 57b5a4c33997cf717d25322d68eb16ca21da61e6..020cdaea78b714689551764ca27fcadbf11a8edf 100644 --- a/gdb_testing/native_gdb.py +++ b/gdb_testing/native_gdb.py @@ -12,8 +12,10 @@ def run(what, run="run"): def version(): gdb.set_title("version") - print(gdb.execute('pi print(sys.version)')[1]) + print(gdb.execute('show version')[1].split("\n")[0]) + print(gdb.execute('pi print("Python "+str(sys.version))')[1][:-1].replace("\n", " --- ")) + print("") def nominal_time(): run("Nominal time") @@ -44,23 +46,36 @@ PARAMETERS = [ '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)] - - def to_run(): - gdb.execute("""python +PY_ON_BREAKPOINT = """python class TestBP(gdb.Breakpoint): def __init__(self): gdb.Breakpoint.__init__(self, "action") self.silent=True def stop(self): - {params} + {on_breakpoint} return False TestBP() end -""".format(params="\n ".join(params))) +""" + +def gdb_py_breakpoint_sleep_for_ref(): + SLEEP_TIME = 0.001 + gdb.execute(PY_ON_BREAKPOINT.format(on_breakpoint="import time;time.sleep({})".format(SLEEP_TIME))) + + run("Python sleep {}s on breakpoint for reference".format(SLEEP_TIME)) + +def gdb_py_breakpoint(): + gdb.execute(PY_ON_BREAKPOINT.format(on_breakpoint="")) + + run("Python breakpoint") + +def gdb_py_breakpoint_parameter(params_choice): + params = [par for i, par in enumerate(PARAMETERS) if params_choice & (1 << i)] + + def to_run(): + gdb.execute(PY_ON_BREAKPOINT.format(on_breakpoint="\n ".join(params))) run("Py BP param {:02b}".format(params_choice)[2:]) @@ -137,7 +152,7 @@ def benchmark(_gdb, what=None, at_init=None): global gdb gdb = _gdb - #what = [version, do_nothing, set_breakpoints] + what = [version, nominal_time, gdb_py_breakpoint, gdb_py_breakpoint_sleep_for_ref] if what is None: what = [version, do_nothing, set_breakpoints, nominal_time, gdb_breakpoint, gdb_watchpoint] + \ list(map(lambda x: gdb_py_breakpoint_parameter(x), (0b0, 0b1, 0b10, 0b11))) diff --git a/mcgdb_testing/benchmark.c b/mcgdb_testing/benchmark.c index 80b9975006d8e3980d9b0f48cd937f8bc8a7f0a4..980028c0d149350f9d9ea23abd9ec1050e2a64f6 100644 --- a/mcgdb_testing/benchmark.c +++ b/mcgdb_testing/benchmark.c @@ -1,76 +1,87 @@ -#include <stdio.h> -#include <stdlib.h> -#include <sys/time.h> -#include <unistd.h> - -/***********/ -// modified by debugging, do not change to macro. -int repeat = 2; - -int it_count = 1000; -int us_sleep_time = 100; - -/***********/ - -void finish_data_ready(void) {} - -void finish(struct timeval x, struct timeval y) { - - static float it_total; - static float ms_busy_time, us_busy_once; - static float ms_total_sleep; - static float ms_time; - { - static double x_us, y_us; - - x_us = (double) x.tv_sec*1000000 + (double) x.tv_usec; - y_us = (double) y.tv_sec*1000000 + (double) y.tv_usec; - - it_total = repeat * it_count; - - ms_time = (y_us - x_us)/1000; - ms_total_sleep = us_sleep_time*(it_total/1000.0); - ms_busy_time = ms_time - ms_total_sleep; - us_busy_once = ms_busy_time * 1000 / it_total; - } - - finish_data_ready(); - - printf("Repeat: %d; Loop: %d; usleep %dus (one) %1.fms (total)\n", - repeat, it_count, us_sleep_time, ms_total_sleep); - printf("------------------\n"); - printf("Total time: %1.fms\n", ms_time); - printf("Busy time : %1.fms\n", ms_busy_time); - printf("Busy once : %1.fus\n", us_busy_once); -} - -void action(int it) { - usleep(us_sleep_time); -} - -void benchmark(void) { - static int i; - - for (i = 0; i < it_count; ++i) { - action(i); - } -} - -int main(int argc, char** argv) { - struct timeval before , after; - int i; - - benchmark(); // warm-up - - gettimeofday(&before , NULL); - - for (i = 0; i < repeat; ++i) { - benchmark(); - } - - gettimeofday(&after , NULL); - - finish(before, after); - - return EXIT_SUCCESS; -} +#include <time.h> +#include <sys/time.h> +#include <unistd.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +struct timespec tbefore, tafter; + + +/***********/ +// modified by debugging, do not change to macro. +int repeat = 2; + +int it_count = 1000; +int us_sleep_time = 100; + +/***********/ + +void finish_data_ready(void) {} + +void finish(struct timeval x, struct timeval y) { + + static float it_total; + static float ms_total_sleep; + static float us_time, us_busy_once; + { + long nsec; + + time_t sec = tafter.tv_sec - tbefore.tv_sec; + + if (tafter.tv_nsec > tbefore.tv_nsec) { + nsec = tafter.tv_nsec - tbefore.tv_nsec; + } else { + sec--; + nsec = (1000000000L + tafter.tv_nsec) - tbefore.tv_nsec; + } + printf("Total time: %ld.%09ld\n", sec, nsec); + it_total = repeat * it_count; + + us_time = ((float)sec) * (1 / it_total * 1000000); + us_time += ((float) nsec) / (it_total * 1000); + + us_busy_once = us_time - us_sleep_time; + + ms_total_sleep = (float)(us_sleep_time * it_total) / 1000000; + } + + printf("Repeat: %d; Loop: %d; usleep %dus (one) %.2fms (total)\n", + repeat, it_count, us_sleep_time, ms_total_sleep); + printf("------------------\n"); + + printf("Busy once : %1.fus\n", us_busy_once); + + finish_data_ready(); +} + +void action(int it) { + usleep(us_sleep_time); +} + +void benchmark(void) { + static int i; + + for (i = 0; i < it_count; ++i) { + action(i); + } +} + +int main(int argc, char** argv) { + struct timeval before , after; + int i; + + benchmark(); // warm-up + + clock_gettime(CLOCK_MONOTONIC_RAW, &tbefore); + + for (i = 0; i < repeat; ++i) { + benchmark(); + } + + clock_gettime(CLOCK_MONOTONIC_RAW, &tafter); + + finish(before, after); + + return EXIT_SUCCESS; +}