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
9f5df834
Commit
9f5df834
authored
Mar 01, 2013
by
Colin Howe
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from viotti/master
Improvements on the MongoDB panel
parents
e3058933
9799edf3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
48 deletions
+92
-48
debug_toolbar_mongo/operation_tracker.py
+3
-3
debug_toolbar_mongo/panel.py
+37
-5
debug_toolbar_mongo/templates/mongo-panel.html
+52
-40
No files found.
debug_toolbar_mongo/operation_tracker.py
View file @
9f5df834
...
...
@@ -145,7 +145,7 @@ def _cursor_refresh(cursor_self):
__traceback_hide__
=
True
query_data
=
{
'time'
:
total_time
,
'operation'
:
'
query
'
,
'operation'
:
'
find
'
,
'stack_trace'
:
_get_stacktrace
(),
}
...
...
@@ -161,7 +161,7 @@ def _cursor_refresh(cursor_self):
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
[
'limit'
]
=
abs
(
query_son
.
get
(
'limit'
,
0
)
)
query_data
[
'query'
]
=
query_son
[
'query'
]
elif
'aggregate'
in
query_son
:
query_data
[
'collection'
]
=
query_son
[
'aggregate'
]
...
...
@@ -172,7 +172,7 @@ def _cursor_refresh(cursor_self):
else
:
# Normal Query
query_data
[
'skip'
]
=
privar
(
'skip'
)
query_data
[
'limit'
]
=
privar
(
'limit'
)
query_data
[
'limit'
]
=
abs
(
privar
(
'limit'
)
or
0
)
query_data
[
'query'
]
=
query_son
.
get
(
'$query'
)
or
query_son
query_data
[
'ordering'
]
=
_get_ordering
(
query_son
)
...
...
debug_toolbar_mongo/panel.py
View file @
9f5df834
from
django.template
import
Template
,
Context
from
django.template.loader
import
render_to_string
from
django.utils.safestring
import
mark_safe
from
debug_toolbar.panels
import
DebugPanel
import
operation_tracker
_NAV_SUBTITLE_TPL
=
u'''
{
%
for o, n, t in operations
%
}
{{ n }} {{ o }}{{ n|pluralize }} in {{ t }}ms<br/>
{
%
if forloop.last and forloop.counter0
%
}
{{ count }} operation{{ count|pluralize }} in {{ time }}ms
{
%
endif
%
}
{
%
endfor
%
}
'''
class
MongoDebugPanel
(
DebugPanel
):
"""Panel that shows information about MongoDB operations.
...
...
@@ -22,11 +33,32 @@ class MongoDebugPanel(DebugPanel):
return
'MongoDB'
def
nav_subtitle
(
self
):
num_queries
=
len
(
operation_tracker
.
queries
)
attrs
=
[
'queries'
,
'inserts'
,
'updates'
,
'removes'
]
total_time
=
sum
(
sum
(
o
[
'time'
]
for
o
in
getattr
(
operation_tracker
,
a
))
for
a
in
attrs
)
return
'{0} operations in {1:.2f}ms'
.
format
(
num_queries
,
total_time
)
fun
=
lambda
x
,
y
:
(
x
,
len
(
y
),
'
%.2
f'
%
sum
(
z
[
'time'
]
for
z
in
y
))
ctx
=
{
'operations'
:
[],
'count'
:
0
,
'time'
:
0
}
if
operation_tracker
.
queries
:
ctx
[
'operations'
]
.
append
(
fun
(
'read'
,
operation_tracker
.
queries
))
ctx
[
'count'
]
+=
len
(
operation_tracker
.
queries
)
ctx
[
'time'
]
+=
sum
(
x
[
'time'
]
for
x
in
operation_tracker
.
queries
)
if
operation_tracker
.
inserts
:
ctx
[
'operations'
]
.
append
(
fun
(
'insert'
,
operation_tracker
.
inserts
))
ctx
[
'count'
]
+=
len
(
operation_tracker
.
inserts
)
ctx
[
'time'
]
+=
sum
(
x
[
'time'
]
for
x
in
operation_tracker
.
inserts
)
if
operation_tracker
.
updates
:
ctx
[
'operations'
]
.
append
(
fun
(
'update'
,
operation_tracker
.
updates
))
ctx
[
'count'
]
+=
len
(
operation_tracker
.
updates
)
ctx
[
'time'
]
+=
sum
(
x
[
'time'
]
for
x
in
operation_tracker
.
updates
)
if
operation_tracker
.
removes
:
ctx
[
'operations'
]
.
append
(
fun
(
'remove'
,
operation_tracker
.
removes
))
ctx
[
'count'
]
+=
len
(
operation_tracker
.
removes
)
ctx
[
'time'
]
+=
sum
(
x
[
'time'
]
for
x
in
operation_tracker
.
removes
)
ctx
[
'time'
]
=
'
%.2
f'
%
ctx
[
'time'
]
return
mark_safe
(
Template
(
_NAV_SUBTITLE_TPL
)
.
render
(
Context
(
ctx
)))
def
title
(
self
):
return
'MongoDB Operations'
...
...
debug_toolbar_mongo/templates/mongo-panel.html
View file @
9f5df834
{% load mongo_debug_tags %}
<style
type=
"text/css"
>
#djDebug
.panelContent
tbody
th
{
width
:
auto
;
}
#djDebug
.panelContent
table
{
display
:
table
;
}
#djDebug
tr
.row1
{
background-color
:
#F5F5F5
;
}
#djDebug
#djDebugRequestVarsPanel
table
:first-of-type
tbody
tr
:nth-child
(
odd
)
{
background-color
:
#F5F5F5
;
}
pre
.mongo-highlight
,
pre
.mongo-highlight
span
{
font-family
:
'Consolas'
,
'Deja Vu Sans Mono'
,
'Bitstream Vera Sans Mono'
,
'Monaco'
,
'Courier New'
,
monospace
!important
;
font-size
:
1.05em
!important
;
...
...
@@ -19,7 +31,7 @@ table.mongo-op-table tbody {
}
</style>
<h4>
Querie
s
</h4>
<h4>
Read
s
</h4>
{% if queries %}
<table
class=
"mongo-op-table"
>
<thead>
...
...
@@ -27,7 +39,7 @@ table.mongo-op-table tbody {
<th>
Time (ms)
</th>
<th>
Operation
</th>
<th>
Collection
</th>
<th>
Query
</th>
<th
style=
"width: 100%"
>
Query
</th>
<th>
Ordering
</th>
<th>
Skip
</th>
<th>
Limit
</th>
...
...
@@ -42,12 +54,12 @@ table.mongo-op-table tbody {
<td>
{{ query.collection }}
</td>
<td>
{% if query.query %}
<pre
class=
"mongo-highlight"
>
{{ query.query|format_dict|highlight:"javascript"|safe }}
</pre>
{% endif %}
<pre
class=
"mongo-highlight"
>
{{ query.query|format_dict|highlight:"javascript"|safe }}
</pre>
{% endif %}
</td>
<td>
<pre
class=
"mongo-highlight"
>
{% if query.ordering %}{{ query.ordering }}{% endif %}
</pre>
</td>
<td>
{
% if query.skip %}{{ query.skip }}{% endif %
}
</td>
<td>
{
% if query.limit %}{{ query.limit }}{% endif %
}
</td>
<td>
{% if query.ordering %}
<pre
class=
"mongo-highlight"
>
{{ query.ordering }}
</pre>
{% endif %}
</td>
<td>
{
{ query.skip|default:"" }
}
</td>
<td>
{
{ query.limit|default:"" }
}
</td>
<td><a
href=
"javascript:void(0);"
class=
"mongo-toggle-trace"
data-row=
"queries-{{ forloop.counter }}"
>
Toggle
</a></td>
</tr>
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
...
...
@@ -87,7 +99,7 @@ table.mongo-op-table tbody {
<thead>
<tr>
<th>
Time (ms)
</th>
<th>
Document
</th>
<th
style=
"width: 100%"
>
Document
</th>
<th>
Safe
</th>
<th>
Stack Trace
</th>
</tr>
...
...
@@ -133,30 +145,38 @@ table.mongo-op-table tbody {
<p>
No inserts recorded
</p>
{% endif %}
<h4>
Remov
es
</h4>
{% if
remov
es %}
<h4>
Updat
es
</h4>
{% if
updat
es %}
<table
class=
"mongo-op-table"
>
<thead>
<tr>
<th>
Time (ms)
</th>
<th>
Query / Id
</th>
<th>
Query
</th>
<th
style=
"width: 100%"
>
Update
</th>
<th>
Safe
</th>
<th>
Multi
</th>
<th>
Upsert
</th>
<th>
Stack Trace
</th>
</tr>
</thead>
<tbody>
{% for
remove in remov
es %}
{% for
update in updat
es %}
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
<td>
{{
remov
e.time|floatformat:"4" }}
</td>
<td>
{{
updat
e.time|floatformat:"4" }}
</td>
<td>
<pre
class=
"mongo-highlight"
>
{{
remove.spec_or_id
|format_dict:120|highlight:"javascript"|safe }}
</pre>
<pre
class=
"mongo-highlight"
>
{{
update.spec
|format_dict:120|highlight:"javascript"|safe }}
</pre>
</td>
<td>
{{ remove.safe }}
</td>
<td><a
href=
"javascript:void(0);"
class=
"mongo-toggle-trace"
data-row=
"removes-{{ forloop.counter }}"
>
Toggle
</a></td>
<td>
<pre
class=
"mongo-highlight"
>
{{ update.document|format_dict:120|highlight:"javascript"|safe }}
</pre>
</td>
<td>
{{ update.safe }}
</td>
<td>
{{ update.multi }}
</td>
<td>
{{ update.upsert }}
</td>
<td><a
href=
"javascript:void(0);"
class=
"mongo-toggle-trace"
data-row=
"updates-{{ forloop.counter }}"
>
Toggle
</a></td>
</tr>
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
<td
colspan=
"
4
"
>
<table
class=
"mongo-stack-trace "
id=
"mongo-stack-trace-
remov
es-{{ forloop.counter }}"
>
<td
colspan=
"
7
"
>
<table
class=
"mongo-stack-trace "
id=
"mongo-stack-trace-
updat
es-{{ forloop.counter }}"
>
<thead>
<tr>
<th>
Line
</th>
...
...
@@ -166,7 +186,7 @@ table.mongo-op-table tbody {
</tr>
</thead>
<tbody>
{% for line in
remov
e.stack_trace %}
{% for line in
updat
e.stack_trace %}
<tr>
<td
class=
"lineno"
>
{{ line.1 }}
</td>
<td
class=
"file"
>
{{ line.0|embolden_file }}
</td>
...
...
@@ -182,41 +202,33 @@ table.mongo-op-table tbody {
</tbody>
</table>
{% else %}
<p>
No
remov
es recorded
</p>
<p>
No
updat
es recorded
</p>
{% endif %}
<h4>
Updat
es
</h4>
{% if
updat
es %}
<h4>
Remov
es
</h4>
{% if
remov
es %}
<table
class=
"mongo-op-table"
>
<thead>
<tr>
<th>
Time (ms)
</th>
<th>
Query
</th>
<th>
Update
</th>
<th
style=
"width: 100%"
>
Query / Id
</th>
<th>
Safe
</th>
<th>
Multi
</th>
<th>
Upsert
</th>
<th>
Stack Trace
</th>
</tr>
</thead>
<tbody>
{% for
update in updat
es %}
{% for
remove in remov
es %}
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
<td>
{{ update.time|floatformat:"4" }}
</td>
<td>
<pre
class=
"mongo-highlight"
>
{{ update.spec|format_dict:120|highlight:"javascript"|safe }}
</pre>
</td>
<td>
{{ remove.time|floatformat:"4" }}
</td>
<td>
<pre
class=
"mongo-highlight"
>
{{
update.document
|format_dict:120|highlight:"javascript"|safe }}
</pre>
<pre
class=
"mongo-highlight"
>
{{
remove.spec_or_id
|format_dict:120|highlight:"javascript"|safe }}
</pre>
</td>
<td>
{{ update.safe }}
</td>
<td>
{{ update.multi }}
</td>
<td>
{{ update.upsert }}
</td>
<td><a
href=
"javascript:void(0);"
class=
"mongo-toggle-trace"
data-row=
"updates-{{ forloop.counter }}"
>
Toggle
</a></td>
<td>
{{ remove.safe }}
</td>
<td><a
href=
"javascript:void(0);"
class=
"mongo-toggle-trace"
data-row=
"removes-{{ forloop.counter }}"
>
Toggle
</a></td>
</tr>
<tr
class=
"{% cycle 'djDebugOdd' 'djDebugEven' %}"
>
<td
colspan=
"
7
"
>
<table
class=
"mongo-stack-trace "
id=
"mongo-stack-trace-
updat
es-{{ forloop.counter }}"
>
<td
colspan=
"
4
"
>
<table
class=
"mongo-stack-trace "
id=
"mongo-stack-trace-
remov
es-{{ forloop.counter }}"
>
<thead>
<tr>
<th>
Line
</th>
...
...
@@ -226,7 +238,7 @@ table.mongo-op-table tbody {
</tr>
</thead>
<tbody>
{% for line in
updat
e.stack_trace %}
{% for line in
remov
e.stack_trace %}
<tr>
<td
class=
"lineno"
>
{{ line.1 }}
</td>
<td
class=
"file"
>
{{ line.0|embolden_file }}
</td>
...
...
@@ -242,7 +254,7 @@ table.mongo-op-table tbody {
</tbody>
</table>
{% else %}
<p>
No
updat
es recorded
</p>
<p>
No
remov
es recorded
</p>
{% endif %}
<script>
...
...
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