#!/usr/local/bin/perl -w use CGI qw(:standard); use GD::Graph::bars; use strict; use Time::HiRes; use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep clock_gettime clock_getres clock ); my $graph = GD::Graph::bars->new(2000, 600); my $format = $graph->export_format; print header("image/$format"); my $count = 20; my $arr = [[[]]]; my $i; my $j; my $rnd; my $t; my @tmp; my @h; my @cpu = ([[],[]], [[],[]], [[],[]], [[],[]], [[],[]]); # nCPU -> count[] -> ... my @process = (0, 0, 0); # { start CPUn, howmuch, begin, ... } for ($i = 0; $i < $count; ++$i) { $h[$i] = $i; for ($j = 0; $j < 3; ++$j) { @process = (0, 0, 0); $process[0] = $j; $process[1] = rand; $process[2] = scalar (gettimeofday); push @{ $cpu[$j][0] }, [ @process ]; } } repeat: if (defined ($cpu[0][0][0]) and ($cpu[0][0][0][1] + $cpu[0][0][0][2] < gettimeofday)) { push @{ $cpu[0][1][0] }, $cpu[0][0][0][1]; push @{ $cpu[0][1][1] }, (gettimeofday - $cpu[0][0][0][2]); $cpu[0][0][0][1] = rand; $cpu[0][0][0][2] = scalar (gettimeofday); @tmp = (0, 0, 0); $tmp[0] = $cpu[0][0][0][0]; $tmp[1] = $cpu[0][0][0][1]; $tmp[2] = $cpu[0][0][0][2]; shift @{$cpu[0][0]}; push @{ $cpu[3][0] }, [ @tmp ]; } if (defined ($cpu[1][0][0]) and ($cpu[1][0][0][1] + $cpu[1][0][0][2] < gettimeofday)) { push @{ $cpu[1][1][0] }, $cpu[1][0][0][1]; push @{ $cpu[1][1][1] }, gettimeofday - $cpu[1][0][0][2]; $cpu[1][0][0][1] = rand; $cpu[1][0][0][2] = scalar (gettimeofday); @tmp = (0, 0, 0); $tmp[0] = $cpu[1][0][0][0]; $tmp[1] = $cpu[1][0][0][1]; $tmp[2] = $cpu[1][0][0][2]; shift @{$cpu[1][0]}; push @{ $cpu[3][0] }, [ @tmp ]; } if (defined ($cpu[2][0][0]) and ($cpu[2][0][0][1] + $cpu[2][0][0][2] < gettimeofday)) { # print "CPU#2\t", $cpu[2][0][0][1], "\t", gettimeofday - $cpu[2][0][0][2], "\n"; push @{ $cpu[2][1][0] }, $cpu[2][0][0][1]; push @{ $cpu[2][1][1] }, gettimeofday - $cpu[2][0][0][2]; $cpu[2][0][0][1] = rand; $cpu[2][0][0][2] = scalar (gettimeofday); @tmp = (0, 0, 0); $tmp[0] = $cpu[2][0][0][0]; $tmp[1] = $cpu[2][0][0][1]; $tmp[2] = $cpu[2][0][0][2]; shift @{$cpu[2][0]}; push @{ $cpu[4][0] }, [ @tmp ]; } if (defined ($cpu[3][0][0]) and ($cpu[3][0][0][1] + $cpu[3][0][0][2] < gettimeofday)) { push @{ $cpu[3][1][0] }, $cpu[3][0][0][1]; push @{ $cpu[3][1][1] }, gettimeofday - $cpu[3][0][0][2]; $cpu[3][0][0][1] = rand; $cpu[3][0][0][2] = scalar (gettimeofday); @tmp = (0, 0, 0); $tmp[0] = $cpu[3][0][0][0]; $tmp[1] = $cpu[3][0][0][1]; $tmp[2] = $cpu[3][0][0][2]; shift @{$cpu[3][0]}; $rnd = rand; if ($rnd >= 0 and $rnd < 0.2) { push @{ $cpu[0][0] }, [ @tmp ]; } if ($rnd >= 0.2 and $rnd < 1.0) { push @{ $cpu[4][0] }, [ @tmp ]; } } if (defined ($cpu[4][0][0]) and ($cpu[4][0][0][1] + $cpu[4][0][0][2] < gettimeofday)) { # print "CPU#4\t", $cpu[4][0][0][1], "\t", gettimeofday - $cpu[4][0][0][2], "\n"; push @{ $cpu[4][1][0] }, $cpu[4][0][0][1]; push @{ $cpu[4][1][1] }, gettimeofday - $cpu[4][0][0][2]; $cpu[4][0][0][1] = rand; $cpu[4][0][0][2] = scalar (gettimeofday); @tmp = (0, 0, 0); $tmp[0] = $cpu[4][0][0][0]; $tmp[1] = $cpu[4][0][0][1]; $tmp[2] = $cpu[4][0][0][2]; shift @{$cpu[4][0]}; $rnd = rand; if ($rnd >= 0 and $rnd < 0.1) { push @{ $cpu[2][0] }, [ @tmp ]; } } goto repeat if ( defined $cpu[0][0][0] || defined $cpu[1][0][0] || defined $cpu[2][0][0] || defined $cpu[3][0][0] || defined $cpu[4][0][0] ); for ($i = $count * 2; $i > 0; --$i) { defined($cpu[0][1][0][$j]) or $cpu[0][1][0][$j] = 0; defined($cpu[0][1][1][$j]) or $cpu[0][1][1][$j] = 0; defined($cpu[1][1][0][$j]) or $cpu[1][1][0][$j] = 0; defined($cpu[1][1][1][$j]) or $cpu[1][1][1][$j] = 0; defined($cpu[2][1][0][$j]) or $cpu[2][1][0][$j] = 0; defined($cpu[2][1][1][$j]) or $cpu[2][1][1][$j] = 0; defined($cpu[3][1][0][$j]) or $cpu[3][1][0][$j] = 0; defined($cpu[3][1][1][$j]) or $cpu[3][1][1][$j] = 0; defined($cpu[4][1][0][$j]) or $cpu[4][1][0][$j] = 0; defined($cpu[4][1][1][$j]) or $cpu[4][1][1][$j] = 0; } # for ($i = 0; $i < $count; ++$i) { #repeat: # for ($j = 0; ; ++$j) { # defined($arr[$i][$j + 1]) or last; # } # if ($arr[$i][$j] == 1) { # $arr[$i][$j + 1] = 4; # goto repeat; # } # if ($arr[$i][$j] == 2) { # $arr[$i][$j + 1] = 4; # goto repeat; # } # if ($arr[$i][$j] == 3) { # $arr[$i][$j + 1] = 5; # goto repeat; # } # if ($arr[$i][$j] == 4) { # $rnd_rslt = rand; # $arr[$i][$j + 1] = 1 # if ($rnd_rslt >= 0 and $rnd_rslt < 0.2); # $arr[$i][$j + 1] = 5 # if ($rnd_rslt >= 0.2 and $rnd_rslt < 1.0); # goto repeat; # } # if ($arr[$i][$j] == 5) { # $rnd_rslt = rand; # $arr[$i][$j + 1] = 3 # if ($rnd_rslt >= 0 and $rnd_rslt < 0.1); # $arr[$i][$j + 1] = 6 # if ($rnd_rslt >= 0.1 and $rnd_rslt < 1.0); # goto repeat; # } # } # for ($i = 0; $i < $count; ++$i) { # $r0[$i] = 0; # $r1[$i] = 0; # $r2[$i] = 0; # for ($j = 0; ; ++$j) { ## print "$arr[$i][$j] "; # # ($i - 0) / 3 == int(($i - 0) / 3) # and $r0[($i - 0) / 3] += 1 # if defined $arr[$i][$j]; # ($i - 1) / 3 == int(($i - 1) / 3) # and $r1[($i - 1) / 3] += 1 # if defined $arr[$i][$j]; # # ($i - 2) / 3 == int(($i - 2) / 3) # and $r2[($i - 2) / 3] += 1 # if defined $arr[$i][$j]; # defined($arr[$i][$j + 1]) or last; # } ## print "\n"; # } # for ($i = 0; $i < $count; ++$i) { # print "r0[$i]=$r0[$i]\n" if defined $r0[$i]; # print "r1[$i]=$r1[$i]\n" if defined $r1[$i]; # print "r2[$i]=$r2[$i]\n" if defined $r2[$i]; # } my @data = ( [ @h ], [ @{$cpu[0][1][0]} ], [ @{$cpu[0][1][1]} ], [ @{$cpu[1][1][0]} ], [ @{$cpu[1][1][1]} ], [ @{$cpu[2][1][0]} ], [ @{$cpu[2][1][1]} ], [ @{$cpu[3][1][0]} ], [ @{$cpu[3][1][1]} ], [ @{$cpu[4][1][0]} ], [ @{$cpu[4][1][1]} ] ); $graph->set( x_label => "Count", y_label => '', title => 'Repository Dynamic', y_max_value => 3, y_min_value => 0, y_tick_number => 10, y_label_skip => 1, x_ticks => 1, # correct_width => 5 dclrs => [ qw(lblue dblue lred dred lgreen dgreen lpurple dpurple gray dgray) ] ) or die $graph->error; my $gd = $graph->plot(\@data) or die $graph->error; binmode STDOUT; print $graph->plot(\@data)->$format();