--- /dev/null
+#! /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
+ }
+
+}