From 85bd265bd5fe9dda44c67c2b2e618a79c2fb8fdc Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Fri, 23 Jan 2009 10:59:59 -0800 Subject: Add preliminary support for stacktraces to see where SQL queries are coming from. I'm wanting to test this a bit more before I merge it in fully. Feedback welcome.--- debug_toolbar/media/toolbar.js | 7 ++++++ debug_toolbar/media/toolbar.min.js | 2 +- debug_toolbar/panels/sql.py | 29 +++++++++++++++++++++- .../templates/debug_toolbar/panels/sql.html | 22 ++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js index b6baa2c..bff9b21 100644 --- a/debug_toolbar/media/toolbar.js +++ b/debug_toolbar/media/toolbar.js @@ -35,12 +35,19 @@ jQuery(function($) { }); $('#djDebugTemplatePanel a.djTemplateShowContext').click(function() { $.djDebug.toggle_content($(this).parent().next()); + return false; + }); + $('#djDebugSQLPanel a.djSQLShowStacktrace').click(function() { + $.djDebug.toggle_content($(this).parent().next()); + return false; }); $('#djHideToolBarButton').click(function() { $.djDebug.hide_toolbar(true); + return false; }); $('#djShowToolBarButton').click(function() { $.djDebug.show_toolbar(); + return false; }); if ($.cookie(COOKIE_NAME)) { $.djDebug.hide_toolbar(false); diff --git a/debug_toolbar/media/toolbar.min.js b/debug_toolbar/media/toolbar.min.js index 43bfead..4c8364e 100644 --- a/debug_toolbar/media/toolbar.min.js +++ b/debug_toolbar/media/toolbar.min.js @@ -1 +1 @@ -var _$=window.$;jQuery.noConflict();jQuery(function(a){var b="dj_debug_panel";a.djDebug=function(d,c){a.djDebug.init()};a.extend(a.djDebug,{init:function(){var c=null;a("#djDebugPanelList li a").click(function(){c=a("#djDebug #"+this.className);if(c.is(":visible")){a(document).trigger("close.djDebug")}else{a(".panelContent").hide();c.show();a.djDebug.open()}return false});a("#djDebug a.close").click(function(){a(document).trigger("close.djDebug");return false});a("#djDebug a.remoteCall").click(function(){a("#djDebugWindow").load(this.href,{},function(){a("#djDebugWindow a.back").click(function(){a(this).parent().hide();return false})});a("#djDebugWindow").show();return false});a("#djDebugTemplatePanel a.djTemplateShowContext").click(function(){a.djDebug.toggle_content(a(this).parent().next())});a("#djHideToolBarButton").click(function(){a.djDebug.hide_toolbar(true)});a("#djShowToolBarButton").click(function(){a.djDebug.show_toolbar()});if(a.cookie(b)){a.djDebug.hide_toolbar(false)}else{a("#djDebugToolbar").show()}},open:function(){a(document).bind("keydown.djDebug",function(c){if(c.keyCode==27){a.djDebug.close()}})},toggle_content:function(c){if(c.is(":visible")){c.hide()}else{c.show()}},close:function(){a(document).trigger("close.djDebug");return false},hide_toolbar:function(c){a("#djDebugToolbar").hide("fast");a("#djDebugToolbarHandle").show();if(c){a.cookie(b,"hide",{path:"/",expires:10})}},show_toolbar:function(){a("#djDebugToolbarHandle").hide();a("#djDebugToolbar").show("fast");a.cookie(b,null,{path:"/",expires:-1})}});a(document).bind("close.djDebug",function(){a(document).unbind("keydown.djDebug");a(".panelContent").hide()})});jQuery(function(){jQuery.djDebug()});$=_$;jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h Time (ms) Action + Stacktrace Query @@ -20,6 +21,27 @@ {% endif %} {% endif %} + + {% if query.stacktrace %} +
Toggle Stacktrace
+ + {% endif %} + {{ query.sql|safe }} {% endfor %} -- cgit v1.2.3 From 1a52939905b7a43a9cf83cde6216a98cc5cbc595 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Fri, 23 Jan 2009 11:45:14 -0800 Subject: Tuple unpacking of stacktrace variables for niceness. --- debug_toolbar/templates/debug_toolbar/panels/sql.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html index 1896e3c..d08f93e 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/sql.html +++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html @@ -31,11 +31,11 @@ Method File - {% for s in query.stacktrace %} + {% for file, line, method in query.stacktrace %} - {{ s.1 }} -
{{ s.2|escape }}

