| |
| /pliant/linux/storage/bench.pli |
| |
| 1 |
module "/pliant/language/unsafe.pli" | |
| 2 |
module "/pliant/language/stream.pli" | |
| 3 |
module "/pliant/util/crypto/intn.pli" | |
| 4 |
module "filesystem.pli" | |
| 5 |
| |
| 6 |
constant page_size 4096 | |
| 7 |
constant bench_seconds 30 | |
| 8 |
constant seek_unit 4096 | |
| 9 |
constant transfert_unit 4*2^20 | |
| 10 |
| |
| 11 |
| |
| 12 |
function storage_bench device | |
| 13 |
arg Str device | |
| 14 |
random 2n # make sure random generator is initialised | |
| 15 |
var Address buffer := memory_allocate (max seek_unit transfert_unit)+page_size null | |
| 16 |
var Address b := cast (cast buffer uInt)+page_size-(cast buffer uInt)%page_size Address | |
| 17 |
var Intn size := filesystem_query:device size | |
| 18 |
console device " size is " size\2^20 " MB" eol | |
| 19 |
| |
| 20 |
(var Stream dev) open device in+safe+nocache | |
| 21 |
var DateTime start := datetime ; var Int count := 0 | |
| 22 |
part seek_loop | |
| 23 |
var Intn offset := random size | |
| 24 |
offset := offset\seek_unit*seek_unit | |
| 25 |
dev configure "seek "+string:offset | |
| 26 |
dev raw_read b seek_unit | |
| 27 |
count += 1 | |
| 28 |
if datetime:seconds-start:seconds<bench_seconds/2 | |
| 29 |
restart seek_loop | |
| 30 |
var Float seek := (datetime:seconds-start:seconds)/count | |
| 31 |
if dev=success | |
| 32 |
console "average seek time is " (cast seek*10000 Int)/10 " ms" eol | |
| 33 |
else | |
| 34 |
console "failed to seek on " device eol | |
| 35 |
| |
| 36 |
(var Stream dev) open device in+safe+nocache | |
| 37 |
var Intn offset := random:size\2 | |
| 38 |
offset := offset\transfert_unit*transfert_unit | |
| 39 |
dev configure "seek "+string:offset | |
| 40 |
var DateTime start := datetime ; var Int count := 0 | |
| 41 |
part transfert_loop | |
| 42 |
dev raw_read b transfert_unit | |
| 43 |
count += 1 | |
| 44 |
if datetime:seconds-start:seconds<bench_seconds/2 | |
| 45 |
restart transfert_loop | |
| 46 |
var Float transfert := (cast count Float)*transfert_unit/(datetime:seconds-start:seconds) | |
| 47 |
if dev=success | |
| 48 |
console "average transfert is " (cast 10*transfert/2^20 Int)/10 " MB/s (at " (cast 100*offset\size Int) "%)" eol | |
| 49 |
else | |
| 50 |
console "failed to read on " device eol | |
| 51 |
memory_free buffer | |
| 52 |
| |
| 53 |
| |
| 54 |
function storage_verify device | |
| 55 |
arg Str device | |
| 56 |
(var Stream dev) open device in+safe+nocache | |
| 57 |
var Address buffer := memory_allocate 2*page_size null | |
| 58 |
var Address b := cast (cast buffer uInt)+page_size-(cast buffer uInt)%page_size Address | |
| 59 |
var DateTime start := datetime | |
| 60 |
var uInt count := 0 | |
| 61 |
while dev=success | |
| 62 |
dev raw_read b page_size | |
| 63 |
if dev=success | |
| 64 |
count += 1 | |
| 65 |
var DateTime stop := datetime | |
| 66 |
var Float transfert := (cast count Float)*page_size/(stop:seconds-start:seconds) | |
| 67 |
console "successfully red " count " pages in " (cast stop:seconds-start:seconds Int) " seconds (that's " 1n*count*page_size\2^20 " MB and " (cast 10*transfert/2^20 Int)/10 " MB/s)" eol | |
| 68 |
memory_free buffer | |
| 69 |
| |
| 70 |
| |
| 71 |
export storage_bench storage_verify | |
| 72 |
| |
| |