15c2921b0SApple OSS Distributions#!/usr/local/bin/recon 25c2921b0SApple OSS Distributions 35c2921b0SApple OSS Distributionslocal benchrun = require 'benchrun' 45c2921b0SApple OSS Distributionslocal perfdata = require 'perfdata' 55c2921b0SApple OSS Distributionslocal csv = require 'csv' 65c2921b0SApple OSS Distributionslocal sysctl = require 'sysctl' 75c2921b0SApple OSS Distributions 85c2921b0SApple OSS Distributionsrequire 'strict' 95c2921b0SApple OSS Distributions 105c2921b0SApple OSS Distributionslocal kDefaultDuration = 15 115c2921b0SApple OSS Distributions 125c2921b0SApple OSS Distributionslocal benchmark = benchrun.new { 135c2921b0SApple OSS Distributions name = 'xnu.perf_compressor', 145c2921b0SApple OSS Distributions version = 1, 155c2921b0SApple OSS Distributions arg = arg, 165c2921b0SApple OSS Distributions modify_argparser = function(parser) 175c2921b0SApple OSS Distributions parser:argument { 185c2921b0SApple OSS Distributions name = 'path', 195c2921b0SApple OSS Distributions description = 'Path to perf_compressor binary' 205c2921b0SApple OSS Distributions } 215c2921b0SApple OSS Distributions parser:option{ 225c2921b0SApple OSS Distributions name = '--duration', 235c2921b0SApple OSS Distributions description = 'How long, in seconds, to run each iteration', 245c2921b0SApple OSS Distributions default = kDefaultDuration 255c2921b0SApple OSS Distributions } 265c2921b0SApple OSS Distributions parser:option{ 275c2921b0SApple OSS Distributions name = '--variant', 285c2921b0SApple OSS Distributions description = 'Which benchmark variant to run', 295c2921b0SApple OSS Distributions default = 'compress-and-decompress', 305c2921b0SApple OSS Distributions choices = {'compress', 'compress-and-decompress'} 315c2921b0SApple OSS Distributions } 325c2921b0SApple OSS Distributions parser:option{ 335c2921b0SApple OSS Distributions name = '--buffer-size', 345c2921b0SApple OSS Distributions description = 'MB size of buffer to send to compressor', 355c2921b0SApple OSS Distributions default = 100 365c2921b0SApple OSS Distributions } 375c2921b0SApple OSS Distributions parser:option{ 385c2921b0SApple OSS Distributions name = '--data-type', 395c2921b0SApple OSS Distributions description = 'Fill the buffer with random, zero, or typical data', 405c2921b0SApple OSS Distributions default = 'typical', 415c2921b0SApple OSS Distributions choices = {'typical', 'random', 'zero'} 425c2921b0SApple OSS Distributions } 435c2921b0SApple OSS Distributions parser:flag { 445c2921b0SApple OSS Distributions name = '--verbose', 455c2921b0SApple OSS Distributions description = 'Print benchmark progress', 465c2921b0SApple OSS Distributions } 475c2921b0SApple OSS Distributions end 485c2921b0SApple OSS Distributions} 495c2921b0SApple OSS Distributionslocal is_development_kernel, err = sysctl("kern.development") 505c2921b0SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check for development kernel") 515c2921b0SApple OSS Distributionsif is_development_kernel == 0 then 525c2921b0SApple OSS Distributions print "Skipping benchmark on non-development kernel." 535c2921b0SApple OSS Distributions os.exit(0) 545c2921b0SApple OSS Distributionsend 555c2921b0SApple OSS Distributionslocal hw_page_size, err = sysctl("hw.pagesize") 565c2921b0SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check hw page size") 575c2921b0SApple OSS Distributionslocal vm_page_size, err = sysctl("vm.pagesize") 585c2921b0SApple OSS Distributionsbenchmark:assert(err == nil, "Unable to check vm page size") 59*8d741a5dSApple OSS Distributionslocal product_name = benchmark:spawn{'/usr/bin/sw_vers', '-productName'} 605c2921b0SApple OSS Distributionsif hw_page_size ~= vm_page_size then 61*8d741a5dSApple OSS Distributions benchmark:print "Skipping benchmark on this platform because benchmark process has a different page size than the kernel" 62*8d741a5dSApple OSS Distributions os.exit(0) 63*8d741a5dSApple OSS Distributionselseif string.find(product_name, "Watch OS") or string.find(product_name, "TVOS") then 64*8d741a5dSApple OSS Distributions -- rdar://103802544: Temporarily disable test for watchOS and tvOS 65*8d741a5dSApple OSS Distributions benchmark:print "Skipping benchmark on this platform as a temporary workaround to avoid device panics" 665c2921b0SApple OSS Distributions os.exit(0) 675c2921b0SApple OSS Distributionsend 685c2921b0SApple OSS Distributions 695c2921b0SApple OSS Distributionsargs = {benchmark.opt.path, benchmark.opt.variant, benchmark.opt.data_type, benchmark.opt.duration, benchmark.opt.buffer_size} 705c2921b0SApple OSS Distributionsif benchmark.opt.verbose then 715c2921b0SApple OSS Distributions table.insert(args, 2, "-v") 725c2921b0SApple OSS Distributions args["echo"] = true 735c2921b0SApple OSS Distributionsend 745c2921b0SApple OSS Distributionsfor out in benchmark:run(args) do 755c2921b0SApple OSS Distributions local result = out:match("-----Results-----\n(.*)") 765c2921b0SApple OSS Distributions benchmark:assert(result, "Unable to find result data in output") 775c2921b0SApple OSS Distributions local data = csv.openstring(result, {header = true}) 785c2921b0SApple OSS Distributions for field in data:lines() do 795c2921b0SApple OSS Distributions for k, v in pairs(field) do 805c2921b0SApple OSS Distributions unit = perfdata.unit.bytes_per_second 815c2921b0SApple OSS Distributions if k == "Compression Ratio" then 825c2921b0SApple OSS Distributions unit = perfdata.unit.custom("uncompressed / compressed") 835c2921b0SApple OSS Distributions end 845c2921b0SApple OSS Distributions benchmark.writer:add_value(k, unit, tonumber(v), { 855c2921b0SApple OSS Distributions data_type = benchmark.opt.data_type, 865c2921b0SApple OSS Distributions buffer_size = benchmark.opt.buffer_size, 875c2921b0SApple OSS Distributions [perfdata.larger_better] = true 885c2921b0SApple OSS Distributions }) 895c2921b0SApple OSS Distributions end 905c2921b0SApple OSS Distributions end 915c2921b0SApple OSS Distributionsend 925c2921b0SApple OSS Distributions 935c2921b0SApple OSS Distributionsbenchmark:finish() 94