Hi Khaled,

I came across a perl script for the same, and after some modifications, I
was able to get the stats. Can you try experimenting with the attached
script.

Regards
Rahul

On Thu, Feb 18, 2016 at 3:10 AM, Khaled Attia <[email protected]>
wrote:

> Did that, now the problem is not in parsing the stats.txt
>
>
>
> New problems appear in template processing
>
> I’ve solved most but I’m stuck at the icache and dcache components
>
> Error says that attributes are not actually valid attributes
>
>
>
> _______________________________________________
> gem5-users mailing list
> [email protected]
> http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
>
#!/usr/bin/perl

use strict;
use POSIX;

my ($statstxt,$configini,$mcpatxml) = @ARGV;

my $stats = &loadStats($statstxt);
my $config = &loadConfig($configini);
my $mcpatxml = &loadxml($mcpatxml);

$mcpatxml =~ s/value="(.*?)"/'value="'.&subst($1).'"'/ge;

print $mcpatxml;

sub subst() {
    my ($e) = @_;
    my $f = $e;
	if ($e =~ /config.*,/) {
		my $str = '';
		my @values = split(',', $e);
		foreach my $val (@values) {
			my $x = $val;
            $x =~ s/config.([\w\d\.:]+)/$config->{$1}/g;
			$str = $str . eval $x;
			$str = $str . ",";
	    }
		my $ret = substr($str, 0, -1);
		return $ret;
	}
    $e =~ s/stats.([\w\d\.:]+)/$stats->{$1}/g;
    $e =~ s/config.([\w\d\.:]+)/$config->{$1}/g;
    my $r = eval $e;
    if ($r eq "") {
	print STDERR "Warning: empty result for $f\n";
	return $e;
    }
    return eval $e;
}

sub output() {
    print join("\t",@_),"\n";
}

sub loadxml() {
    my ($file) = @_;
    my $result = "";
    open(WORKING,"<$file") or die "Failed to open xml file $file\n";
    while(my $line = <WORKING>) {
	$result .= $line;
    }
    close(WORKING);
    return $result;
}


sub loadStats() {
    my ($result,$file) = ({},@_);
    open(WORKING,"<$file") or die "Failed to open stats file $file\n";
    while(my $line = <WORKING>) {
	chomp($line);
	if ($line =~ /^(\S+)\s+([\d\.\-]+|nan|inf)\s/) {
	    $result->{$1} = $2;
	}
	elsif ($line =~ /(?:Begin|End) Simulation Statistics/) {}
	elsif ($line =~ /^\s*$/) {}
	else {
	    die "Failed to parse stats $line\n";
	}
    }
    close(WORKING);
    return $result;
}

sub loadConfig() {
    my ($result,$current,$file) = ({},"",@_);
    open(WORKING,"<$file") or die "Failed to open config file $file\n";
    while(my $line = <WORKING>) {
	chomp($line);
	if ($line =~ /\[(.*)\]/) {
	    $current = $1;
	}
	elsif ($line =~ /(.*)=(.*)/) {
	    $result->{$current.".".$1} = $2;
	}
	elsif ($line =~ /^\s*$/) {}
	else {
	    die "Failed to parse config $line\n";
	}
    }
    close(WORKING);
    return $result;
}
_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

Reply via email to