xref: /xnu-11215/tests/vm/perf_madvise.lua (revision aca3beaa)
1#!/usr/local/bin/recon
2
3local benchrun = require 'benchrun'
4local perfdata = require 'perfdata'
5local csv = require 'csv'
6require 'strict'
7
8local kDefaultDuration = 5
9local kDefaultSizeMb = 16
10
11local benchmark = benchrun.new {
12    name = 'xnu.madvise',
13    version = 2,
14    arg = arg,
15    modify_argparser = function(parser)
16        parser:argument {
17          name = 'path',
18          description = 'Path to perf_madvise binary'
19        }
20        parser:option{
21          name = '--duration',
22          description = 'How long, in seconds, to run each iteration',
23          default = kDefaultDuration
24        }
25        parser:option{
26            name = '--variant',
27            description = 'Which benchmark variant to run (MADV_FREE)',
28            default = 'MADV_FREE',
29            choices = {"MADV_FREE"}
30        }
31        parser:option{
32            name = '--verbose',
33            description = 'Enable verbose logging',
34        }
35        parser:option{
36            name = '--size',
37            description = 'Madvise buffer size (MB)',
38            default = kDefaultSizeMb
39        }
40    end
41}
42
43local tests = {
44    path = benchmark.opt.path,
45}
46
47local args = {benchmark.opt.path, benchmark.opt.variant, benchmark.opt.duration, benchmark.opt.size}
48if benchmark.opt.verbose then
49    table.insert(args, "-v")
50end
51args.echo = true
52for out in benchmark:run(args) do
53    local result = out:match("-----Results-----\n(.*)")
54    benchmark:assert(result, "Unable to find result data in output")
55    local data = csv.openstring(result, {header = false})
56    for field in data:lines() do
57        benchmark.writer:add_value(field[1], perfdata.unit.custom(field[2]), tonumber(field[3]), {
58          [perfdata.larger_better] = true,
59          variant = benchmark.opt.variant
60        })
61    end
62end
63benchmark.writer:set_primary_metric("madvise throughput")
64
65benchmark:finish()
66