diff options
author | Rob Austein <sra@hactrn.net> | 2010-01-23 04:20:34 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2010-01-23 04:20:34 +0000 |
commit | 4fcf2c4c6b5a59ee488d70c0f0f47618f9791721 (patch) | |
tree | 549e11536fa572c42663401e90465a4e6324b1fa /rpkid | |
parent | 57cb60faa1625b4ac53676858be924c1241ccfea (diff) |
Add cutoff threshold and tuple tracking to gc_summary.
svn path=/rpkid/rpki/async.py; revision=2960
Diffstat (limited to 'rpkid')
-rw-r--r-- | rpkid/rpki/async.py | 25 | ||||
-rw-r--r-- | rpkid/rpki/config.py | 2 |
2 files changed, 18 insertions, 9 deletions
diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py index 21ff0f40..c086b21a 100644 --- a/rpkid/rpki/async.py +++ b/rpkid/rpki/async.py @@ -349,29 +349,38 @@ class gc_summary(object): Periodic summary of GC state, for tracking down memory bloat. """ - def __init__(self, interval): + def __init__(self, interval, threshold = 0): if isinstance(interval, (int, long)): interval = rpki.sundial.timedelta(seconds = interval) self.interval = interval + self.threshold = threshold self.timer = timer(handler = self.handler) self.timer.set(self.interval) def handler(self): rpki.log.debug("gc_summary: Running gc.collect()") gc.collect() - rpki.log.debug("gc_summary: Summarizing") + rpki.log.debug("gc_summary: Summarizing (threshold %d)" % self.threshold) total = {} + tuples = {} for g in gc.get_objects(): - t = type(g).__name__ - if t in total: - total[t] += 1 - else: - total[t] = 1 + k = type(g).__name__ + total[k] = total.get(k, 0) + 1 + if isinstance(g, tuple): + k = ", ".join(type(x).__name__ for x in g) + tuples[k] = tuples.get(k, 0) + 1 rpki.log.debug("gc_summary: Sorting result") total = total.items() total.sort(reverse = True, key = lambda x: x[1]) + tuples = tuples.items() + tuples.sort(reverse = True, key = lambda x: x[1]) rpki.log.debug("gc_summary: Object type counts in descending order") for name, count in total: - rpki.log.debug("gc_summary: %8d %s" % (count, name)) + if count > self.threshold: + rpki.log.debug("gc_summary: %8d %s" % (count, name)) + rpki.log.debug("gc_summary: Tuple counts, length, and leading types in descending order") + for types, count in tuples: + if count > self.threshold: + rpki.log.debug("gc_summary: %8d (%s)" % (count, types)) rpki.log.debug("gc_summary: Scheduling next cycle") self.timer.set(self.interval) diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py index 068762e2..302afe8a 100644 --- a/rpkid/rpki/config.py +++ b/rpkid/rpki/config.py @@ -188,6 +188,6 @@ class parser(object): pass try: - rpki.async.gc_summary(self.getint("gc_summary")) + rpki.async.gc_summary(self.getint("gc_summary"), self.getint("gc_summary_threshold", 0)) except ConfigParser.NoOptionError: pass |