From a934369064036e9093fb8baa22f33159e6167cbf Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Fri, 29 Dec 2023 09:51:30 +0900 Subject: [PATCH 1/6] Page name includes query string --- lib/mini_profiler/timer_struct/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mini_profiler/timer_struct/page.rb b/lib/mini_profiler/timer_struct/page.rb index fecb0f46..94769eb4 100644 --- a/lib/mini_profiler/timer_struct/page.rb +++ b/lib/mini_profiler/timer_struct/page.rb @@ -59,7 +59,7 @@ def symbolize_array(array) def initialize(env) timer_id = MiniProfiler.generate_id - page_name = env['PATH_INFO'] + page_name = env['QUERY_STRING'] != "" ? env['PATH_INFO'] + "?" + env['QUERY_STRING'] : env['PATH_INFO'] started_at = (Time.now.to_f * 1000).to_i started = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i machine_name = env['SERVER_NAME'] From a41679ef3d987f2766c4a93e04e03a15d9906e66 Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Fri, 29 Dec 2023 09:52:36 +0900 Subject: [PATCH 2/6] Badge: align columns, display page name --- lib/html/includes.css | 20 +++++++++++++++++-- lib/html/includes.scss | 32 +++++++++++++++++++++++++++++- lib/html/includes.tmpl | 11 ++++++++-- lib/html/vendor.js | 2 +- lib/mini_profiler/asset_version.rb | 2 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/lib/html/includes.css b/lib/html/includes.css index e34bc4c2..d875257d 100644 --- a/lib/html/includes.css +++ b/lib/html/includes.css @@ -105,7 +105,8 @@ .profiler-result .profiler-unit { font-family: Consolas, monospace, serif; } .profiler-result .profiler-number { - color: #111; } + color: #111; + display: inline-block; } .profiler-result .profiler-info { text-align: right; } .profiler-result .profiler-info .profiler-name { @@ -235,6 +236,19 @@ .profiler-results { z-index: 2147483643; position: fixed; } + .profiler-results.profiler-left .profiler-button { + text-align: left; } + .profiler-results.profiler-right .profiler-button { + text-align: right; } + .profiler-results .profiler-button > .profiler-duration-milliseconds { + min-width: 70px; } + .profiler-results .profiler-button > .profiler-sql-count { + min-width: 55px; } + .profiler-results .profiler-button > .profiler-name { + min-width: 190px; + margin-left: 3px; } + .profiler-results .profiler-button > .profiler-number { + text-align: right; } .profiler-results.profiler-top { top: 0px; } .profiler-results.profiler-top.profiler-left { @@ -285,8 +299,10 @@ background-color: maroon; } .profiler-results .profiler-button.profiler-button-active .profiler-number, .profiler-results .profiler-button.profiler-button-active .profiler-nuclear, + .profiler-results .profiler-button.profiler-button-active .profiler-name, .profiler-results .profiler-controls.profiler-button-active .profiler-number, - .profiler-results .profiler-controls.profiler-button-active .profiler-nuclear { + .profiler-results .profiler-controls.profiler-button-active .profiler-nuclear, + .profiler-results .profiler-controls.profiler-button-active .profiler-name { color: #fff; font-weight: bold; } .profiler-results .profiler-button.profiler-button-active .profiler-unit, diff --git a/lib/html/includes.scss b/lib/html/includes.scss index 477bc717..6557eec6 100644 --- a/lib/html/includes.scss +++ b/lib/html/includes.scss @@ -103,6 +103,7 @@ $zindex: 2147483640; // near 32bit max 2147483647 .profiler-number { color: $numberColor; + display: inline-block; } .profiler-info { @@ -317,6 +318,34 @@ $zindex: 2147483640; // near 32bit max 2147483647 $radius: 10px; + &.profiler-left { + .profiler-button { + text-align: left; + } + } + + &.profiler-right { + .profiler-button { + text-align: right; + } + } + + .profiler-button { + > .profiler-duration-milliseconds { + min-width: 70px; + } + > .profiler-sql-count { + min-width: 55px; + } + > .profiler-name { + min-width: 190px; + margin-left: 3px; + } + > .profiler-number { + text-align: right; + } + } + &.profiler-top { top: 0px; @@ -399,7 +428,8 @@ $zindex: 2147483640; // near 32bit max 2147483647 background-color: maroon; .profiler-number, - .profiler-nuclear { + .profiler-nuclear, + .profiler-name { color: #fff; font-weight: bold; } diff --git a/lib/html/includes.tmpl b/lib/html/includes.tmpl index 42ec6393..6f51cc34 100644 --- a/lib/html/includes.tmpl +++ b/lib/html/includes.tmpl @@ -2,14 +2,21 @@
{{? it.has_duplicate_sql_timings}}!{{?}} - + {{= MiniProfiler.formatDuration(it.duration_milliseconds)}} ms {{? MiniProfiler.showTotalSqlCount()}} - + {{= it.sql_count}} sql {{?}} + + {{? it.name.length >= 30 }} + {{= it.name.substring(0,15) + "..." + it.name.slice(-15) }} + {{??}} + {{= it.name}} + {{?}} +
diff --git a/lib/html/vendor.js b/lib/html/vendor.js index 8e239433..8091abc1 100644 --- a/lib/html/vendor.js +++ b/lib/html/vendor.js @@ -7,7 +7,7 @@ MiniProfiler.templates = {}; MiniProfiler.templates["profilerTemplate"] = function anonymous(it ) { -var out='
';if(it.has_duplicate_sql_timings){out+='!';}out+=' '+( MiniProfiler.formatDuration(it.duration_milliseconds))+' ms ';if(MiniProfiler.showTotalSqlCount()){out+=' '+( it.sql_count)+' sql ';}out+='
'+( it.name)+' ('+( MiniProfiler.formatDuration(it.duration_milliseconds))+' ms) '+( it.machine_name)+' on '+( MiniProfiler.renderDate(it.started_formatted))+'
';if(it.has_sql_timings){out+=' ';}out+=' ';var arr1=it.custom_timing_names;if(arr1){var value,i1=-1,l1=arr1.length-1;while(i1'+( value.toLowerCase() )+' (ms) ';} } out+=' '+( MiniProfiler.templates.timingTemplate({timing: it.root, page: it}) )+' ';if(it.has_sql_timings){out+=' ';}out+=' ';var arr2=it.custom_timing_names;if(arr2){var value,i2=-1,l2=arr2.length-1;while(i2 '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration / it.duration_milliseconds * 100) )+' % in '+( value.toLowerCase() )+' ';} } out+='
event duration (ms) with children (ms) from start (ms)query time (ms)
';if(!it.client_timings){out+=' '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' ';}out+=' show time with children snapshots '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql / it.duration_milliseconds * 100) )+' % in sql
';if(it.client_timings){out+=' ';var arr3=MiniProfiler.getClientTimings(it.client_timings);if(arr3){var value,i3=-1,l3=arr3.length-1;while(i3 ';} } out+='
client event duration (ms) from start (ms)
'+( value.name )+' ';if(value.duration >= 0){out+=' '+( MiniProfiler.formatDuration(value.duration) )+' ';}out+=' +'+( MiniProfiler.formatDuration(value.start) )+'
'+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+'
';}out+=' ';if(it.custom_fields && Object.keys(it.custom_fields).length > 0){out+='

