Profiling. Also, preliminary dummy code for tracking in capa_problem
This commit is contained in:
@@ -306,4 +306,9 @@ class LoncapaModule(XModule):
|
||||
|
||||
filename=settings.DATA_DIR+"problems/"+self.filename+".xml"
|
||||
self.lcp=LoncapaProblem(filename, self.item_id, self.lcp.get_state())
|
||||
|
||||
event_info = self.lcp.get_state()
|
||||
event_info.update({'filename':filename})
|
||||
#server_track(request, 'reset_problem', event_info)
|
||||
|
||||
return json.dumps(self.get_problem_html(encapsulate=False))
|
||||
|
||||
0
perfstats/__init__.py
Normal file
0
perfstats/__init__.py
Normal file
35
perfstats/middleware.py
Normal file
35
perfstats/middleware.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import views, json, tempfile
|
||||
import hotshot
|
||||
import hotshot.stats
|
||||
from django.conf import settings
|
||||
|
||||
tmpfile = None
|
||||
prof = None
|
||||
|
||||
def restart_profile():
|
||||
global prof, tmpfile
|
||||
try:
|
||||
oldname = tmpfile.name
|
||||
except:
|
||||
oldname = ""
|
||||
if prof != None:
|
||||
prof.close()
|
||||
tmpfile = tempfile.NamedTemporaryFile(prefix='prof',delete=False)
|
||||
prof = hotshot.Profile(tmpfile.name)
|
||||
print "Filename", tmpfile.name
|
||||
return (tmpfile.name, oldname)
|
||||
|
||||
restart_profile()
|
||||
|
||||
class ProfileMiddleware:
|
||||
def process_request (self, request):
|
||||
prof.start()
|
||||
print "Process request"
|
||||
|
||||
def process_response (self, request, response):
|
||||
try:
|
||||
prof.stop()
|
||||
except:
|
||||
print "Profiler not active. If you didn't just restart, this is an error"
|
||||
print "Process response"
|
||||
return response
|
||||
3
perfstats/models.py
Normal file
3
perfstats/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
16
perfstats/tests.py
Normal file
16
perfstats/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
7
perfstats/views.py
Normal file
7
perfstats/views.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# Create your views here.
|
||||
import middleware
|
||||
from django.http import HttpResponse
|
||||
|
||||
def end_profile(request):
|
||||
names = middleware.restart_profile()
|
||||
return HttpResponse(str(names))
|
||||
22
settings.py
22
settings.py
@@ -13,6 +13,8 @@ DEFAULT_FEEDBACK_EMAIL = 'feedback@mitx.mit.edu'
|
||||
WIKI_REQUIRE_LOGIN_EDIT = True
|
||||
WIKI_REQUIRE_LOGIN_VIEW = True
|
||||
|
||||
PROFILE = False
|
||||
|
||||
HTTPS = 'on'
|
||||
|
||||
DEBUG = True
|
||||
@@ -68,14 +70,14 @@ TEMPLATE_LOADERS = (
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'track.middleware.TrackMiddleware',
|
||||
'djangomako.middleware.MakoMiddleware',
|
||||
#'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'track.middleware.TrackMiddleware',
|
||||
'djangomako.middleware.MakoMiddleware',
|
||||
#'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'mitx.urls'
|
||||
@@ -96,6 +98,7 @@ INSTALLED_APPS = (
|
||||
'simplewiki',
|
||||
'track',
|
||||
'circuit',
|
||||
'perfstats',
|
||||
# Uncomment the next line to enable the admin:
|
||||
# 'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
@@ -134,6 +137,9 @@ MAXLOG = 500
|
||||
|
||||
execfile("../settings.py")
|
||||
|
||||
if PROFILE :
|
||||
MIDDLEWARE_CLASSES = ( 'perfstats.middleware.ProfileMiddleware',) + MIDDLEWARE_CLASSES
|
||||
|
||||
if 'TRACK_DIR' not in locals():
|
||||
TRACK_DIR = BASE_DIR+'/track_dir/'
|
||||
if 'ASKBOT_EXTRA_SKINS_DIR' not in locals():
|
||||
|
||||
4
urls.py
4
urls.py
@@ -2,6 +2,7 @@ from django.conf.urls.defaults import patterns, include, url
|
||||
import django.contrib.auth.views
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
import perfstats
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
# from django.contrib import admin
|
||||
@@ -30,6 +31,9 @@ urlpatterns = ('',
|
||||
url(r'^courseware/$', 'courseware.views.index'),
|
||||
)
|
||||
|
||||
if settings.PROFILE:
|
||||
urlpatterns=urlpatterns + (url(r'^reprofile$','perfstats.views.end_profile'),)
|
||||
|
||||
if settings.COURSEWARE_ENABLED:
|
||||
urlpatterns=urlpatterns + (url(r'^wiki/', include('simplewiki.urls')),
|
||||
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index'),
|
||||
|
||||
Reference in New Issue
Block a user