-									
{{ s.0|escape }}
+ {{ line }} +
{{ method|escape }}

+									
{{ file|escape }}
{% endfor %} -- cgit v1.2.3 From 4f680980f9987063c663e46ab190c7aeba552ac7 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Sat, 14 Mar 2009 00:15:46 +0700 Subject: fixed bug when the string matches more than once in the html Signed-off-by: Rob Hudson --- debug_toolbar/middleware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index c3cf5f9..9c46079 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -19,7 +19,7 @@ def replace_insensitive(string, target, replacement): Code borrowed from: http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html """ no_case = string.lower() - index = no_case.find(target.lower()) + index = no_case.rfind(target.lower()) if index >= 0: return string[:index] + replacement + string[index + len(target):] else: # no results so return the original string -- cgit v1.2.3 From 3faace8b4fe7fbf0af7998340ce684d462ab0a9c Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Sat, 21 Mar 2009 10:17:54 -0700 Subject: Reverting commit 2a839fd, "Restrict the debug toolbar to a single row of panels." There were some issues with this commit that need to be resolved before it's added back in.--- debug_toolbar/media/toolbar.css | 16 ---------------- debug_toolbar/media/toolbar.js | 34 ---------------------------------- debug_toolbar/media/toolbar.min.css | 2 +- debug_toolbar/media/toolbar.min.js | 2 +- 4 files changed, 2 insertions(+), 52 deletions(-) diff --git a/debug_toolbar/media/toolbar.css b/debug_toolbar/media/toolbar.css index c0a6e1a..9ef6dc3 100644 --- a/debug_toolbar/media/toolbar.css +++ b/debug_toolbar/media/toolbar.css @@ -79,22 +79,6 @@ border-right: 1px solid #487858; } -#djDebugMore ul { - float: right; - background: #2a5738; - display: none; -} - -#djDebugMore:hover ul { - display: block; -} - -#djDebugMore li { - display: inherit; - position: inherit; - line-height: inherit; -} - #djDebugToolbar #djDebugButton { color: #92ef3f; } diff --git a/debug_toolbar/media/toolbar.js b/debug_toolbar/media/toolbar.js index 9cbda92..5baed78 100644 --- a/debug_toolbar/media/toolbar.js +++ b/debug_toolbar/media/toolbar.js @@ -47,8 +47,6 @@ jQuery(function() { } else { $j('#djDebugToolbar').show(); } - $j(window).load($j.djDebug.format_panels); - $j(window).resize($j.djDebug.format_panels); }, open: function() { $j(document).bind('keydown.djDebug', function(e) { @@ -85,37 +83,6 @@ jQuery(function() { path: '/', expires: -1 }); - }, - /* Make sure that panel layout doesn't overflow the screen - * width. Any panel that would otherwise wrap to the next line - * are pushed into a "more..." vertical display in the final - * panel position. */ - format_panels: function () { - // If we've already done some overflow-avoidance, undo the - // effect before recomputing (needed, for example, after a - // window resize). - $j("#djDebugMore > ul > li").appendTo("#djDebugPanelList"); - $j("#djDebugMore").remove(); - - // Check for wrapping by examing the position of the last - // element. - var row_top = $j("#djDebugPanelList > li").position().top; - var final_pos = $j("#djDebugPanelList > li:last").position(); - - if (final_pos.top == row_top && final_pos.left != 0) { - return; - } - - function overflow_check(idx) { - pos = $j(this).position(); - return pos.top > row_top || (idx > 1 && pos.left == 0); - }; - - var more = $j("
  • More...
    • "); - more.prependTo("#djDebugPanelList"); - overflows = $j("#djDebugPanelList > li").filter(overflow_check); - more.appendTo("#djDebugPanelList"); - $j("#djDebugMore > ul").append(overflows); } }); $j(document).bind('close.djDebug', function() { @@ -126,6 +93,5 @@ jQuery(function() { jQuery(function() { jQuery.djDebug(); }); - $ = _$; diff --git a/debug_toolbar/media/toolbar.min.css b/debug_toolbar/media/toolbar.min.css index be5ea7d..c172fbd 100644 --- a/debug_toolbar/media/toolbar.min.css +++ b/debug_toolbar/media/toolbar.min.css @@ -1 +1 @@ -#djDebug *{color:#000;float:none;margin:0;padding:0;position:static;text-align:left;}#djDebug a{color:#f7c757;}#djDebug a:hover{color:#aaa;}#djDebugToolbar{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;}#djDebugToolbarHandle{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;width:16px;}#djDebugToolbarHandle ul li{padding:3px 0 0 3px;}#djDebugToolbarHandle ul li a{font-size:16px;font-weight:bold;}#djDebugToolbar ul{margin:0;padding:0;list-style:none;}#djDebugToolbar li{border-left:1px solid #487858;color:#fff;display:inline;font-size:11px;font-weight:bold;float:none;height:20px;margin:0;padding:0;line-height:30px;padding:8px 9px 9px;position:relative;width:auto;}#djDebugToolbar li:hover{background:#487858;}#djDebugToolbar li:hover a{color:#fff;}#djDebugToolbar li:last-child{border-right:1px solid #487858;}#djDebugMore ul{float:right;background:#2a5738;display:none;}#djDebugMore:hover ul{display:block;}#djDebugMore li{display:inherit;position:inherit;line-height:inherit;}#djDebugToolbar #djDebugButton{color:#92ef3f;}#djDebug pre{background-color:#fff;}#djDebug tr.djDebugOdd pre{background-color:#eee;}#djDebug .panelContent{background:#2a5738;border-bottom:2px solid #234f32;border-top:2px solid #487858;display:none;position:absolute;margin:0;padding:10px;top:32px;width:auto;left:0;right:0;bottom:5px;color:black;z-index:1000000;overflow:auto;}#djDebug .panelContent p a,#djDebug .panelContent dl a{color:#40684c;}#djDebug .panelContent p a:hover,#djDebug .panelContent dl a:hover{color:#92EF3F;}#djDebug .panelContent h3{border-bottom:1px solid #40684c;color:#92ef3f;padding:0 0 5px;}#djDebug .panelContent p{padding:0 5px;}#djDebug .panelContent p,#djDebug .panelContent table,#djDebug .panelContent ol,#djDebug .panelContent ul,#djDebug .panelContent dl{margin:5px 0 15px;background-color:#fff;}#djDebug .panelContent table{width:100%;clear:both;}#djDebug .panelContent table a{color:#40684C;}#djDebug .panelContent table th{background-color:#9dcc49;font-weight:bold;color:#000;font-size:11px;padding:3px 7px 3px;text-align:left;cursor:pointer;border-right:1px solid #b9d977;}#djDebug .panelContent table td{padding:5px 10px;font-size:11px;background:#fff;color:#000;vertical-align:top;}#djDebug .panelContent table tr.djDebugOdd td{background:#eee;}#djDebug .panelContent .close{float:right;font-weight:bold;}#djDebug .panelContent dt,#djDebug .panelContent dd{display:block;}#djDebug .panelContent dd{margin-left:10px;}#djDebug .highlight{color:#000;}#djDebug .highlight .err{color:#000;}#djDebug .highlight .g{color:#000;}#djDebug .highlight .k{color:#40684C;font-weight:bold;}#djDebug .highlight .o{color:#000;}#djDebug .highlight .n{color:#000;}#djDebug .highlight .mi{color:#40684C;font-weight:bold;}#djDebug .highlight .l{color:#000;}#djDebug .highlight .x{color:#000;}#djDebug .highlight .p{color:#000;}#djDebug .highlight .m{color:#40684C;font-weight:bold;}#djDebug .highlight .s{color:#0086d2;}#djDebug .highlight .w{color:#888;}#djDebug .highlight .il{color:#40684C;font-weight:bold;}#djDebug .highlight .na{color:#7D9029;}#djDebug .highlight .nt{color:#008000;font-weight:bold;}#djDebug .highlight .nv{color:#19177C;}#djDebug .highlight .s2{color:#BA2121;}#djDebug .highlight .cp{color:#BC7A00;} \ No newline at end of file +#djDebug *{color:#000;float:none;margin:0;padding:0;position:static;text-align:left;}#djDebug a{color:#f7c757;}#djDebug a:hover{color:#aaa;}#djDebugToolbar{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;}#djDebugToolbarHandle{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;width:16px;}#djDebugToolbarHandle ul li{padding:3px 0 0 3px;}#djDebugToolbarHandle ul li a{font-size:16px;font-weight:bold;}#djDebugToolbar ul{margin:0;padding:0;list-style:none;}#djDebugToolbar li{border-left:1px solid #487858;color:#fff;display:inline;font-size:11px;font-weight:bold;float:none;height:20px;margin:0;padding:0;line-height:30px;padding:8px 9px 9px;position:relative;width:auto;}#djDebugToolbar li:hover{background:#487858;}#djDebugToolbar li:hover a{color:#fff;}#djDebugToolbar li:last-child{border-right:1px solid #487858;}#djDebugToolbar #djDebugButton{color:#92ef3f;}#djDebug pre{background-color:#fff;}#djDebug tr.djDebugOdd pre{background-color:#eee;}#djDebug .panelContent{background:#2a5738;border-bottom:2px solid #234f32;border-top:2px solid #487858;display:none;position:absolute;margin:0;padding:10px;top:32px;width:auto;left:0;right:0;bottom:5px;color:black;z-index:1000000;overflow:auto;}#djDebug .panelContent p a,#djDebug .panelContent dl a{color:#40684c;}#djDebug .panelContent p a:hover,#djDebug .panelContent dl a:hover{color:#92EF3F;}#djDebug .panelContent h3{border-bottom:1px solid #40684c;color:#92ef3f;padding:0 0 5px;}#djDebug .panelContent p{padding:0 5px;}#djDebug .panelContent p,#djDebug .panelContent table,#djDebug .panelContent ol,#djDebug .panelContent ul,#djDebug .panelContent dl{margin:5px 0 15px;background-color:#fff;}#djDebug .panelContent table{width:100%;clear:both;}#djDebug .panelContent table a{color:#40684C;}#djDebug .panelContent table th{background-color:#9dcc49;font-weight:bold;color:#000;font-size:11px;padding:3px 7px 3px;text-align:left;cursor:pointer;border-right:1px solid #b9d977;}#djDebug .panelContent table td{padding:5px 10px;font-size:11px;background:#fff;color:#000;vertical-align:top;}#djDebug .panelContent table tr.djDebugOdd td{background:#eee;}#djDebug .panelContent .close{float:right;font-weight:bold;}#djDebug .panelContent dt,#djDebug .panelContent dd{display:block;}#djDebug .panelContent dd{margin-left:10px;}#djDebug .highlight{color:#000;}#djDebug .highlight .err{color:#000;}#djDebug .highlight .g{color:#000;}#djDebug .highlight .k{color:#40684C;font-weight:bold;}#djDebug .highlight .o{color:#000;}#djDebug .highlight .n{color:#000;}#djDebug .highlight .mi{color:#40684C;font-weight:bold;}#djDebug .highlight .l{color:#000;}#djDebug .highlight .x{color:#000;}#djDebug .highlight .p{color:#000;}#djDebug .highlight .m{color:#40684C;font-weight:bold;}#djDebug .highlight .s{color:#0086d2;}#djDebug .highlight .w{color:#888;}#djDebug .highlight .il{color:#40684C;font-weight:bold;}#djDebug .highlight .na{color:#7D9029;}#djDebug .highlight .nt{color:#008000;font-weight:bold;}#djDebug .highlight .nv{color:#19177C;}#djDebug .highlight .s2{color:#BA2121;}#djDebug .highlight .cp{color:#BC7A00;} \ No newline at end of file diff --git a/debug_toolbar/media/toolbar.min.js b/debug_toolbar/media/toolbar.min.js index fd41bfb..587ac65 100644 --- a/debug_toolbar/media/toolbar.min.js +++ b/debug_toolbar/media/toolbar.min.js @@ -1 +1 @@ -var _$=window.$;$j=jQuery.noConflict();jQuery(function(){var a="dj_debug_panel";$j.djDebug=function(c,b){$j.djDebug.init()};$j.extend($j.djDebug,{init:function(){var b=null;$j("#djDebugPanelList li a").click(function(){b=$j("#djDebug #"+this.className);if(b.is(":visible")){$j(document).trigger("close.djDebug")}else{$j(".panelContent").hide();b.show();$j.djDebug.open()}return false});$j("#djDebug a.close").click(function(){$j(document).trigger("close.djDebug");return false});$j("#djDebug a.remoteCall").click(function(){$j("#djDebugWindow").load(this.href,{},function(){$j("#djDebugWindow a.back").click(function(){$j(this).parent().hide();return false})});$j("#djDebugWindow").show();return false});$j("#djDebugTemplatePanel a.djTemplateShowContext").click(function(){$j.djDebug.toggle_content($j(this).parent().next())});$j("#djHideToolBarButton").click(function(){$j.djDebug.hide_toolbar(true)});$j("#djShowToolBarButton").click(function(){$j.djDebug.show_toolbar()});if($j.cookie(a)){$j.djDebug.hide_toolbar(false)}else{$j("#djDebugToolbar").show()}$j(window).load($j.djDebug.format_panels);$j(window).resize($j.djDebug.format_panels)},open:function(){$j(document).bind("keydown.djDebug",function(b){if(b.keyCode==27){$j.djDebug.close()}})},toggle_content:function(b){if(b.is(":visible")){b.hide()}else{b.show()}},close:function(){$j(document).trigger("close.djDebug");return false},hide_toolbar:function(b){$j("#djDebugToolbar").hide("fast");$j("#djDebugToolbarHandle").show();if(b){$j.cookie(a,"hide",{path:"/",expires:10})}},show_toolbar:function(){$j("#djDebugToolbarHandle").hide();$j("#djDebugToolbar").show("fast");$j.cookie(a,null,{path:"/",expires:-1})},format_panels:function(){$j("#djDebugMore > ul > li").appendTo("#djDebugPanelList");$j("#djDebugMore").remove();var b=$j("#djDebugPanelList > li").position().top;var d=$j("#djDebugPanelList > li:last").position();if(d.top==b&&d.left!=0){return}function e(f){pos=$j(this).position();return pos.top>b||(f>1&&pos.left==0)}var c=$j("
    • More...
      • ");c.prependTo("#djDebugPanelList");overflows=$j("#djDebugPanelList > li").filter(e);c.appendTo("#djDebugPanelList");$j("#djDebugMore > ul").append(overflows)}});$j(document).bind("close.djDebug",function(){$j(document).unbind("keydown.djDebug");$j(".panelContent").hide()})});jQuery(function(){jQuery.djDebug()});$=_$;jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h