Snapshot custom fields

';var arr4=Object.keys(it.custom_fields);if(arr4){var key,i4=-1,l4=arr4.length-1;while(i4 ';} } out+='
'+( key )+' '+( it.custom_fields[key] )+'
';}out+='
';if(it.has_sql_timings){out+='
';var arr5=MiniProfiler.getSqlTimings(it.root);if(arr5){var value,index=-1,l5=arr5.length-1;while(indexms ';if(MiniProfiler.showTotalSqlCount()){out+=' '+( it.sql_count)+' sql ';}out+=' ';if(it.name.length >= 30){out+=' '+( it.name.substring(0,15) + "..." + it.name.slice(-15) )+' ';}else{out+=' '+( it.name)+' ';}out+='
'+( it.name)+' ('+( MiniProfiler.formatDuration(it.duration_milliseconds))+' ms) '+( it.machine_name)+' on '+( MiniProfiler.renderDate(it.started_formatted))+'
step
time from start
query type
duration
call stack
query
';if(it.has_sql_timings){out+=' ';}out+=' ';var arr1=it.custom_timing_names;if(arr1){var value,i1=-1,l1=arr1.length-1;while(i1'+( value.toLowerCase() )+' (ms) ';} } out+=' '+( MiniProfiler.templates.timingTemplate({timing: it.root, page: it}) )+' ';if(it.has_sql_timings){out+=' ';}out+=' ';var arr2=it.custom_timing_names;if(arr2){var value,i2=-1,l2=arr2.length-1;while(i2 '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration / it.duration_milliseconds * 100) )+' % in '+( value.toLowerCase() )+' ';} } out+='
event duration (ms) with children (ms) from start (ms)query time (ms)
';if(!it.client_timings){out+=' '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' ';}out+=' show time with children snapshots '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql / it.duration_milliseconds * 100) )+' % in sql
';if(it.client_timings){out+=' ';var arr3=MiniProfiler.getClientTimings(it.client_timings);if(arr3){var value,i3=-1,l3=arr3.length-1;while(i3 ';} } out+='
client event duration (ms) from start (ms)
'+( value.name )+' ';if(value.duration >= 0){out+=' '+( MiniProfiler.formatDuration(value.duration) )+' ';}out+=' +'+( MiniProfiler.formatDuration(value.start) )+'
'+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+'
';}out+=' ';if(it.custom_fields && Object.keys(it.custom_fields).length > 0){out+='

Snapshot custom fields

