summaryrefslogtreecommitdiffstats
path: root/fs/make_panic
blob: fd27fb85d3b13aabc671697b43b9fcf09d746235 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/perl

#############################################################
#############################################################
##
##    Copyright 2001 Sistina Software Inc.
##
##    This is free software released under the GNU General
##    Public License.  There is no warranty for this
##    software.  See the file COPYING for details.
##
#############################################################
#############################################################

use Getopt::Std;

exit(1) unless getopts('s:f:e:hdqr:l:');

if (defined $opt_h)
{
    print << "EndHelp";
Usage: make_panic [OPTION] 
  -e <iterations>     number of iterations,  infinite if not defined
  -f <forks>          number of processes to fork
  -h                  help
  -s <seed>           seed for random number generator
  -d                  drop seed so you could use it next time
  -q                  Don't print out the status updates. (slient)
  -r                  Number of directories
  -l                  Number of files
EndHelp

    exit(0);
}


if (defined $opt_f)
{
    $opt_f = 1 if $opt_f <=0;
    while (--$opt_f)
    {
	if ($pid = fork())
	{
	    #parent
	}
	elsif (defined $pid)
	{
	    last;
	}
	else
	{
	    die "Fork error $!";
	}
    }
}

if(defined $opt_s)
{
  $seed = $opt_s;
}
else
{
  $seed = time ^ $$;
}
if(defined($opt_d))
{
   system("echo $seed > /make_panic_seed.$$");
}
srand($seed);

if (defined $opt_r)
{
  $dirs = $opt_r;
}
else
{
  $dirs = 50;
}

if (defined $opt_l)
{
  $files = $opt_l;
}
else
{
  $files = 1000;
}


for ($x = 0; $x < $dirs; $x++)
{
    mkdir(sprintf("dir%.10u", $x), 0755);
}

$last = time();
$ops_at_last_tick = 0;

while ( (defined $opt_e)?($opt_e-- > 0):1 )
{
    $v = int(rand(6));

    $x = int(rand($dirs));
    $y = int(rand($files));
    $file = sprintf("dir%.10u/file%.10u", $x, $y);

    if ($v == 0)
    {
	open(DATAFILE, ">> $file") || die;
	close(DATAFILE);
    }
    elsif ($v == 1 || $v == 2)
    {
	$z = int(rand(1000000000));
	if (open(DATAFILE, "+< $file"))
	{
	    seek(DATAFILE, $z, 0);
	    print DATAFILE "$z\n";
	    close(DATAFILE);
	}
    }
    elsif ($v == 3 || $v == 4)
    {
	$z = int(rand(1000000000));
	if (open(DATAFILE, "<  $file"))
	{
	    seek(DATAFILE, -100, 2);
	    read(DATAFILE, $tmp, 100) == 100;
	    close(DATAFILE);
	}
    }
    elsif ($v == 5)
    {
	unlink "$file";
    }


    $ops++;
#    if ($ops % 250 == 0)
#    {
#	$new = time();
#	$last-- if ($new == $last);
#	$rate = 250 / ($new - $last);
#	$pretty_rate = sprintf("%.2f", $rate);
#	$last = $new;
#    }

    $new = time();

    if ($new != $last) {
	$rate = ($ops - $ops_at_last_tick) / ($new - $last);
	$pretty_rate = sprintf("%.2f", $rate);
	$ops_at_last_tick = $ops;
	$last = $new;
    }

   if( ! defined $opt_q ) {
         print "$ops:$v:  $pretty_rate\n";
   }
}