From b57453df606e0aa11a8b4d5e9c09b3698153b2f1 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 7 Jun 2017 21:49:46 +0300 Subject: [PATCH 1/2] Report events per second in the CPU benchmark. Ref. #140. --- src/tests/cpu/sb_cpu.c | 16 ++++++++++++++++ tests/t/test_cpu.t | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/tests/cpu/sb_cpu.c b/src/tests/cpu/sb_cpu.c index f3dfed6..46a9cf9 100644 --- a/src/tests/cpu/sb_cpu.c +++ b/src/tests/cpu/sb_cpu.c @@ -27,6 +27,8 @@ # include #endif +#include + #include "sysbench.h" /* CPU test arguments */ @@ -42,6 +44,7 @@ static int cpu_init(void); static void cpu_print_mode(void); static sb_event_t cpu_next_event(int thread_id); static int cpu_execute_event(sb_event_t *, int); +static void cpu_report_cumulative(sb_stat_t *); static int cpu_done(void); static sb_test_t cpu_test = @@ -53,6 +56,7 @@ static sb_test_t cpu_test = .print_mode = cpu_print_mode, .next_event = cpu_next_event, .execute_event = cpu_execute_event, + .report_cumulative = cpu_report_cumulative, .done = cpu_done }, .args = cpu_args @@ -124,6 +128,18 @@ void cpu_print_mode(void) log_text(LOG_NOTICE, "Prime numbers limit: %d\n", max_prime); } +/* Print cumulative stats. */ + +void cpu_report_cumulative(sb_stat_t *stat) +{ + log_text(LOG_NOTICE, "CPU speed:"); + log_text(LOG_NOTICE, " events per second: %8.2f", + stat->events / stat->time_interval); + + sb_report_cumulative(stat); +} + + int cpu_done(void) { return 0; diff --git a/tests/t/test_cpu.t b/tests/t/test_cpu.t index 645b205..61eb725 100644 --- a/tests/t/test_cpu.t +++ b/tests/t/test_cpu.t @@ -27,6 +27,8 @@ cpu benchmark tests Threads started! + CPU speed: + events per second: *.* (glob) General statistics: total time: *s (glob) From 66a410b192138cbc7437a8dc6a889487a275e7ec Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 7 Jun 2017 22:09:28 +0300 Subject: [PATCH 2/2] Fix db_connect() in legacy API to initialize db_driver properly. Fixes #146. --- src/sb_lua.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sb_lua.c b/src/sb_lua.c index 7898089..f174883 100644 --- a/src/sb_lua.c +++ b/src/sb_lua.c @@ -880,12 +880,14 @@ int sb_lua_db_connect(lua_State *L) sb_lua_ctxt_t * const ctxt = &tls_lua_ctxt; ctxt->driver = db_create(NULL); - if (ctxt->driver == NULL) { + if (ctxt->driver == NULL) + { luaL_error(L, "DB initialization failed"); - lua_pushstring(L, ctxt->driver->sname); - lua_setglobal(L, "db_driver"); } + lua_pushstring(L, ctxt->driver->sname); + lua_setglobal(L, "db_driver"); + if (ctxt->con != NULL) return 0;