ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [2/2] ambari git commit: AMBARI-17527. Setup logging to find memory leak rootcause (aonishuk)
Date Fri, 01 Jul 2016 16:02:53 GMT
AMBARI-17527. Setup logging to find memory leak rootcause (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3a942404
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3a942404
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3a942404

Branch: refs/heads/branch-2.4
Commit: 3a942404d75ef09f245072ac22f5e040ca2ef15f
Parents: d1da45b
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Fri Jul 1 19:02:45 2016 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Fri Jul 1 19:02:45 2016 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/main.py        | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3a942404/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index 201264c..f93722f 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -18,6 +18,50 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
+import gc
+import traceback
+import threading
+import time
+
+def setup_memory_leak_debugger():
+  gc.disable_old = gc.disable
+  gc.enable_old = gc.enable
+  gc.isenabled_old = gc.isenabled
+
+  MEMORY_LEAK_DEBUG_FILEPATH = "/var/log/ambari-agent/memory_leak_debug.out"
+  def print_debug_info(result):
+    time_prefix =  time.strftime('%X %x')
+    thread_repr = repr(threading.currentThread())
+    stack_trace = ''.join(traceback.format_stack()).strip()
+
+    message = '{0} | {1}\n{2}\n'.format(time_prefix, thread_repr, stack_trace)
+    if result:
+      message = '{0}Result = {1}\n'.format(message, result)
+
+    with open(MEMORY_LEAK_DEBUG_FILEPATH, "a") as f:
+      f.write(message)
+
+  def disable_new():
+    result = gc.disable_old()
+    print_debug_info(result)
+    return result
+
+  def enable_new():
+    result = gc.enable_old()
+    print_debug_info(result)
+    return result
+
+  def isenabled_new():
+    result = gc.isenabled_old()
+    print_debug_info(result)
+    return result
+
+  gc.disable = disable_new
+  gc.enable = enable_new
+  gc.isenabled = isenabled_new
+
+setup_memory_leak_debugger()
+
 import logging.handlers
 import logging.config
 import signal


Mime
View raw message