From aa7fbce22575ec4f1df018c3e98ed7203c08ac1b Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 18 Jan 2017 13:16:40 +0300 Subject: [PATCH] Add a comment to oltp_common.lua. Based on #103, add a comment to oltp_common.lua to explain that it should not be called directly, but is meant to be included by other OLTP scripts. --- sysbench/lua/internal/sysbench.rand.lua | 75 +++++++++++++++++++++++++ sysbench/lua/oltp_common.lua | 7 ++- 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 sysbench/lua/internal/sysbench.rand.lua diff --git a/sysbench/lua/internal/sysbench.rand.lua b/sysbench/lua/internal/sysbench.rand.lua new file mode 100644 index 0000000..b56fabf --- /dev/null +++ b/sysbench/lua/internal/sysbench.rand.lua @@ -0,0 +1,75 @@ +-- Copyright (C) 2016-2017 Alexey Kopytov + +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +ffi = require("ffi") + +-- ---------------------------------------------------------------------- +-- Pseudo-random number generation API +-- ---------------------------------------------------------------------- + +sysbench.rand = {} + +ffi.cdef[[ +uint64_t sb_rand_uniform_uint64(void); +uint32_t sb_rand_default(uint32_t, uint32_t); +uint32_t sb_rand_uniform(uint32_t, uint32_t); +uint32_t sb_rand_gaussian(uint32_t, uint32_t); +uint32_t sb_rand_special(uint32_t, uint32_t); +uint32_t sb_rand_pareto(uint32_t, uint32_t); +uint32_t sb_rand_unique(void); +void sb_rand_str(const char *, char *); +double sb_rand_uniform_double(void); +]] + +function sysbench.rand.uniform_uint64() + return ffi.C.sb_rand_uniform_uint64() +end + +function sysbench.rand.default(a, b) + return ffi.C.sb_rand_default(a, b) +end + +function sysbench.rand.uniform(a, b) + return ffi.C.sb_rand_uniform(a, b) +end + +function sysbench.rand.gaussian(a, b) + return ffi.C.sb_rand_gaussian(a, b) +end + +function sysbench.rand.special(a, b) + return ffi.C.sb_rand_special(a, b) +end + +function sysbench.rand.pareto(a, b) + return ffi.C.sb_rand_pareto(a, b) +end + +function sysbench.rand.unique() + return ffi.C.sb_rand_unique() +end + +function sysbench.rand.string(fmt) + local buflen = #fmt + local buf = ffi.new("uint8_t[?]", buflen) + ffi.C.sb_rand_str(fmt, buf) + return ffi.string(buf, buflen) +end + +function sysbench.rand.uniform_double() + return ffi.C.sb_rand_uniform_double() +end + diff --git a/sysbench/lua/oltp_common.lua b/sysbench/lua/oltp_common.lua index ba4b39f..910dcb7 100644 --- a/sysbench/lua/oltp_common.lua +++ b/sysbench/lua/oltp_common.lua @@ -14,9 +14,10 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA --- ---------------------------------------------------------------------- --- Common code for OLTP benchmarks --- ---------------------------------------------------------------------- +-- ----------------------------------------------------------------------------- +-- Common code for OLTP benchmarks. This script is meant to be included by other +-- OLTP script and should not be called directly. +-- ----------------------------------------------------------------------------- -- Generate strings of random digits with 11-digit groups separated by dashes function get_c_value()