remove obsolete commands, remove etime, dump results to stdout in monitor mode when...
smbaker [Tue, 18 Dec 2012 02:13:48 +0000 (18:13 -0800)]
apps/gacks/gackswatcher.py

index 2dfe541..0eae897 100755 (executable)
@@ -179,7 +179,6 @@ class Cgroup:
         self.name = name
         self.utime = 0        # elapsed
         self.stime = 0        # elapsed
-        self.etime = 0
         self.last_utime = None
         self.last_stime = None
         self.charge = 0         # charge based on stime+utime
@@ -230,7 +229,6 @@ class Cgroup:
         if (cgroup.utime + cgroup.stime) >= threshold:
             self.utime += cgroup.utime
             self.stime += cgroup.stime
-            self.etime += cgroup.etime
             self.charge = self.charge + chargeUnit
 
         # Core_count doesn't use a threshold. If there's a nonzero core_count
@@ -308,7 +306,6 @@ class CgroupTotals:
         for cgroup_name,cgroup in self.working_cgroups.items():
             cgroup.stime = 0
             cgroup.mtime = 0
-            cgroup.etime = 0
             cgroup.core_count = 0
 
     def charge_working(self, threshold, chargeUnit):
@@ -355,7 +352,7 @@ class CgroupTotals:
         for cgroup in cglist:
             print "%-24s %8.2f %8d %8d %8.2f %8.2f" % (cgroup.name, cgroup.charge, cgroup.utime, cgroup.stime, cgroup.resv_charge, cgroup.core_charge)
 
-    def save_summary_file(self, filename):
+    def save_summary_file(self, filename, dump=False):
         cglist = self.get_groups_sorted_by_charge()
 
         dir = os.path.dirname(os.path.abspath(filename))
@@ -366,7 +363,10 @@ class CgroupTotals:
 
         f = open(tmp_fn, "w")
         for cgroup in cglist:
-            f.write("%s %0.2f %0.2f %0.2f\n" % (cgroup.name, cgroup.charge, cgroup.resv_charge, cgroup.core_charge))
+            line = "%s %0.2f %0.2f %0.2f" % (cgroup.name, cgroup.charge, cgroup.resv_charge, cgroup.core_charge)
+            f.write(line + "\n")
+            if dump:
+                print line
         f.close()
 
         os.rename(tmp_fn, filename)
@@ -417,7 +417,7 @@ def monitor(opts):
 
             # Save the totals
             print "generating report at time", int(tNow), "hour", hour
-            cgroups.save_summary_file(os.path.join(WATCHER_DIR, str(int(tNow))))
+            cgroups.save_summary_file(os.path.join(WATCHER_DIR, str(int(tNow))), not opts.daemon)
 
             # We've written the totals, so start over with a new 'cgroups'
             # to hold new totals.
@@ -491,7 +491,7 @@ def main():
     (opts, args) = parser.parse_args()
 
     if (len(args)==0):
-        print "specify a command: dumpworking, topgroups, chargetest, monitor"
+        print "specify a command: dumpworking, chargetest, monitor"
         sys.exit(-1)
 
     if opts.daemon:
@@ -502,8 +502,6 @@ def main():
 
     if cmd == "dumpworking":
         dump_working(opts)
-    elif cmd == "topgroups":
-        topgroups(opts)
     elif cmd == "chargetest":
         chargetest(opts)
     elif cmd == "monitor":