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