Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-debug-toolbar-mongo
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
OpenEdx
django-debug-toolbar-mongo
Commits
c92cff03
Commit
c92cff03
authored
May 25, 2011
by
Harry Marr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull out query, skip, limit. Detect cmds (e.g.count)
parent
2abd5c99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
24 deletions
+45
-24
debug_toolbar_mongo/panel.py
+39
-22
debug_toolbar_mongo/templates/mongo-panel.html
+6
-2
No files found.
debug_toolbar_mongo/panel.py
View file @
c92cff03
...
...
@@ -9,7 +9,7 @@ import pymongo.cursor
from
debug_toolbar.panels
import
DebugPanel
class
MongoOperation
Hook
(
object
):
class
MongoOperation
Tracker
(
object
):
"""Track operations sent to MongoDB via PyMongo.
"""
...
...
@@ -36,26 +36,43 @@ class MongoOperationHook(object):
# Inactive or getMore - move on
return
self
.
original_methods
[
'refresh'
](
cursor_self
)
query_details
=
{
'options'
:
privar
(
'query_options'
)(),
'collection_name'
:
privar
(
'collection'
)
.
full_name
,
'num_to_skip'
:
privar
(
'skip'
),
'num_to_return'
:
privar
(
'limit'
),
'query'
:
privar
(
'query_spec'
)(),
'field_selector'
:
privar
(
'fields'
),
}
# NOTE: See pymongo/cursor.py+557 [_refresh()] and
# pymongo/message.py for where information is stored
# Time the actual query
start_time
=
time
.
time
()
result
=
self
.
original_methods
[
'refresh'
](
cursor_self
)
total_time
=
(
time
.
time
()
-
start_time
)
*
1000
self
.
queries
.
append
({
'type'
:
'query'
,
'query'
:
query_details
[
'query'
]
.
to_dict
(),
'collection'
:
query_details
[
'collection_name'
],
query_son
=
privar
(
'query_spec'
)()
.
to_dict
()
query_data
=
{
'time'
:
total_time
,
})
'operation'
:
'query'
,
}
# Collection in format <db_name>.<collection_name>
collection_name
=
privar
(
'collection'
)
query_data
[
'collection'
]
=
collection_name
.
full_name
.
split
(
'.'
)[
1
]
if
query_data
[
'collection'
]
==
'$cmd'
:
query_data
[
'operation'
]
=
'command'
# Handle count as a special case
if
'count'
in
query_son
:
# Information is in a different format to a standar query
query_data
[
'collection'
]
=
query_son
[
'count'
]
query_data
[
'operation'
]
=
'count'
query_data
[
'skip'
]
=
query_son
.
get
(
'skip'
)
query_data
[
'limit'
]
=
query_son
.
get
(
'limit'
)
query_data
[
'query'
]
=
query_son
[
'query'
]
del
query_son
[
'count'
]
else
:
# Normal Query
query_data
[
'skip'
]
=
privar
(
'skip'
)
query_data
[
'limit'
]
=
privar
(
'limit'
)
query_data
[
'query'
]
=
query_son
[
'$query'
]
self
.
queries
.
append
(
query_data
)
return
result
...
...
@@ -82,22 +99,22 @@ class MongoDebugPanel(DebugPanel):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
self
.
__class__
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
op_
hook
=
MongoOperationHook
()
self
.
op_
hook
.
install
()
self
.
op_
tracker
=
MongoOperationTracker
()
self
.
op_
tracker
.
install
()
def
process_request
(
self
,
request
):
self
.
op_
hook
.
reset
()
self
.
op_
hook
.
start
()
self
.
op_
tracker
.
reset
()
self
.
op_
tracker
.
start
()
def
process_response
(
self
,
request
,
response
):
self
.
op_
hook
.
stop
()
self
.
op_
tracker
.
stop
()
def
nav_title
(
self
):
return
'MongoDB'
def
nav_subtitle
(
self
):
num_queries
=
len
(
self
.
op_
hook
.
queries
)
return
'{0}
querie
s executed'
.
format
(
num_queries
)
num_queries
=
len
(
self
.
op_
tracker
.
queries
)
return
'{0}
operation
s executed'
.
format
(
num_queries
)
def
title
(
self
):
return
'MongoDB Queries'
...
...
@@ -107,7 +124,7 @@ class MongoDebugPanel(DebugPanel):
def
content
(
self
):
context
=
self
.
context
.
copy
()
context
[
'queries'
]
=
self
.
op_
hook
.
queries
context
[
'queries'
]
=
self
.
op_
tracker
.
queries
return
render_to_string
(
'mongo-panel.html'
,
context
)
debug_toolbar_mongo/templates/mongo-panel.html
View file @
c92cff03
...
...
@@ -3,18 +3,22 @@
<thead>
<tr>
<th>
Time (ms)
</th>
<th>
Type
</th>
<th>
Operation
</th>
<th>
Collection
</th>
<th>
Query
</th>
<th>
Skip
</th>
<th>
Limit
</th>
</tr>
</thead>
<tbody>
{% for query in queries %}
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
<td>
{{ query.time|floatformat:"4" }}
</td>
<td>
{{ query.
type
|title }}
</td>
<td>
{{ query.
operation
|title }}
</td>
<td>
{{ query.collection }}
</td>
<td><code>
{{ query.query|pprint }}
</code></td>
<td>
{% if query.skip %}{{ query.skip }}{% endif %}
</td>
<td>
{% if query.limit %}{{ query.limit }}{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
...
...
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