Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
bd52b9e4
Commit
bd52b9e4
authored
Jan 15, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed perfstats middleware to log sql queries
parent
82cbb9a1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
35 deletions
+15
-35
perfstats/middleware.py
+15
-35
No files found.
perfstats/middleware.py
View file @
bd52b9e4
import
views
,
json
,
tempfile
import
hotshot
import
hotshot.stats
import
views
,
json
,
tempfile
,
time
from
django.conf
import
settings
from
django.db
import
connection
tmpfile
=
None
prof
=
None
isRunning
=
False
def
restart_profile
():
global
prof
,
tmpfile
,
isRunning
try
:
oldname
=
tmpfile
.
name
except
:
oldname
=
""
if
prof
!=
None
:
if
isRunning
:
prof
.
stop
()
prof
.
close
()
tmpfile
=
tempfile
.
NamedTemporaryFile
(
prefix
=
'prof'
,
delete
=
False
)
prof
=
hotshot
.
Profile
(
tmpfile
.
name
,
lineevents
=
1
)
isRunning
=
False
print
"Filename"
,
tmpfile
.
name
return
(
tmpfile
.
name
,
oldname
)
restart_profile
()
class
ProfileMiddleware
:
def
process_request
(
self
,
request
):
global
isRunning
if
not
isRunning
:
prof
.
start
()
isRunning
=
True
else
:
print
"Profiler was already running. Results may be unpredictable"
self
.
t
=
time
.
time
()
print
"Process request"
def
process_response
(
self
,
request
,
response
):
global
isRunning
if
isRunning
:
prof
.
stop
()
isRunning
=
False
totalTime
=
time
.
time
()
-
self
.
t
tmpfile
=
tempfile
.
NamedTemporaryFile
(
prefix
=
'sqlprof-t='
+
str
(
totalTime
)
+
"-"
,
delete
=
False
)
output
=
""
for
query
in
connection
.
queries
:
output
+=
"Time: "
+
str
(
query
[
'time'
])
+
"
\n
Query: "
+
query
[
'sql'
]
+
"
\n\n
"
tmpfile
.
write
(
output
)
print
"SQL Log file: "
,
tmpfile
.
name
tmpfile
.
close
()
print
"Process response"
return
response
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment