# (C) Copyright 1996-2016 ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. package common::mpp_utils; # assumes Some/Module.pm use Exporter; use File::Basename; use File::stat; @ISA = ('Exporter'); @EXPORT = qw(&file_to_string &file_to_string_nofail &fortran_file_to_string ¤t_date &formats_menu &intro_menu &interfaces_menu &example_menu &testsuite_submenus &classicsuite_submenus &classic_menu &projections &devices &all_devices &projections_info &magml_testsuite_menu &magml_testsuite_submenus &magml_devices &magml_file_to_string &test_suite_selection_html compile_menu epsgram_testsuite_menu epsgram_devices &checkup_platforms &checkup_testsuite_menu &c_file_to_string &c_testsuite_menu &c_testsuite_submenus &c_devices &filesize &program_listing &last_modified_details &check_mpp_for_completion_message &get_valgrid_summary &magplus_version_string &fortan_interface_menu &c_interface_menu &cpp_interface_menu &magml_interface_menu &eps_interface_menu &emphasis &eps_template_from_magml_to_string &epsgram_checkup_menu &log_file_to_string &html_embed &devices_info); # ------------------------------------------------ # emphasis # Returns the given text with HTML emphasis on it # ------------------------------------------------ sub emphasis { my $text = $_[0]; return "$text"; } # --------------------------------------- # filesize # Returns the size of a file as a string # --------------------------------------- sub filesize { local($filename) = $_[0]; my $size = -1024; my $postfix; my $rounded; $st = stat($filename); if ($st) { $size = $st->size; } $size = $size / 1024; # convert to Kb $rounded = sprintf("%.0f", $size); $postfix = "K"; if ($size > 1024) # convert to Mb? { $size = $size / 1024; $postfix = "Mb"; $rounded = sprintf("%.2f", $size); } return "$rounded $postfix"; } # ------------------------------------------------------------------------ # program_listing # Returns a listing of the program executable (for the date/time and size) # ------------------------------------------------------------------------ sub program_listing { local ($filename) = $_[0]; $st = stat($filename); my $strResult = "
";
if ($st)
{
# get a listing of the program
$strResult = $strResult . `ls -lh $filename`;
}
else
{
$strResult = $strResult . "File not found";
}
$strResult = $strResult . "";
return $strResult;
}
# ------------------------------------------------------------------------
# last_modified_details
# Returns the last-modified details for the program executable
# ------------------------------------------------------------------------
sub last_modified_details {
local ($filename) = $_[0];
local ($desc) = $_[1];
local @aparts;
my $strResult = "";
my $strListing;
$st = stat($filename);
if ($st)
{
# get a listing of the program
$strListing = `ls -lh $filename`;
# split into individual words and store in array
@aparts = split (/\s+/, $strListing);
$strResult = $strResult . @aparts[5] . " " . @aparts[6];
}
else
{
$strResult = $strResult . "File not found";
}
return $strResult;
}
# ------------------------------------------------------------------------
# check_mpp_for_completion_message
# Checks the given log file for the Magics++ completion message. If it is
# not there, then the program did not complete. Returns 1 (error) or 0
# ------------------------------------------------------------------------
sub check_mpp_for_completion_message {
local($filename) = @_[0];
local($line) = "";
my $line_num = 1;
my $buffer;
open (FILE, $filename) || return 0; # assume no news is bad news...
# for speed, especially when opening very large log files), we read just
# the last 800 characters and check them for the completion string
seek (FILE, 0, 2); # seek to the end of the file
my $file_len = tell (FILE); # the length of the file
my $seek_place = ($file_len > 800) ? 800 : $file_len;
seek (FILE, -$seek_place, 2); # seek to the (hopefully) start of the completion message
my $rv = read (FILE, $buffer, $seek_place); # read the last part of the file
if ($buffer =~ /.*COMPLETED.*/)
{
return 1;
}
return 0;
}
# ------------------------------------------------------------------------
# get_valgrid_summary
# Checks the valgrind log file for memory leak summary information
# and returns the most important as a string
# ------------------------------------------------------------------------
sub get_valgrid_summary {
local($filename) = @_[0];
local($line) = "";
my $line_num = 1;
my $buffer;
# example string we are trying to parse:
# ==15843== definitely lost: 7,484,447 bytes in 96,940 blocks.
open (FILE, $filename) || return "";
# for speed, especially when opening very large log files), we read just
# the last 800 characters and check them for the completion string
seek (FILE, 0, 2); # seek to the end of the file
my $file_len = tell (FILE); # the length of the file
my $seek_place = ($file_len > 800) ? 800 : $file_len;
seek (FILE, -$seek_place, 2); # seek to the (hopefully) start of the completion message
my $rv = read (FILE, $buffer, $seek_place); # read the last part of the file
if ($buffer =~ /.*definitely\slost:\s(\S+?)\sbytes/)
{
my $byteslost = $1;
my $bytesloststring = $1;
$byteslost =~ s/,//g; # remove commas from the string
if ($byteslost > 1024*500) # highlight if high number
{
return "lost $bytesloststring bytes";
}
return "lost $bytesloststring bytes";
}
return "";
}
# ------------------------------------------------------------------------
# magplus_version_string
# Returns the Magics++ version string
# ------------------------------------------------------------------------
sub magplus_version_string {
return `magics-config --version`;
}
# ------------------------------------------------------------------------------
# file_to_string: reads a file and returns the text as a string
# exits if the file does not exist
sub file_to_string
{
local($filename) = @_[0];
local($string) = "";
open (FILE, $filename) || return ("Cannot open file $filename.");
# open (FILE, $filename) || die "cannot open file $filename.";
@Lines = | $small_startTest suite:$small_end | $small_start$fortran_link$small_end | $small_start$fortran_static_link$small_end | $small_start$classic_link$small_end | $small_start$c_link$small_end | $small_start$magml_link$small_end | $small_start$epsgram_link$small_end | $small_start$filenamelink$small_end |