Enable heap prof of stmgr in heron-shell.
diff --git a/heron/executor/src/python/heron_executor.py b/heron/executor/src/python/heron_executor.py
index 8306c24..6403876 100755
--- a/heron/executor/src/python/heron_executor.py
+++ b/heron/executor/src/python/heron_executor.py
@@ -769,7 +769,7 @@
Log.info("%s exited too many times" % name)
sys.exit(1)
time.sleep(self.interval_between_runs)
- p = self._run_process(name, command)
+ p = self._run_process(name, command, self.shell_env)
del self.processes_to_monitor[pid]
self.processes_to_monitor[p.pid] =\
ProcessInfo(p, name, command, old_process_info.attempts + 1)
@@ -892,6 +892,13 @@
# PEX_ROOT shell environment before forking the processes
shell_env = os.environ.copy()
shell_env["PEX_ROOT"] = os.path.join(os.path.abspath('.'), ".pex")
+ # Refer to https://gperftools.github.io/gperftools/heapprofile.html
+ # for details of settings of gperftools heap profiler
+ shell_env["HEAPPROFILE"] = "stmgr.hprof"
+ shell_env["HEAP_PROFILE_ALLOCATION_INTERVAL"] = "2147483648"
+ shell_env["HEAP_PROFILE_INUSE_INTERVAL"] = "1073741824"
+ shell_env["HEAPPROFILESIGNAL"] = str(signal.SIGUSR1)
+
# Instantiate the executor, bind it to signal handlers and launch it
executor = HeronExecutor(sys.argv, shell_env)
diff --git a/heron/shell/src/python/handlers/__init__.py b/heron/shell/src/python/handlers/__init__.py
index 7c574d5..195a1bc 100644
--- a/heron/shell/src/python/handlers/__init__.py
+++ b/heron/shell/src/python/handlers/__init__.py
@@ -8,3 +8,4 @@
from jstackhandler import JstackHandler
from memoryhistogramhandler import MemoryHistogramHandler
from pidhandler import PidHandler
+from stmgrheapprofhandler import StmgrHeapProfHandler
diff --git a/heron/shell/src/python/handlers/stmgrheapprofhandler.py b/heron/shell/src/python/handlers/stmgrheapprofhandler.py
new file mode 100644
index 0000000..c6464bf
--- /dev/null
+++ b/heron/shell/src/python/handlers/stmgrheapprofhandler.py
@@ -0,0 +1,45 @@
+# Copyright 2017 Twitter. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+''' stmgrheapprofhandler.py '''
+import glob
+import json
+import os
+import signal
+import tornado.web
+
+from heron.shell.src.python import utils
+
+class StmgrHeapProfHandler(tornado.web.RequestHandler):
+ """
+ Responsible for getting the process ID for an instance.
+ """
+
+ # pylint: disable=attribute-defined-outside-init
+ @tornado.web.asynchronous
+ def get(self):
+ ''' get method '''
+ self.content_type = 'application/json'
+ stmgr_pid_files = glob.glob('stmgr*.pid')
+ try:
+ pid_file = stmgr_pid_files[0]
+ with open(pid_file, 'r') as f:
+ pid = f.read()
+ os.kill(int(pid), signal.SIGUSR1)
+ self.write('Performing heap profiling on stream manager...')
+ self.finish()
+ except:
+ self.write("Not stream manager found")
+ self.set_status(404)
+ self.finish()
diff --git a/heron/shell/src/python/main.py b/heron/shell/src/python/main.py
index cd3ad61..1fbeebd 100644
--- a/heron/shell/src/python/main.py
+++ b/heron/shell/src/python/main.py
@@ -34,6 +34,7 @@
(r"^/filedata/(.*)", handlers.FileDataHandler),
(r"^/filestats/(.*)", handlers.FileStatsHandler),
(r"^/download/(.*)", handlers.DownloadHandler),
+ (r"^/stmgrheapprof", handlers.StmgrHeapProfHandler),
])
diff --git a/heron/stmgr/src/cpp/BUILD b/heron/stmgr/src/cpp/BUILD
index 548581a..a726c59 100644
--- a/heron/stmgr/src/cpp/BUILD
+++ b/heron/stmgr/src/cpp/BUILD
@@ -111,6 +111,7 @@
"server/stmgr-main.cpp",
],
copts = [
+ "-Ithird_party",
"-Iheron",
"-Iheron/common/src/cpp",
"-Iheron/statemgrs/src/cpp",
@@ -129,6 +130,7 @@
"//heron/common/src/cpp/metrics:metrics-cxx",
"//heron/statemgrs/src/cpp:statemgrs-cxx",
"//third_party/yaml-cpp:yaml-cxx",
+ "//third_party/gperftools:profiler-cxx",
],
linkstatic = 1,
)
diff --git a/heron/stmgr/src/cpp/server/stmgr-main.cpp b/heron/stmgr/src/cpp/server/stmgr-main.cpp
index 4daebfe..c686145 100644
--- a/heron/stmgr/src/cpp/server/stmgr-main.cpp
+++ b/heron/stmgr/src/cpp/server/stmgr-main.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <gperftools/heap-profiler.h>
#include <iostream>
#include <string>
#include <vector>
@@ -55,6 +56,8 @@
sp_int32 shell_port = atoi(argv[11]);
sp_string heron_internals_config_filename = argv[12];
+ HeapProfilerStart("stmgr");
+
EventLoopImpl ss;
// Read heron internals config from local file
@@ -82,5 +85,6 @@
high_watermark, low_watermark);
mgr.Init();
ss.loop();
+ HeapProfilerStop();
return 0;
}
diff --git a/third_party/gperftools/BUILD b/third_party/gperftools/BUILD
index 195b2e2..5161b76 100644
--- a/third_party/gperftools/BUILD
+++ b/third_party/gperftools/BUILD
@@ -100,6 +100,7 @@
"lib/libprofiler.a",
],
hdrs = [
+ "include/gperftools/heap-profiler.h",
"include/gperftools/profiler.h",
],
includes = ["include"],