Browse Source

[minor] add profiling in development server

version-14
Pratik Vyas 11 years ago
parent
commit
f31a5510e1
2 changed files with 9 additions and 3 deletions
  1. +6
    -1
      webnotes/app.py
  2. +3
    -2
      wnf.py

+ 6
- 1
webnotes/app.py View File

@@ -9,6 +9,7 @@ from werkzeug.wrappers import Request, Response
from werkzeug.local import LocalManager from werkzeug.local import LocalManager
from webnotes.middlewares import StaticDataMiddleware from webnotes.middlewares import StaticDataMiddleware
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from werkzeug.contrib.profiler import ProfilerMiddleware
from webnotes import get_config from webnotes import get_config


import mimetypes import mimetypes
@@ -58,7 +59,11 @@ application = StaticDataMiddleware(application, {
'/': 'public', '/': 'public',
}) })


def serve(port=8000):

def serve(port=8000, profile=False):
global application
from werkzeug.serving import run_simple from werkzeug.serving import run_simple
if profile:
application = ProfilerMiddleware(application)
run_simple('0.0.0.0', int(port), application, use_reloader=True, run_simple('0.0.0.0', int(port), application, use_reloader=True,
use_debugger=True, use_evalex=True) use_debugger=True, use_evalex=True)

+ 3
- 2
wnf.py View File

@@ -137,6 +137,7 @@ def setup_utilities(parser):
help="Set administrator password") help="Set administrator password")
parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site") parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site")
parser.add_argument("--serve", action="store_true", help="Run development server") parser.add_argument("--serve", action="store_true", help="Run development server")
parser.add_argument("--profile", action="store_true", help="enable profiling in development server")
parser.add_argument("--smtp", action="store_true", help="Run smtp debug server", parser.add_argument("--smtp", action="store_true", help="Run smtp debug server",
dest="smtp_debug_server") dest="smtp_debug_server")
parser.add_argument("--python", action="store_true", help="get python shell for a site") parser.add_argument("--python", action="store_true", help="get python shell for a site")
@@ -593,9 +594,9 @@ def smtp_debug_server():
os.execv(python, [python, '-m', "smtpd", "-n", "-c", "DebuggingServer", "localhost:25"]) os.execv(python, [python, '-m', "smtpd", "-n", "-c", "DebuggingServer", "localhost:25"])
@cmd @cmd
def serve(port=8000):
def serve(port=8000, profile=False):
import webnotes.app import webnotes.app
webnotes.app.serve(port=port)
webnotes.app.serve(port=port, profile=profile)


def replace_code(start, txt1, txt2, extn, search=None, force=False): def replace_code(start, txt1, txt2, extn, search=None, force=False):
"""replace all txt1 by txt2 in files with extension (extn)""" """replace all txt1 by txt2 in files with extension (extn)"""


Loading…
Cancel
Save