Skip to content

Commit

Permalink
Display name in badge (#602)
Browse files Browse the repository at this point in the history
* Page name includes query string

* Badge: align columns, display page name

* Move page_name into its own method

* Requests also include query string

* Always display totals control (so URL/name is hidden)

* Whitespace
  • Loading branch information
nateberkopec committed Jan 2, 2024
1 parent c83223f commit 68a69b3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 11 deletions.
20 changes: 18 additions & 2 deletions lib/html/includes.css
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/html/includes.js
Expand Up @@ -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) {
Expand Down
32 changes: 31 additions & 1 deletion lib/html/includes.scss
Expand Up @@ -103,6 +103,7 @@ $zindex: 2147483640; // near 32bit max 2147483647

.profiler-number {
color: $numberColor;
display: inline-block;
}

.profiler-info {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/html/includes.tmpl
Expand Up @@ -2,14 +2,21 @@
<div class="profiler-result">
<div class="profiler-button {{? it.has_duplicate_sql_timings}}profiler-warning{{?}}">
{{? it.has_duplicate_sql_timings}}<span class="profiler-nuclear">!</span>{{?}}
<span class="profiler-number">
<span class="profiler-number profiler-duration-milliseconds">
{{= MiniProfiler.formatDuration(it.duration_milliseconds)}} <span class="profiler-unit">ms</span>
</span>
{{? MiniProfiler.showTotalSqlCount()}}
<span class="profiler-number">
<span class="profiler-number profiler-sql-count">
{{= it.sql_count}} <span class="profiler-unit">sql</span>
</span>
{{?}}
<span class="profiler-name">
{{? it.name.length >= 30 }}
{{= it.name.substring(0,15) + "..." + it.name.slice(-15) }}
{{??}}
{{= it.name}}
{{?}}
</span>
</div>

<div class="profiler-popup">
Expand Down
2 changes: 1 addition & 1 deletion lib/html/vendor.js
Expand Up @@ -7,7 +7,7 @@
MiniProfiler.templates = {};
MiniProfiler.templates["profilerTemplate"] = function anonymous(it
) {
var out=' <div class="profiler-result"> <div class="profiler-button ';if(it.has_duplicate_sql_timings){out+='profiler-warning';}out+='"> ';if(it.has_duplicate_sql_timings){out+='<span class="profiler-nuclear">!</span>';}out+=' <span class="profiler-number"> '+( MiniProfiler.formatDuration(it.duration_milliseconds))+' <span class="profiler-unit">ms</span> </span> ';if(MiniProfiler.showTotalSqlCount()){out+=' <span class="profiler-number"> '+( it.sql_count)+' <span class="profiler-unit">sql</span> </span> ';}out+=' </div> <div class="profiler-popup"> <div class="profiler-info"> <span class="profiler-name"> '+( it.name)+' <span class="profiler-overall-duration">('+( MiniProfiler.formatDuration(it.duration_milliseconds))+' ms)</span> </span> <span class="profiler-server-time">'+( it.machine_name)+' on '+( MiniProfiler.renderDate(it.started_formatted))+'</span> </div> <div class="profiler-output"> <table class="profiler-timings"> <thead> <tr> <th>event</th> <th>duration (ms)</th> <th class="profiler-duration-with-children">with children (ms)</th> <th class="time-from-start">from start (ms)</th> ';if(it.has_sql_timings){out+=' <th colspan="2">query time (ms)</th> ';}out+=' ';var arr1=it.custom_timing_names;if(arr1){var value,i1=-1,l1=arr1.length-1;while(i1<l1){value=arr1[i1+=1];out+=' <th colspan="2">'+( value.toLowerCase() )+' (ms)</th> ';} } out+=' </tr> </thead> <tbody> '+( MiniProfiler.templates.timingTemplate({timing: it.root, page: it}) )+' </tbody> <tfoot> <tr> <td colspan="3"> ';if(!it.client_timings){out+=' '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' ';}out+=' <a class="profiler-toggle-duration-with-children" title="toggles column with aggregate child durations">show time with children</a> <a class="profiler-snapshots-page-link" title="Go to snapshots page" href="'+( MiniProfiler.options.path )+'snapshots">snapshots</a> </td> ';if(it.has_sql_timings){out+=' <td colspan="2" class="profiler-number profiler-percent-in-sql" title="'+( MiniProfiler.getSqlTimingsCount(it.root) )+' queries spent '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql) )+' ms of total request time"> '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql / it.duration_milliseconds * 100) )+' <span class="profiler-unit">% in sql</span> </td> ';}out+=' ';var arr2=it.custom_timing_names;if(arr2){var value,i2=-1,l2=arr2.length-1;while(i2<l2){value=arr2[i2+=1];out+=' <td colspan="2" class="profiler-number profiler-percentage-in-sql" title="'+( it.custom_timing_stats[value].count )+' '+( value.toLowerCase() )+' invocations spent '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration) )+' ms of total request time"> '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration / it.duration_milliseconds * 100) )+' <span class="profiler-unit">% in '+( value.toLowerCase() )+'</span> </td> ';} } out+=' </tr> </tfoot> </table> ';if(it.client_timings){out+=' <table class="profiler-timings profiler-client-timings"> <thead> <tr> <th>client event</th> <th>duration (ms)</th> <th>from start (ms)</th> </tr> </thead> <tbody> ';var arr3=MiniProfiler.getClientTimings(it.client_timings);if(arr3){var value,i3=-1,l3=arr3.length-1;while(i3<l3){value=arr3[i3+=1];out+=' <tr class="';if(value.isTrivial){out+='profiler-trivial';}out+='"> <td class="profiler-label">'+( value.name )+'</td> <td class="profiler-duration"> ';if(value.duration >= 0){out+=' <span class="profiler-unit"></span>'+( MiniProfiler.formatDuration(value.duration) )+' ';}out+=' </td> <td class="profiler-duration time-from-start"> <span class="profiler-unit">+</span>'+( MiniProfiler.formatDuration(value.start) )+' </td> </tr> ';} } out+=' </tbody> <tfoot> <td colspan="3"> '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' </td> </tfoot> </table> ';}out+=' ';if(it.custom_fields && Object.keys(it.custom_fields).length > 0){out+=' <p class="custom-fields-title">Snapshot custom fields</p> <table class="profiler-timings"> <tbody> ';var arr4=Object.keys(it.custom_fields);if(arr4){var key,i4=-1,l4=arr4.length-1;while(i4<l4){key=arr4[i4+=1];out+=' <tr> <td class="profiler-label">'+( key )+'</td> <td class="profiler-label">'+( it.custom_fields[key] )+'</td> </tr> ';} } out+=' </tbody> </table> ';}out+=' </div> </div> ';if(it.has_sql_timings){out+=' <div class="profiler-queries"> <table> <thead> <tr> <th class="ta-right">step<br />time from start<br />query type<br />duration</th> <th class="ta-left">call stack<br />query</th> </tr> </thead> <tbody> ';var arr5=MiniProfiler.getSqlTimings(it.root);if(arr5){var value,index=-1,l5=arr5.length-1;while(index<l5){value=arr5[index+=1];out+=' '+( MiniProfiler.templates.sqlGapTemplate({g: value.prevGap}) )+' '+( MiniProfiler.templates.sqlTimingTemplate({i: index, s: value}) )+' ';if(value.nextGap){out+=' '+( MiniProfiler.templates.sqlGapTemplate({g: value.nextGap}) )+' ';}out+=' ';} } out+=' </tbody> </table> <p class="profiler-trivial-gap-container"> <a class="profiler-toggle-trivial-gaps">show trivial gaps</a> </p> </div> ';}out+=' </div>';return out;
var out=' <div class="profiler-result"> <div class="profiler-button ';if(it.has_duplicate_sql_timings){out+='profiler-warning';}out+='"> ';if(it.has_duplicate_sql_timings){out+='<span class="profiler-nuclear">!</span>';}out+=' <span class="profiler-number profiler-duration-milliseconds"> '+( MiniProfiler.formatDuration(it.duration_milliseconds))+' <span class="profiler-unit">ms</span> </span> ';if(MiniProfiler.showTotalSqlCount()){out+=' <span class="profiler-number profiler-sql-count"> '+( it.sql_count)+' <span class="profiler-unit">sql</span> </span> ';}out+=' <span class="profiler-name"> ';if(it.name.length >= 30){out+=' '+( it.name.substring(0,15) + "..." + it.name.slice(-15) )+' ';}else{out+=' '+( it.name)+' ';}out+=' </span> </div> <div class="profiler-popup"> <div class="profiler-info"> <span class="profiler-name"> '+( it.name)+' <span class="profiler-overall-duration">('+( MiniProfiler.formatDuration(it.duration_milliseconds))+' ms)</span> </span> <span class="profiler-server-time">'+( it.machine_name)+' on '+( MiniProfiler.renderDate(it.started_formatted))+'</span> </div> <div class="profiler-output"> <table class="profiler-timings"> <thead> <tr> <th>event</th> <th>duration (ms)</th> <th class="profiler-duration-with-children">with children (ms)</th> <th class="time-from-start">from start (ms)</th> ';if(it.has_sql_timings){out+=' <th colspan="2">query time (ms)</th> ';}out+=' ';var arr1=it.custom_timing_names;if(arr1){var value,i1=-1,l1=arr1.length-1;while(i1<l1){value=arr1[i1+=1];out+=' <th colspan="2">'+( value.toLowerCase() )+' (ms)</th> ';} } out+=' </tr> </thead> <tbody> '+( MiniProfiler.templates.timingTemplate({timing: it.root, page: it}) )+' </tbody> <tfoot> <tr> <td colspan="3"> ';if(!it.client_timings){out+=' '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' ';}out+=' <a class="profiler-toggle-duration-with-children" title="toggles column with aggregate child durations">show time with children</a> <a class="profiler-snapshots-page-link" title="Go to snapshots page" href="'+( MiniProfiler.options.path )+'snapshots">snapshots</a> </td> ';if(it.has_sql_timings){out+=' <td colspan="2" class="profiler-number profiler-percent-in-sql" title="'+( MiniProfiler.getSqlTimingsCount(it.root) )+' queries spent '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql) )+' ms of total request time"> '+( MiniProfiler.formatDuration(it.duration_milliseconds_in_sql / it.duration_milliseconds * 100) )+' <span class="profiler-unit">% in sql</span> </td> ';}out+=' ';var arr2=it.custom_timing_names;if(arr2){var value,i2=-1,l2=arr2.length-1;while(i2<l2){value=arr2[i2+=1];out+=' <td colspan="2" class="profiler-number profiler-percentage-in-sql" title="'+( it.custom_timing_stats[value].count )+' '+( value.toLowerCase() )+' invocations spent '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration) )+' ms of total request time"> '+( MiniProfiler.formatDuration(it.custom_timing_stats[value].duration / it.duration_milliseconds * 100) )+' <span class="profiler-unit">% in '+( value.toLowerCase() )+'</span> </td> ';} } out+=' </tr> </tfoot> </table> ';if(it.client_timings){out+=' <table class="profiler-timings profiler-client-timings"> <thead> <tr> <th>client event</th> <th>duration (ms)</th> <th>from start (ms)</th> </tr> </thead> <tbody> ';var arr3=MiniProfiler.getClientTimings(it.client_timings);if(arr3){var value,i3=-1,l3=arr3.length-1;while(i3<l3){value=arr3[i3+=1];out+=' <tr class="';if(value.isTrivial){out+='profiler-trivial';}out+='"> <td class="profiler-label">'+( value.name )+'</td> <td class="profiler-duration"> ';if(value.duration >= 0){out+=' <span class="profiler-unit"></span>'+( MiniProfiler.formatDuration(value.duration) )+' ';}out+=' </td> <td class="profiler-duration time-from-start"> <span class="profiler-unit">+</span>'+( MiniProfiler.formatDuration(value.start) )+' </td> </tr> ';} } out+=' </tbody> <tfoot> <td colspan="3"> '+( MiniProfiler.templates.linksTemplate({timing: it.root, page: it}) )+' </td> </tfoot> </table> ';}out+=' ';if(it.custom_fields && Object.keys(it.custom_fields).length > 0){out+=' <p class="custom-fields-title">Snapshot custom fields</p> <table class="profiler-timings"> <tbody> ';var arr4=Object.keys(it.custom_fields);if(arr4){var key,i4=-1,l4=arr4.length-1;while(i4<l4){key=arr4[i4+=1];out+=' <tr> <td class="profiler-label">'+( key )+'</td> <td class="profiler-label">'+( it.custom_fields[key] )+'</td> </tr> ';} } out+=' </tbody> </table> ';}out+=' </div> </div> ';if(it.has_sql_timings){out+=' <div class="profiler-queries"> <table> <thead> <tr> <th class="ta-right">step<br />time from start<br />query type<br />duration</th> <th class="ta-left">call stack<br />query</th> </tr> </thead> <tbody> ';var arr5=MiniProfiler.getSqlTimings(it.root);if(arr5){var value,index=-1,l5=arr5.length-1;while(index<l5){value=arr5[index+=1];out+=' '+( MiniProfiler.templates.sqlGapTemplate({g: value.prevGap}) )+' '+( MiniProfiler.templates.sqlTimingTemplate({i: index, s: value}) )+' ';if(value.nextGap){out+=' '+( MiniProfiler.templates.sqlGapTemplate({g: value.nextGap}) )+' ';}out+=' ';} } out+=' </tbody> </table> <p class="profiler-trivial-gap-container"> <a class="profiler-toggle-trivial-gaps">show trivial gaps</a> </p> </div> ';}out+=' </div>';return out;
}
MiniProfiler.templates["linksTemplate"] = function anonymous(it
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mini_profiler/asset_version.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module Rack
class MiniProfiler
ASSET_VERSION = 'c336b1303a50b21f5222bc23262ca7bf'
ASSET_VERSION = '116e2a6fd81c286e004e2a0afb03baa1'
end
end
13 changes: 10 additions & 3 deletions lib/mini_profiler/timer_struct/page.rb
Expand Up @@ -59,13 +59,12 @@ def symbolize_array(array)

def initialize(env)
timer_id = MiniProfiler.generate_id
page_name = 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']
super(
id: timer_id,
name: page_name,
name: page_name(env),
started: started,
started_at: started_at,
machine_name: machine_name,
Expand Down Expand Up @@ -93,14 +92,22 @@ 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

def name
@attributes[:name]
end

def page_name(env)
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
Expand Down

0 comments on commit 68a69b3

Please sign in to comment.