From 4221ca2879b2d6f10ffe59d1c710b65f3cd6848c Mon Sep 17 00:00:00 2001 From: Debian Live user Date: Fri, 28 Apr 2023 22:37:57 -0400 Subject: fix bytes/second io ops calculation --- src/edit-firefox@ | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/edit-firefox@ b/src/edit-firefox@ index 2fc99bd..9cf36f3 100755 --- a/src/edit-firefox@ +++ b/src/edit-firefox@ @@ -1,30 +1,44 @@ #!/bin/bash -TARGET=$1 +if [ "$1" = -f ] +then + FORCE=y + shift +fi + +if [ $# = 0 ] +then + TARGET=/dev/stderr +else + TARGET=$1 +fi die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } -# Test DEVICE WRITE OPS BY WRITEOPS -test_write_ops() +# uses $DIR +measure_write_speed() { - if ! [ -e "$1" ] + if [ "$FORCE" -o ! -e "$1" ] then mkdir -p "$(dirname "$1")" sync begin=$(date +%s%N) - dd if=/dev/urandom of="$DIR"/urandom.out bs=1M count=300 - sync + count=500 + dd if=/dev/urandom of="$DIR"/urandom.out bs=1M count=$count conv=fdatasync end=$(date +%s%N) - ops=$(( (end - begin) / 1000000000 )) + nanosecs=$(( end - begin )) + millisecs=$(( nanosecs / 1000 / 1000 )) + bytes=$(( count * 1000 * 1000 )) + bytes_per_second=$(( 1000 * bytes / millisecs )) rm "$DIR"/urandom.out - echo "$ops" > "$1" + printf "Sanity check: megabytes/second = %s\n" \ + "$(( bytes_per_second / 1000 / 1000 ))" >&2 + printf '%s\n' "$bytes_per_second" > "$1" fi cat "$1" } DIR=~/.mozilla -READ_OPS=1G -WRITE_OPS=$READ_OPS CONFDIR=$HOME/.config/firestart if [ -e "$CONFDIR"/conf ] @@ -32,8 +46,9 @@ then . "$CONFDIR"/conf fi -WRITE_OPS=$(test_write_ops "$CONFDIR"/diskspeed.dat) -WRITE_OPS=${WRITE_OPS%.*} +disk_write_speed=$(measure_write_speed "$CONFDIR"/diskspeed.dat) + +WRITE_OPS=$(( disk_write_speed / 2 )) READ_OPS=$WRITE_OPS [ -e "$DIR" ] || die "does not exist: $DIR" -- cgit v1.2.3