5 use Time::HiRes qw / usleep / ;
6 use List::Util qw / min max /;
17 &GetOptions("period=i"=>\$period, "numtimes=i"=>\$numtimes, "topk=i"=>\$topk);
19 $#ARGV==0 or die "v3_guest_mem_track_stat.pl [--numtimes=num(-1=forever)] [--period=milliseconds] [--topk=num] /dev/v3-vmN\n";
25 $data = `v3_guest_mem_track $vm snapshot text _`;
27 $data=~/Time:\s+(\d+)/ or die "Cannot parse for time\n";
30 $data=~/Interval:\s+(\d+)\s+cycles/ or die "Cannot parse for time\n";
33 $data=~/Access:\s+(\S+)/ or die "Cannot parse for access\n";
36 $data=~/Reset:\s+(\S+)/ or die "Cannot parse for reset\n";
39 $data=~/Cores:\s*(\d+)/ or die "Cannot parse for cores\n";
42 $data=~/Pages:\s*(\d+)/ or die "Cannot parse for pages\n";
47 for ($core=0;$core<$numcores;$core++) {
48 $data=~/Core\s+$core\s+\((\d+)\s+to\s+(\d+)\,\s+(\d+)\s+pages\s+touched\)\s+\:\s+(\S+)/ or die "Cannot parse core $core\n";
56 $earliest=min(@start);
59 print "\033[2J\033[0;0H"; # clear
63 print "Time:\t$time seconds\n";
64 print "Access:\t$access\n";
65 print "Reset:\t$reset\n";
66 print "Inter:\t$interval cycles (",$interval/$mhz/1000," ms)\n";
67 print "Cores:\t$numcores\n";
68 print "Pages:\t$numpages\n";
69 print "Time:\t$earliest to $latest (",($latest-$earliest)/$mhz/1000," ms interval)\n\n";
71 for ($core=0;$core<$numcores;$core++) {
72 print "Core $core: $pages[$core] pages ($start[$core] to $end[$core])\n";
75 for ($i=0; $i<$numcores; $i++) {
76 for ($j=0; $j<=$i; $j++) {
78 $common[$i][$j]=count(intersect($bits[$i],$bits[$j]));
82 print "\nIntersection (count)\n\n";
84 for ($i=0;$i<$numcores;$i++) {
89 for ($i=0;$i<$numcores;$i++) {
91 for ($j=0;$j<=$i;$j++) {
92 print "\t",$common[$i][$j];
97 print "\nIntersection (%)\n\n";
99 for ($i=0;$i<$numcores;$i++) {
104 for ($i=0;$i<$numcores;$i++) {
106 for ($j=0;$j<=$i;$j++) {
107 print "\t", sprintf("%4.2f",($common[$i][$j]/$numpages));
112 %ph=page_hash(\@bits);
114 @pageranks = sort { $#{$ph{$b}} != $#{$ph{$a}} ? ($#{$ph{$b}} <=> $#{$ph{$a}}) : $a<=>$b } keys %ph;
116 print "\nPages by popularity and sharing cores (top-$topk)\n\n";
118 print "Page\tCores\n";
119 for ($i=0;$i<min($topk,$#pageranks+1);$i++) {
120 print $pageranks[$i],"\t", join(" ",@{$ph{$pageranks[$i]}}),"\n";
127 usleep($period*1000);
137 my $n = length($data);
141 for ($i=0;$i<$n;$i++) {
142 if ((substr($data,$i,1) eq "X")) {
152 my ($left, $right)=@_;
163 for ($i=0;$i<$n;$i++) {
164 if ((substr($left,$i,1) eq "X") && (substr($right,$i,1) eq "X")) {
165 substr($out,$i,1)="X";
167 substr($out,$i,1)=".";
176 my $data=`cat /proc/cpuinfo`;
178 $data=~/cpu\s+MHz\s+:\s+(\S+)/ or die "Cannot find MHz\n";
190 for ($i=0;$i<=$#{$br};$i++) {
191 for ($j=0;$j<length($br->[$i]);$j++) {
192 if ((substr($br->[$i],$j,1) eq "X")) {