]> xenbits.xensource.com Git - xenclient/build.git/commitdiff
Initial commit of guest-process-stats.
authorDaniel Ferstay <daniel.ferstay@citrix.com>
Tue, 20 Oct 2009 21:21:33 +0000 (14:21 -0700)
committerDaniel Ferstay <daniel.ferstay@citrix.com>
Tue, 20 Oct 2009 21:21:33 +0000 (14:21 -0700)
A ruby script that collects process statistics for all running domains.
Output contains the following columns: PID, NAME, KNL_TIME(ms), USR_TIME(ms), MEMORY(KB), CPU(%)

target/generic/target_xenclient_skeleton/usr/bin/guest-process-stats [new file with mode: 0755]

diff --git a/target/generic/target_xenclient_skeleton/usr/bin/guest-process-stats b/target/generic/target_xenclient_skeleton/usr/bin/guest-process-stats
new file mode 100755 (executable)
index 0000000..fa16e3e
--- /dev/null
@@ -0,0 +1,54 @@
+#! /usr/bin/ruby
+
+PROC_LIST = "guest-process-list"
+
+# Script that prints a process accounting report for all running domains.
+# Output contains the following columns:
+# PID, NAME, KNL_TIME(ms), USR_TIME(ms), MEMORY(KB), CPU(%)
+
+`xenstore-list /local/domain`.each_line { |domid|
+  domid.chomp!
+  next if domid.to_i == 0 # No need to inspect Dom0
+
+  puts "DOMAIN #{domid}"
+  
+  pid2info = {} # pid => total_cpu_time
+  line_num = 0
+  `#{PROC_LIST} #{domid} --usrtime --knltime`.each_line { |line|
+    line.chomp!
+    line_num += 1
+    next if line_num == 1 # skip column headers
+    begin
+      pid, name, knl_time, usr_time = line.split
+      pid2info[pid] = knl_time.to_i + usr_time.to_i
+    rescue
+    end
+  }
+
+  sleep(1) # sleep 1 sec
+
+  line_num = 0
+  `#{PROC_LIST} #{domid} --usrtime --knltime --memusage`.each_line { |line|
+    line.chomp!
+    line_num += 1
+    if line_num == 1
+      puts "#{line}  CPU" # print header
+      next
+    end
+
+    begin
+      pid, name, knl_time, usr_time, mem_usage = line.split
+      cpu_usage = "00"
+      if pid2info.has_key? pid
+        prev_time = pid2info[pid]
+        curr_time = knl_time.to_i + usr_time.to_i
+        pct = (curr_time - prev_time) / 1000
+        cpu_usage = "%02d" % (pct * 100)
+      end
+      
+      puts "#{line.chomp}  #{cpu_usage}"
+    rescue
+    end
+  }
+  
+}