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