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 Distributionslocal sysctl = require 'sysctl' 7*5e3eaea3SApple OSS Distributions 8*5e3eaea3SApple OSS Distributionsrequire 'strict' 9*5e3eaea3SApple OSS Distributions 10*5e3eaea3SApple OSS Distributionslocal kDefaultDuration = 15 11*5e3eaea3SApple OSS Distributions 12*5e3eaea3SApple OSS Distributionslocal benchmark = benchrun.new { 13*5e3eaea3SApple OSS Distributions name = 'xnu.perf_compressor', 14*5e3eaea3SApple OSS Distributions version = 1, 15*5e3eaea3SApple OSS Distributions arg = arg, 16*5e3eaea3SApple OSS Distributions modify_argparser = function(parser) 17*5e3eaea3SApple OSS Distributions parser:argument { 18*5e3eaea3SApple OSS Distributions name = 'path', 19*5e3eaea3SApple OSS Distributions description = 'Path to perf_compressor binary' 20*5e3eaea3SApple OSS Distributions } 21*5e3eaea3SApple OSS Distributions parser:option{ 22*5e3eaea3SApple OSS Distributions name = '--duration', 23*5e3eaea3SApple OSS Distributions description = 'How long, in seconds, to run each iteration', 24*5e3eaea3SApple OSS Distributions default = kDefaultDuration 25*5e3eaea3SApple OSS Distributions } 26*5e3eaea3SApple OSS Distributions parser:option{ 27*5e3eaea3SApple OSS Distributions name = '--variant', 28*5e3eaea3SApple OSS Distributions description = 'Which benchmark variant to run', 29*5e3eaea3SApple OSS Distributions default = 'compress-and-decompress', 30*5e3eaea3SApple OSS Distributions choices = {'compress', 'compress-and-decompress'} 31*5e3eaea3SApple OSS Distributions } 32*5e3eaea3SApple OSS Distributions parser:option{ 33*5e3eaea3SApple OSS Distributions name = '--buffer-size', 34*5e3eaea3SApple OSS Distributions description = 'MB size of buffer to send to compressor', 35*5e3eaea3SApple OSS Distributions default = 100 36*5e3eaea3SApple OSS Distributions } 37*5e3eaea3SApple OSS Distributions parser:option{ 38*5e3eaea3SApple OSS Distributions name = '--data-type', 39*5e3eaea3SApple OSS Distributions description = 'Fill the buffer with random, zero, or typical data', 40*5e3eaea3SApple OSS Distributions default = 'typical', 41*5e3eaea3SApple OSS Distributions choices = {'typical', 'random', 'zero'} 42*5e3eaea3SApple OSS Distributions } 43*5e3eaea3SApple OSS Distributions parser:flag { 44*5e3eaea3SApple OSS Distributions name = '--verbose', 45*5e3eaea3SApple OSS Distributions description = 'Print benchmark progress', 46*5e3eaea3SApple OSS Distributions } 47*5e3eaea3SApple OSS Distributions end 48*5e3eaea3SApple OSS Distributions} 49*5e3eaea3SApple OSS Distributionslocal is_development_kernel, err = sysctl("kern.development") 50*5e3eaea3SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check for development kernel") 51*5e3eaea3SApple OSS Distributionsif is_development_kernel == 0 then 52*5e3eaea3SApple OSS Distributions print "Skipping benchmark on non-development kernel." 53*5e3eaea3SApple OSS Distributions os.exit(0) 54*5e3eaea3SApple OSS Distributionsend 55*5e3eaea3SApple OSS Distributionslocal hw_page_size, err = sysctl("hw.pagesize") 56*5e3eaea3SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check hw page size") 57*5e3eaea3SApple OSS Distributionslocal vm_page_size, err = sysctl("vm.pagesize") 58*5e3eaea3SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check vm page size") 59*5e3eaea3SApple OSS Distributionsif hw_page_size ~= vm_page_size then 60*5e3eaea3SApple OSS Distributions print "Skipping benchmark on this platform because benchmark process has a different page size than the kernel" 61*5e3eaea3SApple OSS Distributions os.exit(0) 62*5e3eaea3SApple OSS Distributionsend 63*5e3eaea3SApple OSS Distributions 64*5e3eaea3SApple OSS Distributionsargs = {benchmark.opt.path, benchmark.opt.variant, benchmark.opt.data_type, benchmark.opt.duration, benchmark.opt.buffer_size} 65*5e3eaea3SApple OSS Distributionsif benchmark.opt.verbose then 66*5e3eaea3SApple OSS Distributions table.insert(args, 2, "-v") 67*5e3eaea3SApple OSS Distributions args["echo"] = true 68*5e3eaea3SApple OSS Distributionsend 69*5e3eaea3SApple OSS Distributionsfor out in benchmark:run(args) do 70*5e3eaea3SApple OSS Distributions local result = out:match("-----Results-----\n(.*)") 71*5e3eaea3SApple OSS Distributions benchmark:assert(result, "Unable to find result data in output") 72*5e3eaea3SApple OSS Distributions local data = csv.openstring(result, {header = true}) 73*5e3eaea3SApple OSS Distributions for field in data:lines() do 74*5e3eaea3SApple OSS Distributions for k, v in pairs(field) do 75*5e3eaea3SApple OSS Distributions unit = perfdata.unit.bytes_per_second 76*5e3eaea3SApple OSS Distributions if k == "Compression Ratio" then 77*5e3eaea3SApple OSS Distributions unit = perfdata.unit.custom("uncompressed / compressed") 78*5e3eaea3SApple OSS Distributions end 79*5e3eaea3SApple OSS Distributions benchmark.writer:add_value(k, unit, tonumber(v), { 80*5e3eaea3SApple OSS Distributions data_type = benchmark.opt.data_type, 81*5e3eaea3SApple OSS Distributions buffer_size = benchmark.opt.buffer_size, 82*5e3eaea3SApple OSS Distributions [perfdata.larger_better] = true 83*5e3eaea3SApple OSS Distributions }) 84*5e3eaea3SApple OSS Distributions end 85*5e3eaea3SApple OSS Distributions end 86*5e3eaea3SApple OSS Distributionsend 87*5e3eaea3SApple OSS Distributions 88*5e3eaea3SApple OSS Distributionsbenchmark:finish() 89