Add periodic CPython garbage collector statistics logging to aid in
tracking down a memory leak and as a general health beacon for the long
running process.
The interval at which stats are logged is configurable.
Signed-off-by: Gregory Smith <gps@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4021 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/gc_stats_unittest.py b/scheduler/gc_stats_unittest.py
new file mode 100644
index 0000000..ddb5065
--- /dev/null
+++ b/scheduler/gc_stats_unittest.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import gc
+import logging
+
+import common
+from autotest_lib.client.common_lib.test_utils import mock
+from autotest_lib.client.common_lib.test_utils import unittest
+from autotest_lib.scheduler import gc_stats
+
+
+class TestGcStats(unittest.TestCase):
+ def setUp(self):
+ self.god = mock.mock_god()
+
+
+ def tearDown(self):
+ self.god.unstub_all()
+
+
+ def test_log_garbage_collector_stats(self):
+ # Call this for code coverage.
+ # Prevent log spam from this test but do test that the log
+ # message formats correctly.
+ def _mock_logging_func(message, *args):
+ if args:
+ message %= args
+ self.god.stub_with(logging, 'debug', _mock_logging_func)
+ self.god.stub_with(logging, 'info', _mock_logging_func)
+ gc_stats._log_garbage_collector_stats()
+ # Add a new dict, exercise the delta counting & printing code.
+ y = {}
+ gc_stats._log_garbage_collector_stats(1)
+
+
+if __name__ == '__main__':
+ unittest.main()