';var arr4=Object.keys(it.custom_fields);if(arr4){var key,i4=-1,l4=arr4.length-1;while(i4 ';} } out+='
'+( key )+' '+( it.custom_fields[key] )+'
';}out+='
';if(it.has_sql_timings){out+='
';var arr5=MiniProfiler.getSqlTimings(it.root);if(arr5){var value,index=-1,l5=arr5.length-1;while(index Date: Tue, 2 Jan 2024 09:17:19 +0900 Subject: [PATCH 3/6] Move page_name into its own method --- lib/mini_profiler/timer_struct/page.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/mini_profiler/timer_struct/page.rb b/lib/mini_profiler/timer_struct/page.rb index 94769eb4..3168a38b 100644 --- a/lib/mini_profiler/timer_struct/page.rb +++ b/lib/mini_profiler/timer_struct/page.rb @@ -59,7 +59,6 @@ def symbolize_array(array) def initialize(env) timer_id = MiniProfiler.generate_id - page_name = env['QUERY_STRING'] != "" ? env['PATH_INFO'] + "?" + env['QUERY_STRING'] : env['PATH_INFO'] started_at = (Time.now.to_f * 1000).to_i started = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i machine_name = env['SERVER_NAME'] @@ -101,6 +100,14 @@ def name @attributes[:name] end + def page_name + if env['QUERY_STRING'] && env['QUERY_STRING'] != "" + env['PATH_INFO'] + "?" + env['QUERY_STRING'] + else + env['PATH_INFO'] + end + end + def duration_ms @attributes[:root][:duration_milliseconds] end From 2ce3fee62d437364185572d7ba85688df9cb34fb Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Tue, 2 Jan 2024 09:22:26 +0900 Subject: [PATCH 4/6] Requests also include query string --- lib/mini_profiler/timer_struct/page.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mini_profiler/timer_struct/page.rb b/lib/mini_profiler/timer_struct/page.rb index 3168a38b..102ccdf5 100644 --- a/lib/mini_profiler/timer_struct/page.rb +++ b/lib/mini_profiler/timer_struct/page.rb @@ -64,7 +64,7 @@ def initialize(env) machine_name = env['SERVER_NAME'] super( id: timer_id, - name: page_name, + name: page_name(env), started: started, started_at: started_at, machine_name: machine_name, @@ -92,7 +92,7 @@ def initialize(env) ) self[:request_method] = env['REQUEST_METHOD'] self[:request_path] = env['PATH_INFO'] - name = "#{env['REQUEST_METHOD']} http://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['SCRIPT_NAME']}#{env['PATH_INFO']}" + name = "#{env['REQUEST_METHOD']} http://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['SCRIPT_NAME']}#{page_name(env)}" self[:root] = TimerStruct::Request.createRoot(name, self) end @@ -100,7 +100,7 @@ def name @attributes[:name] end - def page_name + def page_name(env) if env['QUERY_STRING'] && env['QUERY_STRING'] != "" env['PATH_INFO'] + "?" + env['QUERY_STRING'] else From 804f2da6ff522bc103c529a79a1a2889a692dbbc Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Tue, 2 Jan 2024 09:25:00 +0900 Subject: [PATCH 5/6] Always display totals control (so URL/name is hidden) --- lib/html/includes.js | 2 +- lib/mini_profiler/asset_version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/html/includes.js b/lib/html/includes.js index 9fd679eb..4b57ad9f 100644 --- a/lib/html/includes.js +++ b/lib/html/includes.js @@ -220,7 +220,7 @@ var _MiniProfiler = (function() { totalSqlCount += parseInt(json.sql_count); reqs++; - if (!controls && reqs > 1 && options.collapseResults && !expandedResults) { + if (!controls && options.collapseResults && !expandedResults) { if (!totalsControl) { toArray(container.querySelectorAll(".profiler-result")).forEach( function(el) { diff --git a/lib/mini_profiler/asset_version.rb b/lib/mini_profiler/asset_version.rb index 39ecfad2..a9b0d36b 100644 --- a/lib/mini_profiler/asset_version.rb +++ b/lib/mini_profiler/asset_version.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true module Rack class MiniProfiler - ASSET_VERSION = '1369b689f72a69d94d8d7d0ffc2d4842' + ASSET_VERSION = '116e2a6fd81c286e004e2a0afb03baa1' end end From 7d16109d139377f0517cfa565b964491b8da8eff Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Tue, 2 Jan 2024 09:26:44 +0900 Subject: [PATCH 6/6] Whitespace --- lib/mini_profiler/timer_struct/page.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mini_profiler/timer_struct/page.rb b/lib/mini_profiler/timer_struct/page.rb index 102ccdf5..d32d28e8 100644 --- a/lib/mini_profiler/timer_struct/page.rb +++ b/lib/mini_profiler/timer_struct/page.rb @@ -103,10 +103,10 @@ def name def page_name(env) if env['QUERY_STRING'] && env['QUERY_STRING'] != "" env['PATH_INFO'] + "?" + env['QUERY_STRING'] - else + else env['PATH_INFO'] end - end + end def duration_ms @attributes[:root][:duration_milliseconds]
step
time from start
query type
duration
call stack
query