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

📄 mxs_stats.pl

📁 一个用在mips体系结构中的操作系统
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!/usr/local/bin/perl5## 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. ## # This script reads MXS stat output and prints it in a human readable form. # $filename = "";$print_totals = $print_kernel = $print_user = $print_idle = $print_sync = 0;$factor_out_idle = 1;$add_sync_to_kernel = 0;$print_histograms = 0;foreach $i (0 .. $#ARGV) {    if ($ARGV[$i] eq '-t') {         $print_totals = 1;    } elsif ($ARGV[$i] eq '-h') {         $print_histograms = 1;    } elsif ($ARGV[$i] eq '-k') {         $print_kernel = 1;    } elsif ($ARGV[$i] eq '-u') {         $print_user = 1;    } elsif ($ARGV[$i] eq '-i') {         $print_idle = 1;    } elsif ($ARGV[$i] eq '-s') {         $print_sync = 1;    } elsif ($ARGV[$i] eq '-ii') {	 $factor_out_idle = 0;    } elsif ($ARGV[$i] eq '-as') {	 $add_sync_to_kernel = 1;    } elsif ($ARGV[$i] eq '-all') {         $print_totals = 1;         $print_kernel = 1;         $print_user = 1;         $print_idle = 1;         $print_sync = 1;    } else {        $filename = $ARGV[$i];    }}     if (($print_totals + $print_kernel + $print_user + $print_idle + $print_sync) == 0) {    $print_totals = 1;  # Default to printing totals only}  if ($filename eq "") {     print(STDERR "Usage: mxsstats [options] logfile\n");    exit 1;} if (!open(INPUT, $filename)) { die "Can't open $filename: $!"; }$totalcycles = 0;$numcpus = 0;$maxthreadhist = $maxreghist = $maxiwinhist = $maxldsthist = 0; line: while (<INPUT>) {    if (/^MXS:DUMPSTATS: CPU/) {       ($nu,$nu,$cpunum,$nu,$mode, $nu, $nu, $cyclecount, $rest) = split(' ', $_);	if (($cpunum == 0) && ($mode == 0)) {	    $totalcycles = 0;            undef %store;            undef %store_by_mode0;            undef %store_by_mode1;            undef %store_by_mode2;            undef %store_by_mode3;            undef %threadhist_by_mode0;            undef %threadhist_by_mode1;            undef %threadhist_by_mode2;            undef %threadhist_by_mode3;            undef %reghist_by_mode0;            undef %reghist_by_mode1;            undef %reghist_by_mode2;            undef %reghist_by_mode3;            undef %ldsthist_by_mode0;            undef %ldsthist_by_mode1;            undef %ldsthist_by_mode2;            undef %ldsthist_by_mode3;	            undef %iwinhist_by_mode0;            undef %iwinhist_by_mode1;            undef %iwinhist_by_mode2;            undef %iwinhist_by_mode3;       }              if ($cpunum >= $numcpus) {	   $numcpus = $cpunum+1;       }	$totalcycles += $cyclecount;         next line;    }    if (/^MXS:ST_/) {        ($name_string, $value, $rset) = split(' ', $_);	($nu, $name, $rest) = split(/:/, $name_string);        if ($mode == 0)   	   { $store_by_mode0{$name} += $value; }        elsif ($mode == 1)   	   { $store_by_mode1{$name} += $value; }        elsif ($mode == 2)   	   { $store_by_mode2{$name} += $value; }        elsif ($mode == 3)   	   { $store_by_mode3{$name} += $value; }        if (!defined($store{$name})) {            $store{$name} = $value;        } else {             $store{$name} += $value;        }        next line;    }    if (/^MXS:CYCLES:/) {        ($name_string, $cyclecount, $rset) = split(' ', $_);        if ($cpunum == 0) {   	       $totalcycles = 0;        }        $totalcycles += $cyclecount;    }    if (/^MXS:SAMPLE:/) {        ($name_string, $indexvalue, $value, $rst) = split(' ', $_);	($nu, $name, $rest) = split(/:/, $name_string);        $mode = $indexvalue;        if ($mode == 0)   	   { $store_by_mode0{$name} += $value; }        elsif ($mode == 1)   	   { $store_by_mode1{$name} += $value; }        elsif ($mode == 2)   	   { $store_by_mode2{$name} += $value; }        elsif ($mode == 3)   	   { $store_by_mode3{$name} += $value; }        if (!defined($store{$name})) {            $store{$name} = $value;        } else {             $store{$name} += $value;        }    }    if (/^MXS:NTHREADS_HIST:/) {        ($name_string, $indexvalue, $value, $rst) = split(' ', $_);         ($nu, $name, $rest) = split(/:/, $name_string);        if ($mode == 0)             {  $threadhist_by_mode0{$indexvalue} += $value; }        elsif ($mode == 1)            {  $threadhist_by_mode1{$indexvalue} += $value; }        elsif ($mode == 2)            {  $threadhist_by_mode2{$indexvalue} += $value; }        elsif ($mode == 3)            {  $threadhist_by_mode3{$indexvalue} += $value; }                if ($indexvalue > $maxthreadhist) {            $maxthreadhist = $indexvale;        }    }    if (/^MXS:REGS_HIST:/) {        ($name_string, $indexvalue, $value, $rst) = split(' ', $_);         ($nu, $name, $rest) = split(/:/, $name_string);        if ($mode == 0)             {  $reghist_by_mode0{$indexvalue} += $value; }        elsif ($mode == 1)            {  $reghist_by_mode1{$indexvalue} += $value; }        elsif ($mode == 2)            {  $reghist_by_mode2{$indexvalue} += $value; }        elsif ($mode == 3)            {  $reghist_by_mode3{$indexvalue} += $value; }        if ($indexvalue > $maxreghist) {            $maxreghist = $indexvalue;        }    }    if (/^MXS:IWIN_/) {        ($name_string, $indexvalue, $value, $rst) = split(' ', $_);         ($nu, $name, $rest) = split(/:/, $name_string);        if ($mode == 0)             {  $iwinhist_by_mode0{$name . $indexvalue} += $value; }        elsif ($mode == 1)            {  $iwinhist_by_mode1{$name . $indexvalue} += $value; }        elsif ($mode == 2)            {  $iwinhist_by_mode2{$name . $indexvalue} += $value; }        elsif ($mode == 3)            {  $iwinhist_by_mode3{$name . $indexvalue} += $value; }        if ($indexvalue > $maxiwinhist) {            $maxiwinhist = $indexvalue;        }    }    if (/^MXS:LDST_/) {        ($name_string, $indexvalue, $value, $rst) = split(' ', $_);         ($nu, $name, $rest) = split(/:/, $name_string);        if ($mode == 0)             {  $ldsthist_by_mode0{$name . $indexvalue} += $value; }        elsif ($mode == 1)            {  $ldsthist_by_mode1{$name . $indexvalue} += $value; }        elsif ($mode == 2)            {  $ldsthist_by_mode2{$name . $indexvalue} += $value; }        elsif ($mode == 3)            {  $ldsthist_by_mode3{$name . $indexvalue} += $value; }        if ($indexvalue > $maxldsthist) {            $maxldsthist = $indexvalue;        }    }    next line;}if ($store{'ST_RUN_CYCLES'} == 0) {    die "No MXS execution cycles found";}printf("Run %.0f cycles on %d cpus\n", $totalcycles, $numcpus);if (!defined($store_by_mode0{'ST_RUN_CYCLES'})) {    $store_by_mode0{'ST_RUN_CYCLES'} = 0;}if (!defined($store_by_mode1{'ST_RUN_CYCLES'})) {    $store_by_mode1{'ST_RUN_CYCLES'} = 0;}if (!defined($store_by_mode2{'ST_RUN_CYCLES'})) {    $store_by_mode2{'ST_RUN_CYCLES'} = 0;}if (!defined($store_by_mode3{'ST_RUN_CYCLES'})) {    $store_by_mode3{'ST_RUN_CYCLES'} = 0;}printf("  Kernel: %4.1f%%\n",        100.0 * $store_by_mode0{'ST_RUN_CYCLES'}/$store{'ST_RUN_CYCLES'});printf("    User: %4.1f%%\n",        100.0 * $store_by_mode1{'ST_RUN_CYCLES'}/$store{'ST_RUN_CYCLES'});printf("    Idle: %4.1f%%\n",        100.0 * $store_by_mode2{'ST_RUN_CYCLES'}/$store{'ST_RUN_CYCLES'});printf("    Sync: %4.1f%%\n",        100.0 * $store_by_mode3{'ST_RUN_CYCLES'}/$store{'ST_RUN_CYCLES'});if ($print_totals) {     if ($factor_out_idle) {         while (($key,$value) = each %store_by_mode2) {             &Z($key);	     $store{$key} -= $value;	 }	printf("******************************************** STATS total without idle\n");     } else { 	printf("******************************************** STATS total\n");    }    %st = (%store);    &PRINT_STATS();    $hist_samples = $store_by_mode0{'SAMPLE'} +  $store_by_mode1{'SAMPLE'} +         $store_by_mode3{'SAMPLE'};    if (!$factor_out_idle) {        $hist_samples += $store_by_mode2{'SAMPLE'};    }    if ($hist_samples) {         %threadhist = (%threadhist_by_mode0);                %reghist = (%reghist_by_mode0);                %iwinhist = (%iwinhist_by_mode0);               %ldsthist = (%ldsthist_by_mode0);                while (($key,$value) = each %threadhist_by_mode1) {            $threadhist{$key} += $value;        }        while (($key,$value) = each %reghist_by_mode1) {            $reghist{$key} += $value;        }        while (($key,$value) = each %iwinhist_by_mode1) {            $iwinhist{$key} += $value;        }        while (($key,$value) = each %ldsthist_by_mode1) {            $ldsthist{$key} += $value;        }        if (!factor_out_idle) {             while (($key,$value) = each %threadhist_by_mode2) {                $threadhist{$key} += $value;            }            while (($key,$value) = each %reghist_by_mode2) {                $reghist{$key} += $value;            }            while (($key,$value) = each %iwinhist_by_mode2) {                $iwinhist{$key} += $value;            }            while (($key,$value) = each %ldsthist_by_mode2) {                $ldsthist{$key} += $value;            }        }        while (($key,$value) = each %threadhist_by_mode3) {            $threadhist{$key} += $value;        }        while (($key,$value) = each %reghist_by_mode3) {            $reghist{$key} += $value;        }        while (($key,$value) = each %iwinhist_by_mode3) {            $iwinhist{$key} += $value;        }        while (($key,$value) = each %ldsthist_by_mode3) {            $ldsthist{$key} += $value;        }    }    &PRINT_HISTS();}if ($print_kernel) {     %st = (%store_by_mode0);    printf("******************************************* STATS in kernel mode\n");    &PRINT_STATS();    $hist_samples = $store_by_mode0{'SAMPLE'};    if ($hist_samples) {         %threadhist = (%threadhist_by_mode0);                %reghist = (%reghist_by_mode0);                %iwinhist = (%iwinhist_by_mode0);               %ldsthist = (%ldsthist_by_mode0);                if ($add_sync_to_kernel) {            $hist_samples +=  $store_by_mode3{'SAMPLE'};            while (($key,$value) = each %threadhist_by_mode3) {                $threadhist{$key} += $value;            }            while (($key,$value) = each %reghist_by_mode3) {                $reghist{$key} += $value;            }            while (($key,$value) = each %iwinhist_by_mode3) {                $iwinhist{$key} += $value;            }            while (($key,$value) = each %ldsthist_by_mode3) {                $ldsthist{$key} += $value;            }        }        &PRINT_HISTS();    }}if ($print_user) {     %st = (%store_by_mode1);    printf("******************************************* STATS in user mode\n");    &PRINT_STATS();    $hist_samples +=  $store_by_mode1{'SAMPLE'};    if ($hist_samples) {         %threadhist = (%threadhist_by_mode1);                %reghist = (%reghist_by_mode1);                %iwinhist = (%iwinhist_by_mode1);               %ldsthist = (%ldsthist_by_mode1);                &PRINT_HISTS();    }}if ($print_idle) {     %st = (%store_by_mode2);    printf("******************************************* STATS in idle mode\n");    &PRINT_STATS();    $hist_samples +=  $store_by_mode2{'SAMPLE'};    if ($hist_samples) {         %threadhist = (%threadhist_by_mode2);                %reghist = (%reghist_by_mode2);                %iwinhist = (%iwinhist_by_mode2);               %ldsthist = (%ldsthist_by_mode2);                &PRINT_HISTS();    }}if ($print_sync) {     %st = (%store_by_mode3);    printf("******************************************* STATS in sync mode\n");    &PRINT_STATS();    $hist_samples +=  $store_by_mode3{'SAMPLE'};    if ($hist_samples) {         %threadhist = (%threadhist_by_mode3);                %reghist = (%reghist_by_mode3);                %iwinhist = (%iwinhist_by_mode3);               %ldsthist = (%ldsthist_by_mode3);                &PRINT_HISTS();    }}sub PRINT_STATS {    $nz = .0000000001;   #  Used to avoid divided by zero

⌨️ 快捷键说明

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