#!/usr/local/bin/perl ############################################################## # # # 3D Cache Hierarchy Map Generator # # --- Creating 3D cache hierarchy map -- # # version 0.2-gamma, 30/Jan/1997 # # Kenichi MATSUI (matsui@nemoto.ecei.tohoku.ac.jp)# # # ############################################################## ############################################################## # 3Dhierarchy.pl # # Kenichi Matsui, Jan 1997 # # Usage: 3Dhierarchy.pl squid.conf [outputfile] # # A simple perl script to generate 3D cache hierarchy map from # squid.conf. The 3D map written with VRML1.0. # Read the line starting "cache_host" and "visible_hostname" from # squid.conf , and generate hierarchy map. # # [TODO] # 1. Generate map from many server's squid.conf. # 2. More fascinating layout. # 3. Support VRML2.0 or later. # # [URL] # ftp://ftp.nemoto.ecei.tohoku.ac.jp/pub/Net/WWW/VRML/converter/ # 3Dhierarchy.pl # http://www.nemoto.ecei.tohoku.ac.jp/~matsui/VRML/3Dhierarchy/ ############################################################## ################## Set up some parameters #################### ### color "R G B" $background = "0 0 0"; # background $localhost_color = "1 1 0"; # localhost(sphere) $localhost_e_color = "1 1 0"; # localhost(string) $parent_color = "1 0 0"; # parent(sphere) $parent_e_color = "1 0 0"; # parent(string) $sibling_color = "0 0 1"; # sibling(sphere) $sibling_e_color = "0 0 1"; # sibling(string) $localtoparent_line_color = "1 0 0"; # line,localhost -> parent $localtosibling_line_color = "0 1 1"; # line,localhost -> sibling ### distance (m) $parent_diameter = 100; # localhost <-> parent $sibling_diameter = 100; # localhost <-> sibling $parent_height = 100; # parent height $weight_height = 10; # not support yet ### size (m) $parent_weight_alpha = 1; # coefficient of line,localhost -> parent $sibling_weight_alpha = 1; # coefficient of line,localhost -> sibling $weight_location = 0.75; # not support yet $radius = 10; # radius of sphere $default_weight = 1; # default size of line,localhost -> sibling ### font # localhost $localhost_font_size = 10; # size $localhost_font_spacing = 1; # spacing $localhost_font_width = 140; # string width $localhost_font_transparency = 0; # transparency $localhost_font_family = "SANS"; # SANS ,SERIF, TYPEWRITER $localhost_font_style = "BOLD"; # NONE, BOLD, ITALIC $localhost_font_justification = "CENTER"; # LEFT, CENTER, RIGHT # parent $parent_font_size = 10; $parent_font_spacing = 1; $parent_font_width = 140; $parent_font_transparency = 0; $parent_font_family = "SANS"; $parent_font_style = "BOLD"; $parent_font_justification = "CENTER"; # sibling $sibling_font_size = 10; $sibling_font_spacing = 1; $sibling_font_width = 140; $sibling_font_transparency = 0; $sibling_font_family = "SANS"; $sibling_font_style = "BOLD"; $sibling_font_justification = "CENTER"; ### transparency $localhost_transparency = 0; $parent_transparency = 0; $sibling_transparency = 0; $local_to_parent_line = 0; $local_to_sibling_line = 0; ### file name $localhostname = "localhost"; # localhost name (if not found "visible_hostname") $outputfile = "3Dhierarchy.wrl"; # outputfile name (if not defined) ### VRML viewer $viewer = "examiner"; $title = "3D cache hierarchy v0.2"; $speed = "10"; # # ################## End of Set up some parameters ################## ################################################################### # # # If you modify below, it is your own risk. # # # ################################################################### ### version $comment = "3D cache hierarchy map generator version 0.2 (C) Kenichi Matsui (matsui\@nemoto.ecei.tohoku.ac.jp) Jan/1997"; $comment2 = "3D cache hierarchy map generator \n\tversion 0.2 Jan/1997 (C)Kenichi Matsui"; ### pi $pi = 3.14159265; ######## signal behavior $SIG{'HUP'} = 'quit'; $SIG{'INT'} = 'quit'; $SIG{'QUIT'} = 'quit'; $SIG{'KILL'} = 'quit'; ######## get name of squid.conf and outputfile $argc = @ARGV; if($argc == 0){ &print_help; } if($argc == 1){ if (($ARGV[0] eq "-h")||($ARGV[0] eq "-help")){ &print_help; }else{ $conf_file = "$ARGV[0]"; } } if($argc == 2){ $conf_file = "$ARGV[0]"; $outputfile = "$ARGV[1]"; } if($argc >= 3){ &print_help; } ######## ######## START ######## &print_start; ######## get time &get_localtime; ######## analyze confile &analyze_confile($conf_file); &analyze_result; ######## calclating x,y,z &calc_xyz; ######## open outputfile open(OUT,">$outputfile")||die "Can't open $outputfile\n\n"; print "Now creating vrml file... \n"; ######## creating VRML file ######## header %def_titles = ("comment", "$comment", "comment2","$comment2", "background", "$background", "viewer", "$viewer", "title", "$title", "speed", "$speed", "home_x", "$home_x", "home_y", "$home_y", "home_z", "$home_z", "home2_x", "$home2_x", "home2_y", "$home2_y", "home2_z", "$home2_z" ); &vrml_header(*def_titles); ####### localhost sphere print OUT "DEF localhost Separator \{\n"; undef(%def_title); %def_title = ("DEF","locahostsphere", "color","$localhost_color", "transp","$localhost_transparency", "radius","$radius"); &Sphere(*def_title); ####### localhost name $tmp_y = 1.5*$radius; print OUT < 1){ undef(%def_title); %def_title = ("DEF","toparentlineh", "color","$localtoparent_line_color", "transp","$local_to_parent_line", "width" ,"$parent_diameter", "height","$parent_weight_w{$_}", "depth","$parent_weight_w{$_}"); print OUT <){ next if /^#/; if(/^cache_host\s/){ @data = split(/\s+/); $host_and_type{$data[1]} = $data[2]; $host_and_weight{$data[1]} = $default_weight; foreach (@data){ if(/weight/){ @weight = split(/=/); $host_and_weight{$data[1]} = $weight[1]; }else{ $host_and_weight{$data[1]} = $default_weight; } } if((/\ssibling\s/)||(/\sneighbor\s/)){ $sibling_count++; $total_sibling_weight += $host_and_weight{$data[1]} }elsif(/\sparent\s/){ $parent_count++; $total_parent_weight += $host_and_weight{$data[1]} } }elsif(/^visible_hostname\s/){ @data = split(/\s+/); $localhostname = "$data[1]"; } } close(CONF); } ######## show data from configure file sub analyze_result { print "\nHOSTNAME\tType\tWeight\n"; print "-------------------------------------\n"; foreach (sort keys %host_and_type){ print "$_ $host_and_type{$_} $host_and_weight{$_}\n"; } print "-------------------------------------\n"; print "Total Parent = $parent_count\n"; print "Total Sibling = $sibling_count\n"; print "localhostname = $localhostname\n\n"; } ######## get time sub get_localtime { local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime; local($mname) = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[$mon]; local($dname) = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[$wday]; $mon++; $date_form = "$mday/$mname/$year, $hour:$min:$sec"; } ######## START message sub print_start { print "$comment2\n\n"; print "\tInput confile: $conf_file\n"; print "\tOutput vrmlfile: $outputfile\n\n"; } ######## END message sub print_end { print "finished.\n"; print "\t Outputfile is $outputfile\n"; } ####### HELP message sub print_help { print "$comment2\n"; print "--Creating 3D cache hierarchy map--\n\n"; print "\tUsage: 3Dhierarchy squid.conf [outputfile]\n"; print "\t Options:\n"; print "\t -h\t print this message\n"; print "\t -help\t print this message\n"; print "\n"; exit; } ######## when caught signal sub quit { print "Caught signal. exiting"; close(CONF); print "."; close(OUT); print "."; unlink($outputfile); print "."; print "done\n"; exit; } ######## ######## END of whole script ######## exit;