3 # ------------------------------------------------
4 # Copyright 2014 AT&T Intellectual Property
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # -------------------------------------------
24 $interval = int($ARGV[0]);
29 print STDERR "Argument 1 ($ARGV[0]) ignored.\n";
35 $interval = int($ARGV[1]);
40 print STDERR "Argument 2 ($ARGV[1]) ignored.\n";
45 print STDERR "Only 2 arguments accepted, additional args ignored.\n";
48 open O, ">resource_log.csv" or die "Can't open resource_log.csv\n";
53 open I,"getconf PAGESIZE |";
56 $pagesize = int($line);
60 $effective_uid = $REAL_USER_ID;
61 $ps_cmd = "ps -U $effective_uid |";
69 @flds = split /\s+/,$line;
70 if($flds[3] =~ /rts/){
71 push @rts_pids,int($flds[0]);
73 if($flds[3] =~ /hfta_(\d+)/){
74 $hfta_pid{$1} = int($flds[0]);
78 $rts_pids = sort {$a<=>$b} @rts_pids;
81 print O "START monitoring at time $now\n";
82 print O "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
84 print "START monitoring at time $now\n";
85 print "ts,proc,pid,utime,stime,vm_size,rss,pagesize\n";
88 #foreach $p (@rts_pids){
91 #print "\nHFTA PIDs:\n";
92 # foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
93 # print "($h,",$hfta_pid{$h},") ";
99 foreach $p (@rts_pids){
101 print O "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
103 print "$now,rts,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
106 foreach $h (sort {$a<=>$b} keys(%hfta_pid)){
109 print O "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
111 print "$now,hfta_$h,$p,$user_time,$sys_time,$vm_size,$resident_set_size,$pagesize\n";
127 open I_PROC_STATS,"/proc/$pid/stat";
129 $line=<I_PROC_STATS>;
132 #print "getstats($pid): $line\n";
135 @flds = split / +/,$line;
138 $pid = $flds[$pos]; $pos++;
139 $fname = $flds[$pos]; $pos++;
140 $state = $flds[$pos]; $pos++;
141 $pppid = $flds[$pos]; $pos++;
142 $pgrp = $flds[$pos]; $pos++;
143 $session = $flds[$pos]; $pos++;
144 $tty_n = $flds[$pos]; $pos++;
145 $tpgid = $flds[$pos]; $pos++;
146 $flags = $flds[$pos]; $pos++;
147 $minor_faults = $flds[$pos]; $pos++;
148 $child_minor_faults = $flds[$pos]; $pos++;
149 $major_faults = $flds[$pos0]; $pos++;
150 $child_major_faults = $flds[$pos0]; $pos++;
151 $user_time = $flds[$pos]; $pos++;
152 $sys_time = $flds[$pos]; $pos++;
153 $child_user_time = $flds[$pos]; $pos++;
154 $child_sys_time = $flds[$pos]; $pos++;
155 $priority = $flds[$pos]; $pos++;
156 $nice = $flds[$pos]; $pos++;
157 $num_threads = $flds[$pos]; $pos++;
158 $interval_timer_realvalue = $flds[$pos]; $pos++;
159 $start_time = $flds[$pos]; $pos++;
160 $vm_size = $flds[$pos]; $pos++;
161 $resident_set_size = $flds[$pos]; $pos++;
162 $rss_limit = $flds[$pos]; $pos++;
163 $startcode = $flds[$pos]; $pos++;
164 $endcode = $flds[$pos]; $pos++;
165 $startstack = $flds[$pos]; $pos++;
166 $curr_kernel_stack_ptr = $flds[$pos]; $pos++;
167 $curr_instruction_ptr = $flds[$pos]; $pos++;
168 $signal = $flds[$pos]; $pos++;
169 $sigblocked = $flds[$pos]; $pos++;
170 $sigignore = $flds[$pos]; $pos++;
171 $wchan = $flds[$pos]; $pos++;
172 $nswap = $flds[$pos]; $pos++;
173 $exit_signal = $flds[$pos]; $pos++;
174 $processor = $flds[$pos]; $pos++;
175 $rt_priority = $flds[$pos]; $pos++;
176 $policy = $flds[$pos]; $pos++;
177 $aggr_block_io_delays = $flds[$pos]; $pos++;
178 $guest_time = $flds[$pos]; $pos++;
179 $cguest_time = $flds[$pos]; $pos++;