From 7312515be0af2b9993e071001d6e78ee097d5555 Mon Sep 17 00:00:00 2001 From: Tiago Henriques Date: Wed, 28 Jun 2017 17:20:07 +0200 Subject: [PATCH] Add two examples of custom lua cpu tests --- src/lua/empty-test.lua | 24 ++++++++++++++++++++++++ src/lua/prime-test.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/lua/empty-test.lua create mode 100644 src/lua/prime-test.lua diff --git a/src/lua/empty-test.lua b/src/lua/empty-test.lua new file mode 100644 index 0000000..7be089b --- /dev/null +++ b/src/lua/empty-test.lua @@ -0,0 +1,24 @@ +#!/usr/bin/env sysbench + +-- you can run this script like this: +-- $ ./empty-test.lua --cpu-max-prime=20000 --threads=8 --histogram --report-interval=1 run + +sysbench.cmdline.options = { + -- the default values for built-in options are currently ignored, see + -- https://github.com/akopytov/sysbench/issues/151 + ["cpu-max-prime"] = {"CPU maximum prime", 10000}, + ["threads"] = {"Number of threads", 2}, + ["histogram"] = {"Show histogram", "on"}, + ["report-interval"] = {"Report interval", 1} +} + +function event() +end + +function sysbench.hooks.report_intermediate(stat) + local seconds = stat.time_interval + print(string.format("%.0f;%u;%4.2f", + stat.time_total, + stat.threads_running, + stat.events / seconds)) +end \ No newline at end of file diff --git a/src/lua/prime-test.lua b/src/lua/prime-test.lua new file mode 100644 index 0000000..58cac5c --- /dev/null +++ b/src/lua/prime-test.lua @@ -0,0 +1,37 @@ +#!/usr/bin/env sysbench + +-- you can run this script like this: +-- $ ./prime-test.lua --cpu-max-prime=20000 --threads=8 --histogram --report-interval=1 run + +sysbench.cmdline.options = { + -- the default values for built-in options are currently ignored, see + -- https://github.com/akopytov/sysbench/issues/151 + ["cpu-max-prime"] = {"CPU maximum prime", 10000}, + ["threads"] = {"Number of threads", 2}, + ["histogram"] = {"Show histogram", "on"}, + ["report-interval"] = {"Report interval", 1} +} + +function event() + n = 0 + for c = 3, sysbench.opt.cpu_max_prime do + t = math.sqrt(c) + l = 2 + for l = 2, t do + if c % l == 0 then + break + end + end + if l > t then + n = n + 1 + end + end +end + +function sysbench.hooks.report_intermediate(stat) + local seconds = stat.time_interval + print(string.format("%.0f;%u;%4.2f", + stat.time_total, + stat.threads_running, + stat.events / seconds)) +end \ No newline at end of file