# -*- Perl -*- # This module defines the format for converting raw data to # tabbed FTA format. # To use it, put 'use FTA_Format' at the top of your # script. Then call print_header and print_ln as necessary. # Implementation notes: # From # http://www.perl.com/doc/manual/html/pod/perlfunc/sprintf.html # Perl permits the following universally-known flags between the % and the conversion letter: # number minimum field width # .number "precision": digits after decimal point for # floating-point, max length for string, minimum length # for integer package FTA_Format; use strict; use Carp; # use Math::Random qw(:all); require Exporter; our @ISA = qw(Exporter); # child of Exporter our @EXPORT = qw(print_header print_ln format_flt); # Symbols to be exported by default # our @EXPORT_OK = qw($weight); # Symbols to be exported on request our $VERSION = .01; # Version number ############################# # FTA Databases ############################# ############################# # Function Prototypes ############################# sub print_header (*$); sub print_ln(*$$); # Arguments: file handle, and table type # Usage example: print_header (*OUT, "platform"); sub print_header(*$){ my ($OUT,$table) = @_; $_ = $table; SWITCH: { if (/^platform$/) { print $OUT "# platform_id platform_name platform_location platform_type notes\n"; last SWITCH; } if (/^creator$/){ print $OUT "# creator_id component_id node_id platform_id creator cite copyright\n"; last SWITCH; } if (/^node$/){ print $OUT "# node_id platform_id node_name node_ip node_location timezone proc_model os_name cores_per_proc num_procs mem_size disk_size up_bw down_bw metric_id notes\n"; last SWITCH; } if (/^node_perf$/){ print $OUT "# metric_id node_id platform_id sfpop_speed dfpop_speed iop_speed i_val f_val s_val\n"; last SWITCH; } if (/^event_state$/){ print $OUT "# event_id component_id node_id platform_id i_val f_val s_val\n"; last SWITCH; } if (/^component$/){ print $OUT "# component_id node_id platform_id creator_id node_name component_type trace_start trace_end resolution\n"; last SWITCH; } if (/^event_trace$/){ print $OUT "# event_id component_id node_id platform_id node_name event_type event_start_time event_stop_time event_end_reason\n"; last SWITCH; } die "undefined header table: $table"; } } # Arguments: file handle, table type, and reference to data array # Usage example: print_ln (*OUT, "platform", [$PLATFORM_ID, $PLATFORM_NAME, # $PLATFORM_LOCATION, $PLATFORM_TYPE, "NULL"]); sub print_ln(*$$){ my ($OUT, $table, $data) = @_; $_ = $table; my (@fmt_data) = map {format_flt($_)} @$data; SWITCH: { if (/^platform$/) { printf $OUT ("%5d\t%30s\t%50s\t%30s\t%50s", @fmt_data); last SWITCH; } if (/^creator$/){ printf $OUT ("%5d\t%5d\t%5d\t%5d\t%30s\t%30s\t%30s\n",@fmt_data); last SWITCH; } if (/^node$/){ printf $OUT ("%10s\t%5d\t%10s\t%10s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\n",@fmt_data); last SWITCH; } if (/^node_perf$/){ # note dfpop_speed is a string in the print versus a float # as its value could be the string "NULL". If you specify # %10.2s instead, then number after the decimal point would # be the maximum length printf $OUT ("%10s\t%5d\t%5d\t%5s\t%13s\t%6s\t%6s\t%6s\t%6s\n",@fmt_data); last SWITCH; } if (/^event_state$/){ printf $OUT ("%5d\t%5d\t%5d\t%5d\t%5d\t%10.3f%30s\n",@fmt_data); last SWITCH; } # note trace_start, trace_end is a string in the print versus a float # as its value could be the string "NULL". If you had specified # %10.2s instead, then number after the decimal point would # be the maximum length if (/^component$/){ printf $OUT ("%5d\t%5s\t%5d\t%5d\t%30s\t%5s\t%13s\t%13s\t%6d\n",@fmt_data); last SWITCH; } # note event_start_time, event_end_time is a string in the print versus a float # as its value could be the string "NULL". If you had specified # %10.2s instead, then number after the decimal point would # be the maximum length if (/^event_trace$/){ printf $OUT ("%5d\t%5d\t%5d\t%5d\t%5s\t%10d\t%13s\t%13s\t%11s\n",@fmt_data); last SWITCH; } die "undefined data table: $table"; } } # round to decimal points sub format_flt ($){ my ($value) = @_; defined ($value) or confess "float not defined"; my ($num); if ($value =~ m/^\d+\.(\d*)$/){ # sprintf does rounding $num = sprintf("%20.3f", $value); return $num; } else { return $value; } } 1;