Subject: [PATCH v2 3/3] gnu: Add sysbench.

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 7 Mar 2022 23:38:09 -0500

* gnu/packages/benchmark.scm (sysbench): New variable.
---
 gnu/packages/benchmark.scm | 137 +++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)

diff --git a/gnu/packages/benchmark.scm b/gnu/packages/benchmark.scm
index eb5df3d4c3..87c39aac8c 100644
--- a/gnu/packages/benchmark.scm
+++ b/gnu/packages/benchmark.scm
@@ -37,19 +37,27 @@ (define-module (gnu packages benchmark)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system python)
   #:use-module (gnu packages)
+  #:use-module (gnu packages autotools)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages c)
   #:use-module (gnu packages check)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages kde-frameworks)
+  #:use-module (gnu packages databases)
+  #:use-module (gnu packages docbook)
   #:use-module (gnu packages linux)
+  #:use-module (gnu packages lua)
   #:use-module (gnu packages maths)
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages opencl)
   #:use-module (gnu packages perl)
+  #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
   #:use-module (gnu packages python-science)
   #:use-module (gnu packages python-web)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages qt)
+  #:use-module (gnu packages xml)
   #:use-module (ice-9 match))
 
 (define-public fio
@@ -430,3 +438,132 @@ (define-public kdiskmark
 @item Report generation.
 @end itemize")
     (license license:gpl3+)))
+
+(define-public sysbench
+  (package
+    (name "sysbench")
+    (version "1.0.20")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/akopytov/sysbench")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (modules '((guix build utils)))
+              (snippet '(begin
+                          ;; Ensure no bundled libraries get used.
+                          (delete-file-recursively "third_party")
+                          (substitute* "configure.ac"
+                            (("^third_party/.*")
+                             ""))
+                          (substitute* "Makefile.am"
+                            ((".*(LUAJIT|CK)_DIR =.*")
+                             ""))))
+              (sha256
+               (base32
+                "1sanvl2a52ff4shj62nw395zzgdgywplqvwip74ky8q7s6qjf5qy"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list
+      #:configure-flags #~(list "--with-pgsql"
+                                ;; Explicitly specify the library directory of
+                                ;; MySQL, otherwise `mysql_config` gets
+                                ;; consulted and adds unnecessary link
+                                ;; directives.
+                                (string-append "--with-mysql-libs="
+                                               #$(this-package-input "mysql")
+                                               "/lib")
+                                "--with-system-luajit"
+                                "--with-system-ck"
+                                ;; If we let the build tool select the most
+                                ;; optimal compiler architecture flag, the
+                                ;; build is not reproducible.
+                                "--without-gcc-arch")
+      #:phases #~(modify-phases %standard-phases
+                   (add-after 'unpack 'patch-test-runner
+                     (lambda _
+                       (substitute* "tests/test_run.sh"
+                         (("/bin/bash")
+                          (which "bash"))
+                         ;; Do not attempt to invoke the cram command via
+                         ;; Python, as on Guix it is a shell script (wrapper).
+                         (("\\$\\(command -v cram\\)")
+                          "-m cram"))))
+                   (add-after 'unpack 'disable-test-installation
+                     (lambda _
+                       (substitute* "tests/Makefile.am"
+                         (("install-data-local")
+                          "do-not-install-data-local")
+                         (("^test_SCRIPTS.*")
+                          ""))))
+                   (add-after 'unpack 'fix-docbook
+                     (lambda* (#:key inputs #:allow-other-keys)
+                       (substitute* "m4/ax_check_docbook.m4"
+                         (("DOCBOOK_ROOT=.*" all)
+                          (string-append
+                           all "XML_CATALOG="
+                           (search-input-file inputs
+                                              "xml/dtd/docbook/catalog.xml")
+                           "\n")))
+                       (substitute* "doc/xsl/xhtml.xsl"
+                         (("http://docbook.sourceforge.net/release/xsl\
+/current/xhtml/docbook.xsl")
+                          (search-input-file
+                           inputs (string-append "xml/xsl/docbook-xsl-"
+                                                 #$(package-version docbook-xsl)
+                                                 "/xhtml/docbook.xsl"))))
+                       (substitute* "doc/xsl/xhtml-chunk.xsl"
+                         (("http://docbook.sourceforge.net/release/xsl\
+/current/xhtml/chunk.xsl")
+                          (search-input-file
+                           inputs (string-append "xml/xsl/docbook-xsl-"
+                                                 #$(package-version docbook-xsl)
+                                                 "/xhtml/chunk.xsl")))))))))
+    (native-inputs (list autoconf
+                         automake
+                         libtool
+                         pkg-config
+                         python-cram
+                         python-wrapper
+                         which
+                         ;; For documentation
+                         libxml2        ;for XML_CATALOG_FILES
+                         libxslt
+                         docbook-xml-4.1.2
+                         docbook-xsl))
+    (inputs (list ck libaio luajit mysql postgresql))
+    (home-page "https://github.com/akopytov/sysbench/")
+    (synopsis "Scriptable database and system performance benchmark")
+    (description "@command{sysbench} is a scriptable multi-threaded benchmark
+tool based on LuaJIT.  It is most frequently used for database benchmarks, but
+can also be used to create arbitrarily complex workloads that do not involve a
+database server.  @command{sysbench} comes with the following bundled
+benchmarks:
+@table @file
+@item oltp_*.lua
+A collection of OLTP-like database benchmarks.
+@item fileio
+A filesystem-level benchmark.
+@item cpu
+A simple CPU benchmark.
+@item memory
+A memory access benchmark.
+@item threads
+A thread-based scheduler benchmark.
+@item mutex
+A POSIX mutex benchmark.
+@end table
+It includes features such as:
+@itemize
+@item
+Extensive statistics about rate and latency is available, including latency
+percentiles and histograms.
+@item
+Low overhead even with thousands of concurrent threads.  @command{sysbench} is
+capable of generating and tracking hundreds of millions of events per second.
+@item
+New benchmarks can be easily created by implementing pre-defined hooks in
+user-provided Lua scripts.
+@item
+@end itemize")
+    (license license:gpl2+)))
-- 
2.34.0