nbw-bt/Thesis/LaTeX/appendix.tex

78 lines
2.4 KiB
TeX
Raw Normal View History

\chapter{Perl Dokumentation}\label{app:PerlDoc}
\input{../../Umsetzung/Perl/Kieker.tex}
\chapter{Perl Skripte zur Auswertung}\label{app:PerlScripts}
\section{Zählen von Aufrufhäugigkeiten}\label{app:perlFunCnt}
Dieses Skript liest einen von \textsf{Kieker.Analysis} ereugten Trace in textueller Form (erzeugt mit \emph{--print-Execution-Trace}) und erzeugt eine CSV-Datei mit allen Funktionen und ihren Aufrufhäufigkeiten.
\begin{lstlisting}[language=perl]
use Getopt::Long;
my $inputfile = '';
my $outputfile = 'a.out';
GetOptions ("i|input|inputfile=s" => \$inputfile, # string
"o|output|outputfile=s" => \$outputfile ); # string
unless ($inputfile) {
die("Missing option -i");
}
open(my $inFile, "<", $inputfile) || die "Can't open $inputfile: $!";
open(my $outFile, ">", "$outputfile.csv") || die "Can't open $outputfile: $!";
my %funHash = ();
my %funHashTrace = ();
my $trace;
while (<$inFile>) {
if (/0::@\d+:(\S+)\s/) {
$funHash{$1} += 1;
$funHashTrace{$1} += 1;
} elsif ($trace && /^TraceId\s(\d+)/) {
open(my $traceOutFile, ">", "$outputfile-$trace.csv")
|| die "Can't open $outputfile-$trace.csv: $!";
while (my ($key, $value) = each %funHashTrace) {
print $traceOutFile "$key;$value\n";
}
$trace = $1;
%funHashTrace = ();
} elsif (/^TraceId\s(\d+)/) {
$trace = $1;
%funHashTrace = ();
}
}
open(my $traceOutFile, ">", "$outputfile-$trace.csv")
|| die "Can't open $outputfile-$trace.csv: $!";
while (my ($key, $value) = each %funHashTrace) {
print $traceOutFile "$key;$value\n";
}
while (my ($key, $value) = each %funHash) {
print $outFile "$key;$value\n";
}
\end{lstlisting}
\section{Aggregieren von Funktionsaufrufen}\label{app:perlFunAgg}
Mit diesem Skript werden die Trace-Daten modifiziert. Alle Funktionsnamen werden ignoriert und durch \emph{agg()} ersetzt. Somit existiert nur noch eine Funktion pro Paket. Die Aggregation erfolgt vor der Verarbeitung durch Kieker, damit auch graphische Auswertungen durch Kieker erzeugt werden können.
\begin{lstlisting}[language=perl]
use File::Copy;
my $inFile;
opendir(my $dh, ".") || die "can't opendir .: $!";
my @files = grep(/\.dat$/,readdir($dh));
foreach my $d (@files) {
copy($d,$d.".bak");
open($inFile, "<",$d.".bak");
open(my $outFile, ">",$d);
while (<$inFile>) {
s/(;EPrints.*\.).*?(;EPrints)/$1agg$2/;
print $outFile $_;
}
}
closedir $dh;
\end{lstlisting}