From ceb24bc32e5f59957ff85ef1bee850fd3076e753 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 11 Oct 2021 13:10:55 +0300 Subject: [PATCH] tests: show the number of parallel jobs used while testing --- cmd/tools/modules/testing/common.v | 3 +++ vlib/benchmark/benchmark.v | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 402fe8530d..cfca10a94c 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -7,6 +7,7 @@ import benchmark import sync.pool import v.pref import v.util.vtest +import runtime const github_job = os.getenv('GITHUB_JOB') @@ -233,6 +234,7 @@ pub fn (mut ts TestSession) test() { remaining_files = vtest.filter_vtest_only(remaining_files, fix_slashes: false) ts.files = remaining_files ts.benchmark.set_total_expected_steps(remaining_files.len) + ts.benchmark.njobs = runtime.nr_jobs() mut pool_of_test_runners := pool.new_pool_processor(callback: worker_trunner) // for handling messages across threads ts.nmessages = chan LogMessage{cap: 10000} @@ -266,6 +268,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { p.set_thread_context(idx, tls_bench) } tls_bench.no_cstep = true + tls_bench.njobs = ts.benchmark.njobs mut relative_file := os.real_path(p.get_item(idx)) mut cmd_options := [ts.vargs] mut run_js := false diff --git a/vlib/benchmark/benchmark.v b/vlib/benchmark/benchmark.v index cd9f9944c7..704245c688 100644 --- a/vlib/benchmark/benchmark.v +++ b/vlib/benchmark/benchmark.v @@ -21,6 +21,7 @@ pub mut: nfail int nskip int nexpected_steps int + njobs int cstep int bok string bfail string @@ -200,7 +201,15 @@ pub fn (b &Benchmark) total_message(msg string) string { if b.nskip > 0 { tmsg += term.colorize(term.bold, term.colorize(term.yellow, '$b.nskip skipped')) + ', ' } - tmsg += '$b.ntotal total. ${term.colorize(term.bold, 'Runtime:')} ${b.bench_timer.elapsed().microseconds() / 1000} ms.\n' + mut njobs_label := '' + if b.njobs > 0 { + if b.njobs == 1 { + njobs_label = ', on ${term.colorize(term.bold, 1.str())} job' + } else { + njobs_label = ', on ${term.colorize(term.bold, b.njobs.str())} parallel jobs' + } + } + tmsg += '$b.ntotal total. ${term.colorize(term.bold, 'Runtime:')} ${b.bench_timer.elapsed().microseconds() / 1000} ms${njobs_label}.\n' return tmsg }