blob: 0bd9406abd12a52ab488fc7801f234b7ab8e2fb4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/bin/bash
FILE_REPO="/mnt/perfmount/file_repo"
TEST=0
DD_BS=512
RAND_SCALE=20
function usage()
{
echo "usage: $1 <thread_count> <file_count>"
exit 1
}
function create_files()
{
tid=$1
count=$2
start=$((tid*count))
if [ $TEST -eq "1" ]; then
for ((i=0; i<${count}; i++)); do
outfile=$FILE_REPO/tid${tid}_file$((start+i))
echo "dd if=/dev/urandom of=$outfile bs=1b count=$((RANDOM*20))"
done
else
for ((i=0; i<${count}; i++)); do
filesize=$((RANDOM*RAND_SCALE))
dd_count=$((filesize/DD_BS))
outfile=$FILE_REPO/tid${tid}_file$((start+i))
dd if=/dev/zero of=$outfile bs=1b count=$dd_count > /dev/null 2>&1
echo "$tid $i"
done
fi
}
function Not_A_Number()
{
echo $1$2 | grep ^[0-9]*$ > /dev/null
return $?
}
function main()
{
if [ $# -ne 2 ]; then
usage $0
fi
if ! Not_A_Number $1 $2; then
echo "Invalid input. Enter only numbers."
usage
fi
if [ $2 -lt $1 ]; then
echo "Number of files cannot be less than number of threads"
usage $0
fi
mkdir -p $FILE_REPO
nthr=$1
fc=$2
files_per_thr=$((fc/nthr))
for i in `seq 0 $((nthr-1))`; do
create_files $i $files_per_thr &
done
wait
}
main $@
|