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