From: Petr Špaček Date: Thu, 21 Dec 2017 15:42:20 +0000 (+0100) Subject: daemon: gather luacov statistics from early start X-Git-Tag: v2.0.0~49^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77af3465e64255e3762437556e162871746a78c7;p=thirdparty%2Fknot-resolver.git daemon: gather luacov statistics from early start If KRESD_COVERAGE_STATS environment variable is set, luacov statistics are saved to path specified by it. Beware! Parallel execution needs special handling which is not built-in. --- diff --git a/daemon/engine.c b/daemon/engine.c index f126b855a..92fde30ae 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -663,6 +663,34 @@ static void update_state(uv_timer_t *handle) lru_apply(engine->resolver.cache_rtt, update_stat_item, NULL); } +/** + * Start luacov measurement and store results to file specified by + * KRESD_COVERAGE_STATS environment variable. + * Do nothing if the variable is not set. + */ +static void init_measurement(struct engine *engine) +{ + const char * const statspath = getenv("KRESD_COVERAGE_STATS"); + if (!statspath) + return; + + char * snippet = NULL; + int ret = asprintf(&snippet, + "_luacov_runner = require('luacov.runner')\n" + "_luacov_runner.init({\n" + " statsfile = '%s',\n" + " exclude = {'test', 'tapered', 'lua/5.1'},\n" + "})\n" + "jit.off()\n", statspath + ); + assert(ret > 0); + + ret = luaL_loadstring(engine->L, snippet); + assert(ret == 0); + lua_call(engine->L, 0, 0); + free(snippet); +} + int engine_init(struct engine *engine, knot_mm_t *pool) { if (engine == NULL) { @@ -677,6 +705,7 @@ int engine_init(struct engine *engine, knot_mm_t *pool) if (ret != 0) { engine_deinit(engine); } + init_measurement(engine); /* Initialize resolver */ ret = init_resolver(engine); if (ret != 0) {