X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=bin%2Fmonitor_gs.pl;h=e42eb850fe946e6b03d175ed0de3d77b57579f61;hb=refs%2Fchanges%2F82%2F5282%2F1;hp=7fd96f4008cb56aee822df1518e805ae272da64c;hpb=07495effe193ca3f73c3bf0ce417068f9ac9dcdd;p=com%2Fgs-lite.git diff --git a/bin/monitor_gs.pl b/bin/monitor_gs.pl index 7fd96f4..e42eb85 100755 --- a/bin/monitor_gs.pl +++ b/bin/monitor_gs.pl @@ -1,180 +1,180 @@ -#! /usr/bin/perl - -# ------------------------------------------------ -# Copyright 2014 AT&T Intellectual Property -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ------------------------------------------- - -use English; - -$interval = 10; -$to_tty = 0; -if(scalar(@ARGV)>0){ - if(int($ARGV[0])>0){ - $interval = int($ARGV[0]); - }else{ - if($ARGV[0] eq '-'){ - $to_tty = 1; - }else{ - print STDERR "Argument 1 ($ARGV[0]) ignored.\n"; - } - } -} -if(scalar(@ARGV)>1){ - if(int($ARGV[1])>0){ - $interval = int($ARGV[1]); - }else{ - if($ARGV[1] eq '-'){ - $to_tty = 1; - }else{ - print STDERR "Argument 2 ($ARGV[1]) ignored.\n"; - } - } -} -if(scalar(@ARGV)>2){ - print STDERR "Only 2 arguments accepted, additional args ignored.\n"; -} - -open O, ">resource_log.csv" or die "Can't open resource_log.csv\n"; - - - -# get the page size -open I,"getconf PAGESIZE |"; -$line=; -chomp($line); -$pagesize = int($line); -close(I); - - -$effective_uid = $REAL_USER_ID; -$ps_cmd = "ps -U $effective_uid |"; - -%hfta_pid=(); - -open P,$ps_cmd; -while($line=
){
- chomp($line);
- $line =~ s/^\s+//;
- @flds = split /\s+/,$line;
- if($flds[3] =~ /rts/){
- push @rts_pids,int($flds[0]);
- }
- if($flds[3] =~ /hfta_(\d+)/){
- $hfta_pid{$1} = int($flds[0]);
- }
-}
-
-$rts_pids = sort {$a<=>$b} @rts_pids;
-
-$now=time();
-print O "START monitoring at time $now\n";
-print O "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
-if(to_tty){
- print "START monitoring at time $now\n";
- print "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
-}
-#print "RTS PIDs:\n";
-#foreach $p (@rts_pids){
-# print "$p ";
-#}
-#print "\nHFTA PIDs:\n";
-# foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
-# print "($h,",$hfta_pid{$h},") ";
-#}
-#print "\n";
-
-while(1){
- $now=time();
- foreach $p (@rts_pids){
- get_proc_stats($p);
- print O "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
- if(to_tty){
- print "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
- }
- }
- foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
- $p=$hfta_pid{$h};
- get_proc_stats($p);
- print O "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
- if(to_tty){
- print "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
- }
- }
-
- sleep($interval);
-}
-
-
-
-sub get_proc_stats{
-my $pid = shift;
-my $line;
-my @flds;
-my $pos;
-
-
-open I_PROC_STATS,"/proc/$pid/stat";
-
-$line= ){
+ chomp($line);
+ $line =~ s/^\s+//;
+ @flds = split /\s+/,$line;
+ if($flds[3] =~ /rts/){
+ push @rts_pids,int($flds[0]);
+ }
+ if($flds[3] =~ /hfta_(\d+)/){
+ $hfta_pid{$1} = int($flds[0]);
+ }
+}
+
+$rts_pids = sort {$a<=>$b} @rts_pids;
+
+$now=time();
+print O "START monitoring at time $now\n";
+print O "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
+if(to_tty){
+ print "START monitoring at time $now\n";
+ print "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
+}
+#print "RTS PIDs:\n";
+#foreach $p (@rts_pids){
+# print "$p ";
+#}
+#print "\nHFTA PIDs:\n";
+# foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
+# print "($h,",$hfta_pid{$h},") ";
+#}
+#print "\n";
+
+while(1){
+ $now=time();
+ foreach $p (@rts_pids){
+ get_proc_stats($p);
+ print O "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
+ if(to_tty){
+ print "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
+ }
+ }
+ foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
+ $p=$hfta_pid{$h};
+ get_proc_stats($p);
+ print O "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
+ if(to_tty){
+ print "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
+ }
+ }
+
+ sleep($interval);
+}
+
+
+
+sub get_proc_stats{
+my $pid = shift;
+my $line;
+my @flds;
+my $pos;
+
+
+open I_PROC_STATS,"/proc/$pid/stat";
+
+$line=