⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.prl

📁 一个用在mips体系结构中的操作系统
💻 PRL
📖 第 1 页 / 共 2 页
字号:
#!/usr/local/bin/perl5 -w## Copyright (C) 1996-1998 by the Board of Trustees#    of Leland Stanford Junior University.# # This file is part of the SimOS distribution. # See LICENSE file for terms of the license. ##### GLOBALS########   fieldname####   config########   fields in a data bucket:####       name        - name of bucket####       n           - number of stat entries (times went into node)####       lattotal    - total latency cycles####       latcorr     - sum of the squares of latency####       latmin      - minimum latency####       latmax      - maximum latency####       comptotal   - total computation cycles####       compcorr    - sum of the squares of computation ####       compmin     - minimum computation ####       compmax     - maximum computation ####       <SR_FIELDS> - a field for each stat record field and derived field@fieldname = ();%config = ();######## Parse the named tree into a useful format####sub ParseTree {    my($infile, $targetTree) = @_;    my($tree, $t);    $t = 0;    open(INFILE, $infile);    do {        $tree = $t;        $t = ParseNextTree(\*INFILE, $targetTree);    } until (!$t);    close(INFILE);    return $tree;}sub ParseNextTree {    my($infile, $targetTree) = @_;    my($tree, @path);    my($nodename, $treeName, $name) = ("nil", "nil", "nil");    my($indx, $field, $depth, $parent, $n);    $tree = {};    @path = ();    while (<$infile>) {        if (/^TIMING:   \s+                 tree        \s+  (\S+)   \s+                 depth       \s+  (\d+)   \s+                 name        \s+  (\S+)   \s+                 parent      \s+  (\S+)   \s+                 n           \s+  (\S+)   /x) {            $treeName = $1;            $depth = $2;            $name = $3;            $parent = $4;            $n = $5;                        if ($treeName ne $targetTree) {                next;            }            splice(@path, $depth);            ($name eq "ROOT") || ($parent eq $path[$#path])                || die "bad parent name=$name par=$parent path=@path";                        $parentname = join('.', @path);                        push(@path, $name);            $nodename = join('.', @path);            if ($parentname ne "") {                push(@{$tree->{$parentname}{"children"}}, $nodename);            }            @{$tree->{$nodename}{"children"}} = ();            # printf "nodename = $nodename\n";                        $tree->{$nodename}{"name"} = $nodename;            $tree->{$nodename}{"derived"} = 0;            $tree->{$nodename}{"n"} = $n;            $tree->{$nodename}{"lattotal"} = 0;            $tree->{$nodename}{"comptotal"} = 0;            $tree->{$nodename}{"latcorr"} = 0;            $tree->{$nodename}{"compcorr"} = 0;            $tree->{$nodename}{"latmin"} = 0;            $tree->{$nodename}{"latmax"} = 0;            $tree->{$nodename}{"compmin"} = 0;            $tree->{$nodename}{"compmax"} = 0;        } elsif (/^TIMING: \s+                 sumX       \s+   (\S+)   \s+                 sumY       \s+  (\S+)   \s+                 sumXX      \s+  (\S+)   \s+                 sumYY      \s+  (\S+)   \s+                 sumXY      \s+  (\S+)   \s+                 minX       \s+  (\S+)   \s+                 maxX       \s+  (\S+)   \s+                 minY       \s+  (\S+)   \s+                 maxY       \s+  (\S+)   /x) {                        if ($treeName ne $targetTree) {                next;            }                        $tree->{$nodename}{"lattotal"} = $1;            $tree->{$nodename}{"comptotal"} = $2;            $tree->{$nodename}{"latcorr"} = $3;            $tree->{$nodename}{"compcorr"} = $4;            $tree->{$nodename}{"latmin"} = $6;            $tree->{$nodename}{"latmax"} = $7;            $tree->{$nodename}{"compmin"} = $8;            $tree->{$nodename}{"compmax"} = $9;                    } elsif (/^TIMING: \s+ SR_BUCKET \s+ /x) {            if ($treeName ne $targetTree) {                next;            }            $indx = 0;                        foreach $field (split(/\s+/, $')) {                $tree->{$nodename}{$fieldname[$indx++]} = $field;            }        } elsif (/^TIMING: \s+ tree \s+ (\S+) \s+ END/x) {            if ($1 eq $targetTree) {                ($treeName eq $1) || die "bad tree end";                last;            }        } elsif (/^TIMING: \s+ SR_FIELDS \s+ /x) {            $indx = 0;                        foreach $field (split(/\s+/, $')) {                $fieldname[$indx++] = $field;            }            $fieldname[$indx++] = "n";            $fieldname[$indx++] = "lattotal";            $fieldname[$indx++] = "comptotal";            $fieldname[$indx++] = "latcorr";            $fieldname[$indx++] = "compcorr";            $fieldname[$indx++] = "latmin";            $fieldname[$indx++] = "latmax";            $fieldname[$indx++] = "compmin";            $fieldname[$indx++] = "compmax";                    } elsif (/MACHINE \s+ (\S+) \s+ (\S+)/x) {            $config{$1} = $2;        }    }    if (!defined($tree->{"ROOT"})) {        return 0;    }    return $tree;}######## TotalTree########sub TotalTree {    my($tree, $startnode) = @_;    my($total);    $total = {};    print "-> TotalTree with start $startnode\n";    $total->{"name"} = "TOTAL";    $total->{"n"} = $tree->{$startnode}{"n"};    $total->{"lattotal"} = $tree->{$startnode}{"lattotal"};    $total->{"latmin"} = $tree->{$startnode}{"latmin"};    $total->{"latmax"} = $tree->{$startnode}{"latmax"};    $total->{"latcorr"} = $tree->{$startnode}{"latcorr"};        TotalNode($tree, $startnode, \%$total);    ComputeDerivedFields(\%$total);    return $total;}sub TotalNode {    my($tree, $node, $total) = @_;    my($child);        print "-> TotalNode $node\n";    SumUp($total, $tree->{$node});        foreach $child (@{$tree->{$node}{"children"}}) {        if (&PhaseName($child) eq "DESCHED") {            # handle specially        } else {            TotalNode($tree, $child, $total);        }    }}######## SumTree########sub SumTree {    my($tree, $startnode, $states, $dim) = @_;    my($comp);    $comp = {};        defined($states->{PhaseName($startnode)}) || die "startnode needs to be defined";    &SumNode($tree, $startnode, $states, $dim, "", \%$comp);    foreach $state (keys %$comp) {        $comp->{$state}{"name"} = $state;        ComputeDerivedFields($comp->{$state});    }    return $comp;}sub SumNode {    my($tree, $node, $states, $dim, $current, $comp) = @_;    my($child, $name, @cur, $temp);    $temp = {};    $name = &PhaseName($node);    if (defined($states->{$name})) {        @cur = split(/:/, $current);        foreach $i (0..$dim-1) {            if ($states->{$name}[$i]) {                $cur[$i] = $states->{$name}[$i];            }        }        $current = join(':', @cur);    }    SumAcross(\%$temp, $tree->{$node});    foreach $child (@{$tree->{$node}{"children"}}) {        if (&PhaseName($child) eq "DESCHED") {            # handle specially                    } else {            SumUp(\%$temp,                  &SumNode($tree, $child, $states, $dim, $current, $comp));        }    }    if (defined($states->{$name})) {        SumAcross(\%{$comp->{$current}}, $temp);        return 0;    }        return $temp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -