Преглед изворни кода

HUE-296 [core] Memory profiling config

Abraham Elmahrek пре 11 година
родитељ
комит
a106006

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -33,6 +33,9 @@
   # Enable or disable backtrace for server error
   http_500_debug_mode=false
 
+  # Enable or disable memory profiling.
+  ## memory_profiler=false
+
   # Server email for internal error messages
   ## django_server_email='hue@localhost.localdomain'
 

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -42,6 +42,9 @@
   # Enable or disable backtrace for server error
   ## http_500_debug_mode=true
 
+  # Enable or disable memory profiling.
+  ## memory_profiler=false
+
   # Server email for internal error messages
   ## django_server_email='hue@localhost.localdomain'
 

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -687,6 +687,12 @@ HTTP_500_DEBUG_MODE = Config(
   default=True
 )
 
+MEMORY_PROFILER = Config(
+  key='memory_profiler',
+  help=_('Enable or disable memory profiling.'),
+  type=coerce_bool,
+  default=False)
+
 AUDIT_EVENT_LOG_DIR = Config(
   key="audit_event_log_dir",
   help=_("The directory where to store the auditing logs. Auditing is disable if the value is empty."),

+ 3 - 2
desktop/core/src/desktop/settings.py

@@ -360,5 +360,6 @@ SKIP_SOUTH_TESTS = True
 os.environ['KRB5CCNAME'] = desktop.conf.KERBEROS.CCACHE_PATH.get()
 
 # Memory
-MEMORY_PROFILER = hpy()
-MEMORY_PROFILER.setrelheap()
+if desktop.conf.MEMORY_PROFILER.get():
+  MEMORY_PROFILER = hpy()
+  MEMORY_PROFILER.setrelheap()

+ 3 - 0
desktop/core/src/desktop/views.py

@@ -241,6 +241,9 @@ def memory(request):
   if not request.user.is_superuser:
     return HttpResponse(_("You must be a superuser."))
 
+  if not hasattr(settings, 'MEMORY_PROFILER'):
+    return HttpResponse(_("You must enable the memory profiler via the memory_profiler config in the hue.ini."))
+
   heap = settings.MEMORY_PROFILER.heap()
   heap = heap[int(request.GET.get('from', 0)):int(request.GET.get('to', len(heap)))]
   if 'index' in request.GET: