rails_mini_profiler 0.6.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +47 -35
  3. data/app/adapters/rails_mini_profiler/database_adapter.rb +16 -0
  4. data/app/controllers/rails_mini_profiler/application_controller.rb +9 -15
  5. data/app/controllers/rails_mini_profiler/profiled_requests_controller.rb +31 -4
  6. data/app/helpers/rails_mini_profiler/profiled_requests_helper.rb +10 -0
  7. data/app/javascript/js/clipboard_controller.js +9 -2
  8. data/app/javascript/js/filter_controller.js +4 -0
  9. data/app/javascript/stylesheets/components/buttons.scss +59 -0
  10. data/app/javascript/stylesheets/components/{profiled_request_table/profiled_request_table.scss → dropdown.scss} +0 -76
  11. data/app/javascript/stylesheets/components/input.scss +10 -0
  12. data/app/javascript/stylesheets/{navbar.scss → components/navbar.scss} +0 -0
  13. data/app/javascript/stylesheets/components/page_header.scss +7 -0
  14. data/app/javascript/stylesheets/components/{profiled_request_table/placeholder.scss → placeholder.scss} +4 -1
  15. data/app/javascript/stylesheets/components/profiled_request_table.scss +55 -0
  16. data/app/javascript/stylesheets/components/trace.scss +93 -0
  17. data/app/javascript/stylesheets/profiled_requests.scss +3 -67
  18. data/app/javascript/stylesheets/rails-mini-profiler.scss +16 -30
  19. data/app/javascript/stylesheets/traces.scss +44 -76
  20. data/app/models/rails_mini_profiler/flamegraph.rb +1 -1
  21. data/app/models/rails_mini_profiler/profiled_request.rb +1 -1
  22. data/app/models/rails_mini_profiler/trace.rb +4 -19
  23. data/app/presenters/rails_mini_profiler/controller_trace_presenter.rb +10 -2
  24. data/app/presenters/rails_mini_profiler/instantiation_trace_presenter.rb +15 -3
  25. data/app/presenters/rails_mini_profiler/profiled_request_presenter.rb +2 -2
  26. data/app/presenters/rails_mini_profiler/render_partial_trace_presenter.rb +6 -2
  27. data/app/presenters/rails_mini_profiler/render_template_trace_presenter.rb +6 -2
  28. data/app/presenters/rails_mini_profiler/sequel_trace_presenter.rb +16 -4
  29. data/app/presenters/rails_mini_profiler/trace_presenter.rb +10 -8
  30. data/app/search/rails_mini_profiler/profiled_request_search.rb +0 -1
  31. data/app/search/rails_mini_profiler/trace_search.rb +27 -0
  32. data/app/views/rails_mini_profiler/profiled_requests/shared/header/_header.erb +1 -2
  33. data/app/views/rails_mini_profiler/profiled_requests/shared/table/_table_head.erb +7 -7
  34. data/app/views/rails_mini_profiler/profiled_requests/{shared → show}/_trace.html.erb +24 -22
  35. data/app/views/rails_mini_profiler/profiled_requests/show/_trace_list.erb +12 -0
  36. data/app/views/rails_mini_profiler/profiled_requests/show/_trace_list_header.erb +87 -0
  37. data/app/views/rails_mini_profiler/profiled_requests/show/_trace_list_placeholder.erb +12 -0
  38. data/app/views/rails_mini_profiler/profiled_requests/show.html.erb +4 -17
  39. data/db/migrate/20210621185018_create_rmp.rb +3 -3
  40. data/lib/generators/rails_mini_profiler/templates/rails_mini_profiler.rb.erb +1 -0
  41. data/lib/rails_mini_profiler/badge.rb +20 -11
  42. data/lib/rails_mini_profiler/configuration/user_interface.rb +26 -0
  43. data/lib/rails_mini_profiler/configuration.rb +4 -0
  44. data/lib/rails_mini_profiler/flamegraph_guard.rb +10 -6
  45. data/lib/rails_mini_profiler/middleware.rb +12 -10
  46. data/lib/rails_mini_profiler/request_context.rb +22 -18
  47. data/lib/rails_mini_profiler/request_wrapper.rb +12 -55
  48. data/lib/rails_mini_profiler/response_wrapper.rb +21 -17
  49. data/lib/rails_mini_profiler/{tracing → tracers}/controller_tracer.rb +15 -1
  50. data/lib/rails_mini_profiler/tracers/instantiation_tracer.rb +17 -0
  51. data/lib/rails_mini_profiler/{tracing → tracers}/null_trace.rb +1 -1
  52. data/lib/rails_mini_profiler/tracers/registry.rb +76 -0
  53. data/lib/rails_mini_profiler/tracers/rmp_tracer.rb +17 -0
  54. data/lib/rails_mini_profiler/{tracing → tracers}/sequel_tracer.rb +15 -1
  55. data/lib/rails_mini_profiler/{tracing → tracers}/sequel_tracker.rb +4 -1
  56. data/lib/rails_mini_profiler/{tracing → tracers}/subscriptions.rb +6 -12
  57. data/lib/rails_mini_profiler/{tracing → tracers}/trace.rb +2 -2
  58. data/lib/rails_mini_profiler/tracers/trace_factory.rb +27 -0
  59. data/lib/rails_mini_profiler/tracers/tracer.rb +52 -0
  60. data/lib/rails_mini_profiler/tracers/view_tracer.rb +29 -0
  61. data/lib/rails_mini_profiler/tracers.rb +14 -0
  62. data/lib/rails_mini_profiler/user.rb +1 -1
  63. data/lib/rails_mini_profiler/version.rb +1 -1
  64. data/lib/rails_mini_profiler.rb +1 -1
  65. data/vendor/assets/javascripts/rails-mini-profiler.css +1 -1
  66. data/vendor/assets/javascripts/rails-mini-profiler.js +1 -1
  67. metadata +39 -26
  68. data/app/javascript/stylesheets/components/page_header/page_header.scss +0 -3
  69. data/app/models/rails_mini_profiler/controller_trace.rb +0 -37
  70. data/app/models/rails_mini_profiler/instantiation_trace.rb +0 -37
  71. data/app/models/rails_mini_profiler/render_partial_trace.rb +0 -37
  72. data/app/models/rails_mini_profiler/render_template_trace.rb +0 -37
  73. data/app/models/rails_mini_profiler/rmp_trace.rb +0 -35
  74. data/app/models/rails_mini_profiler/sequel_trace.rb +0 -37
  75. data/lib/rails_mini_profiler/tracing/trace_factory.rb +0 -37
  76. data/lib/rails_mini_profiler/tracing/tracer.rb +0 -31
  77. data/lib/rails_mini_profiler/tracing/view_tracer.rb +0 -12
  78. data/lib/rails_mini_profiler/tracing.rb +0 -11
@@ -0,0 +1,93 @@
1
+ .trace {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: flex-start;
5
+ padding: 0.25em 0;
6
+ list-style: none;
7
+ }
8
+
9
+ .trace:nth-child(odd) {
10
+ background: var(--grey-100);
11
+ }
12
+
13
+ .trace .trace-bar {
14
+ position: relative;
15
+ height: 16px;
16
+ padding: 0;
17
+ margin: 0;
18
+ background: linear-gradient(to top right, var(--grey-500), var(--grey-400));
19
+ cursor: pointer;
20
+ }
21
+
22
+ .instantiation-trace .trace-bar {
23
+ background: linear-gradient(to top right, var(--green-400), var(--green-300));
24
+ }
25
+
26
+ .sequel-trace .trace-bar {
27
+ background: linear-gradient(to top right, var(--green-500), var(--green-400));
28
+ }
29
+
30
+ .controller-trace .trace-bar {
31
+ background: linear-gradient(to top right, var(--yellow-500), var(--yellow-400));
32
+ }
33
+
34
+ .render-template-trace .trace-bar,
35
+ .render-partial-trace .trace-bar {
36
+ background: linear-gradient(to top right, var(--blue-500), var(--blue-400));
37
+ }
38
+
39
+ .trace-name {
40
+ overflow: hidden;
41
+ box-sizing: border-box;
42
+ padding: 0 0.5em;
43
+ margin: 0;
44
+ color: var(--grey-400);
45
+ font-size: 14px;
46
+ text-align: right;
47
+ text-overflow: ellipsis;
48
+ }
49
+
50
+ .trace-payload {
51
+ margin: 0;
52
+ }
53
+
54
+ .sequel-trace-query {
55
+ overflow: auto;
56
+ max-height: 100px;
57
+ padding: 1em 1em;
58
+ background: var(--grey-100);
59
+ white-space: pre-wrap;
60
+ }
61
+
62
+ .sequel-trace-binds {
63
+ overflow: auto;
64
+ max-height: 100px;
65
+ padding: 0.5em 1em;
66
+ margin: 0 0 1em 0;
67
+ background: var(--grey-50);
68
+ font-size: 12px;
69
+ white-space: pre-wrap;
70
+ }
71
+
72
+ .backtrace {
73
+ display: flex;
74
+ flex-direction: row;
75
+ align-items: center;
76
+ justify-content: space-between;
77
+ padding: 0.5em;
78
+ background: var(--grey-100);
79
+ }
80
+
81
+ .backtrace button {
82
+ overflow: auto;
83
+ height: 20px;
84
+ padding: 0;
85
+ margin: 0;
86
+ background: none;
87
+ color: var(--grey-500);
88
+ }
89
+
90
+ .backtrace button svg {
91
+ width: 20px;
92
+ height: 20px;
93
+ }
@@ -1,15 +1,4 @@
1
- @import 'components/profiled_request_table/placeholder';
2
- @import 'components/profiled_request_table/profiled_request_table';
3
-
4
- main {
5
- display: flex;
6
- width: 100%;
7
- justify-content: center;
8
- }
9
-
10
- .main-section {
11
- width: var(--main-width);
12
- }
1
+ @import 'components/profiled_request_table';
13
2
 
14
3
  .search-field {
15
4
  box-sizing: border-box;
@@ -18,57 +7,11 @@ main {
18
7
  border-radius: 5px;
19
8
  }
20
9
 
21
- .request-details-data {
22
- display: flex;
23
- padding: 1rem 0;
24
- }
25
-
26
- .request-details-actions {
10
+ .profiled-requests-header {
27
11
  display: flex;
12
+ flex-direction: row;
28
13
  align-items: center;
29
14
  justify-content: space-between;
30
- padding: 0 0 1rem;
31
- margin: 0;
32
- }
33
-
34
- .data-item {
35
- display: flex;
36
- flex-direction: column;
37
- align-items: flex-start;
38
- padding: 0;
39
- margin-right: 3rem;
40
- list-style: none;
41
- }
42
-
43
- .data-item small {
44
- color: var(--grey-400);
45
- }
46
-
47
- .data-item span {
48
- margin: 0.25rem 0;
49
- }
50
-
51
- [class*='request-status-2'],
52
- [class*='request-method-get'] {
53
- background: var(--green-400) !important;
54
- color: white;
55
- }
56
-
57
- [class*='request-status-4'],
58
- [class*='request-method-put'],
59
- [class*='request-method-patch'] {
60
- background: var(--yellow-400) !important;
61
- color: white;
62
- }
63
-
64
- [class*='request-status-5'],
65
- [class*='request-method-delete'] {
66
- background: var(--red-500) !important;
67
- color: white;
68
- }
69
-
70
- .flamegraph-button button {
71
- background: var(--grey-200);
72
15
  }
73
16
 
74
17
  .clear-action button {
@@ -80,10 +23,3 @@ main {
80
23
  background: var(--red-600);
81
24
  }
82
25
  }
83
-
84
- .profiled-requests-header {
85
- display: flex;
86
- flex-direction: row;
87
- align-items: center;
88
- justify-content: space-between;
89
- }
@@ -1,10 +1,15 @@
1
1
  @import 'flashes';
2
2
  @import 'flamegraph';
3
- @import 'navbar';
4
3
  @import 'profiled_requests';
5
4
  @import 'traces';
5
+ @import 'components/buttons';
6
+ @import 'components/input';
7
+ @import 'components/navbar';
6
8
  @import 'components/pagination';
7
- @import 'components/page_header/page_header';
9
+ @import 'components/page_header';
10
+ @import 'components/dropdown';
11
+ @import 'components/placeholder';
12
+ @import 'components/trace';
8
13
  @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');
9
14
 
10
15
  @font-face {
@@ -55,6 +60,9 @@ html {
55
60
  --primary: var(--red-600);
56
61
  --border-color: var(--grey-200);
57
62
  --text-color: var(--grey-900);
63
+ --fw-normal: 400;
64
+ --fw-semibold: 600;
65
+ --fw-bold: 700;
58
66
  }
59
67
 
60
68
  * {
@@ -70,36 +78,14 @@ body {
70
78
  color: var(--text-color);
71
79
  }
72
80
 
73
- button,
74
- .button {
75
- display: inline-block;
76
- padding: 0.5em 0.5em;
77
- border: none;
78
- border-radius: 0.25rem;
79
- cursor: pointer;
80
- font-size: 1rem;
81
- text-align: center;
82
- text-decoration: none;
83
-
84
- &:disabled {
85
- background: var(--grey-200);
86
- cursor: not-allowed;
87
- }
88
- }
89
-
90
- button:hover {
91
- box-shadow: 0 0.25rem 0.25rem 0 var(--grey-50);
81
+ main {
82
+ display: flex;
83
+ width: 100%;
84
+ justify-content: center;
92
85
  }
93
86
 
94
- button.none {
95
- padding: 0;
96
- border: none;
97
- background: none;
98
- outline: none;
99
-
100
- &:hover {
101
- box-shadow: none;
102
- }
87
+ .main-section {
88
+ width: var(--main-width);
103
89
  }
104
90
 
105
91
  /* --------------------------------------- */
@@ -1,110 +1,78 @@
1
- .trace-list {
2
- padding: 0;
3
- margin: 2rem 0;
4
- }
5
-
6
- .trace {
1
+ .profiled-request-details {
7
2
  display: flex;
8
3
  align-items: center;
9
- justify-content: flex-start;
10
- padding: 0.25em 0;
11
- list-style: none;
4
+ justify-content: space-between;
5
+ padding-bottom: 2rem;
12
6
  }
13
7
 
14
- .trace:nth-child(odd) {
15
- background: var(--grey-100);
8
+ .request-details-data {
9
+ display: flex;
16
10
  }
17
11
 
18
- .trace .trace-bar {
19
- position: relative;
20
- height: 16px;
12
+ .data-item {
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: flex-start;
21
16
  padding: 0;
22
- margin: 0;
23
- background: linear-gradient(to top right, var(--grey-500), var(--grey-400));
24
- cursor: pointer;
25
- }
26
-
27
- .instantiation-trace .trace-bar {
28
- background: linear-gradient(to top right, var(--green-400), var(--green-300));
29
- }
30
-
31
- .sequel-trace .trace-bar {
32
- background: linear-gradient(to top right, var(--green-500), var(--green-400));
17
+ margin-right: 3rem;
18
+ list-style: none;
33
19
  }
34
20
 
35
- .controller-trace .trace-bar {
36
- background: linear-gradient(to top right, var(--yellow-500), var(--yellow-400));
21
+ .data-item small {
22
+ color: var(--grey-400);
37
23
  }
38
24
 
39
- .render-template-trace .trace-bar,
40
- .render-partial-trace .trace-bar {
41
- background: linear-gradient(to top right, var(--blue-500), var(--blue-400));
25
+ .data-item span {
26
+ margin: 0.25rem 0;
42
27
  }
43
28
 
44
- .trace-name {
45
- overflow: hidden;
46
- box-sizing: border-box;
47
- padding: 0 0.5em;
48
- margin: 0;
49
- color: var(--grey-400);
50
- font-size: 14px;
51
- text-align: right;
52
- text-overflow: ellipsis;
29
+ [class*='request-status-2'],
30
+ [class*='request-method-get'] {
31
+ background: var(--green-400) !important;
32
+ color: white;
53
33
  }
54
34
 
55
- .trace-payload {
56
- margin: 0;
35
+ [class*='request-status-4'],
36
+ [class*='request-method-put'],
37
+ [class*='request-method-patch'] {
38
+ background: var(--yellow-400) !important;
39
+ color: white;
57
40
  }
58
41
 
59
- .sequel-trace-query {
60
- overflow: auto;
61
- max-height: 100px;
62
- padding: 1em 1em;
63
- background: var(--grey-100);
64
- white-space: pre-wrap;
42
+ [class*='request-status-5'],
43
+ [class*='request-method-delete'] {
44
+ background: var(--red-500) !important;
45
+ color: white;
65
46
  }
66
47
 
67
- .sequel-trace-binds {
68
- overflow: auto;
69
- max-height: 100px;
70
- padding: 0.5em 1em;
71
- margin: 0 0 1em 0;
72
- background: var(--grey-50);
73
- font-size: 12px;
74
- white-space: pre-wrap;
48
+ .trace-list {
49
+ padding: 1rem;
50
+ border: 1px solid var(--grey-200);
51
+ border-radius: 5px;
75
52
  }
76
53
 
77
- .trace-table {
54
+ .trace-details-table {
78
55
  width: 100%;
79
56
  border: hidden 1px var(--border-color);
80
57
  margin-top: 1em;
81
58
  border-collapse: collapse;
82
59
  }
83
60
 
84
- .backtrace {
61
+ .trace-details-table tr th {
62
+ font-weight: var(--fw-semibold);
63
+ }
64
+
65
+ .trace-list-header {
85
66
  display: flex;
86
- flex-direction: row;
87
67
  align-items: center;
88
68
  justify-content: space-between;
89
- padding: 0.5em;
90
- background: var(--grey-100);
69
+ padding-bottom: 1rem;
91
70
  }
92
71
 
93
- .backtrace button {
94
- width: 20px;
95
- height: 20px;
96
- padding: 0;
97
- margin: 0;
98
- background: none;
72
+ .trace-list-filters {
73
+ display: flex;
74
+ width: 60%;
75
+ align-items: center;
76
+ justify-content: space-between;
99
77
  color: var(--grey-500);
100
- transition: color 200ms ease-in-out;
101
- }
102
-
103
- .backtrace button.copied {
104
- color: var(--green-400);
105
- }
106
-
107
- .backtrace button svg {
108
- width: 20px;
109
- height: 20px;
110
78
  }
@@ -5,7 +5,7 @@
5
5
  # Table name: rmp_flamegraphs
6
6
  #
7
7
  # id :integer not null, primary key
8
- # rmp_profiled_request_id :bigint not null
8
+ # rmp_profiled_request_id :integer not null
9
9
  # data :binary
10
10
  # created_at :datetime not null
11
11
  # updated_at :datetime not null
@@ -43,7 +43,7 @@ module RailsMiniProfiler
43
43
  def request=(request)
44
44
  self.request_body = request.body
45
45
  self.request_headers = request.headers
46
- self.request_method = request.method
46
+ self.request_method = request.request_method
47
47
  self.request_path = request.path
48
48
  self.request_query_string = request.query_string
49
49
  end
@@ -5,12 +5,12 @@
5
5
  # Table name: rmp_traces
6
6
  #
7
7
  # id :integer not null, primary key
8
- # rmp_profiled_request_id :bigint not null
8
+ # rmp_profiled_request_id :integer not null
9
9
  # name :string
10
- # start :bigint
11
- # finish :bigint
10
+ # start :integer
11
+ # finish :integer
12
12
  # duration :integer
13
- # allocations :bigint
13
+ # allocations :integer
14
14
  # payload :json
15
15
  # backtrace :json
16
16
  # created_at :datetime not null
@@ -23,24 +23,9 @@
23
23
  module RailsMiniProfiler
24
24
  class Trace < RailsMiniProfiler::ApplicationRecord
25
25
  self.table_name = RailsMiniProfiler.storage_configuration.traces_table
26
- self.inheritance_column = :name
27
26
 
28
27
  belongs_to :profiled_request,
29
28
  class_name: 'RailsMiniProfiler::ProfiledRequest',
30
29
  foreign_key: :rmp_profiled_request_id
31
-
32
- class << self
33
- def find_sti_class(name)
34
- subclasses = {
35
- 'process_action.action_controller' => RailsMiniProfiler::ControllerTrace,
36
- 'sql.active_record' => RailsMiniProfiler::SequelTrace,
37
- 'instantiation.active_record' => RailsMiniProfiler::InstantiationTrace,
38
- 'rails_mini_profiler.total_time' => RailsMiniProfiler::RmpTrace,
39
- 'render_template.action_view' => RailsMiniProfiler::RenderTemplateTrace,
40
- 'render_partial.action_view' => RailsMiniProfiler::RenderPartialTrace
41
- }
42
- subclasses[name] || self
43
- end
44
- end
45
30
  end
46
31
  end
@@ -6,10 +6,18 @@ module RailsMiniProfiler
6
6
  'Action Controller'
7
7
  end
8
8
 
9
- def payload
9
+ def view_runtime
10
+ payload['view_runtime']
11
+ end
12
+
13
+ def db_runtime
14
+ payload['db_runtime']
15
+ end
16
+
17
+ def content
10
18
  content_tag('div') do
11
19
  content_tag('pre', class: 'trace-payload') do
12
- content_tag(:div, "View Time: #{model.view_runtime} ms, DB Time: #{model.db_runtime} ms",
20
+ content_tag(:div, "View Time: #{view_runtime} ms, DB Time: #{db_runtime} ms",
13
21
  class: 'sequel-trace-query')
14
22
  end
15
23
  end
@@ -3,12 +3,24 @@
3
3
  module RailsMiniProfiler
4
4
  class InstantiationTracePresenter < TracePresenter
5
5
  def label
6
- "#{model.class_name} Instantiation"
6
+ "#{class_name} Instantiation"
7
+ end
8
+
9
+ def class_name
10
+ payload['class_name']
11
+ end
12
+
13
+ def record_count
14
+ payload['record_count']
15
+ end
16
+
17
+ def db_runtime
18
+ payload['db_runtime']
7
19
  end
8
20
 
9
21
  def description
10
- record_string = 'Record'.pluralize(model.record_count)
11
- "Instantiated #{model.record_count} #{model.class_name} #{record_string}"
22
+ record_string = 'Record'.pluralize(record_count)
23
+ "Instantiated #{record_count} #{class_name} #{record_string}"
12
24
  end
13
25
  end
14
26
  end
@@ -30,8 +30,8 @@ module RailsMiniProfiler
30
30
 
31
31
  return nil unless model.flamegraph.present?
32
32
 
33
- link_to(flamegraph_path(model.id), title: 'Show Flamegraph', class: 'flamegraph-button') do
34
- content_tag('button', 'Flamegraph')
33
+ link_to(flamegraph_path(model.id), title: 'Show Flamegraph') do
34
+ content_tag('button', 'Flamegraph', class: 'btn-grey')
35
35
  end
36
36
  end
37
37
  end
@@ -2,10 +2,14 @@
2
2
 
3
3
  module RailsMiniProfiler
4
4
  class RenderPartialTracePresenter < TracePresenter
5
+ def identifier
6
+ payload['identifier']
7
+ end
8
+
5
9
  def label
6
10
  root = Rails.root.to_s.split('/').to_set
7
- identifier = model.identifier.split('/').to_set
8
- (root ^ identifier).drop(2).join('/').reverse.truncate(30).reverse
11
+ id = identifier.split('/').to_set
12
+ (root ^ id).drop(2).join('/').reverse.truncate(30).reverse
9
13
  end
10
14
  end
11
15
  end
@@ -2,10 +2,14 @@
2
2
 
3
3
  module RailsMiniProfiler
4
4
  class RenderTemplateTracePresenter < TracePresenter
5
+ def identifier
6
+ payload['identifier']
7
+ end
8
+
5
9
  def label
6
10
  root = Rails.root.to_s.split('/').to_set
7
- identifier = model.identifier.split('/').to_set
8
- (root ^ identifier).drop(2).join('/').reverse.truncate(30).reverse
11
+ id = identifier.split('/').to_set
12
+ (root ^ id).drop(2).join('/').reverse.truncate(30).reverse
9
13
  end
10
14
 
11
15
  def description
@@ -6,14 +6,26 @@ module RailsMiniProfiler
6
6
  sql_description
7
7
  end
8
8
 
9
+ def name
10
+ payload['name']
11
+ end
12
+
13
+ def sql
14
+ payload['sql']
15
+ end
16
+
17
+ def binds
18
+ payload['binds']
19
+ end
20
+
9
21
  alias description label
10
22
 
11
- def payload
23
+ def content
12
24
  return nil if transaction?
13
25
 
14
26
  content_tag('div') do
15
27
  content_tag('pre', class: 'trace-payload') do
16
- content_tag(:div, model.sql, class: 'sequel-trace-query')
28
+ content_tag(:div, sql, class: 'sequel-trace-query')
17
29
  end + binding_content
18
30
  end
19
31
  end
@@ -57,9 +69,9 @@ module RailsMiniProfiler
57
69
  end
58
70
 
59
71
  def simple_binds
60
- return [] if model.binds.nil? || model.binds.empty?
72
+ return [] if binds.nil? || binds.empty?
61
73
 
62
- model.binds.each_with_object({}) do |hash, object|
74
+ binds.each_with_object({}) do |hash, object|
63
75
  name = hash['name']
64
76
  value = hash['value']
65
77
  object[name] = value
@@ -2,9 +2,12 @@
2
2
 
3
3
  module RailsMiniProfiler
4
4
  class TracePresenter < BasePresenter
5
- def initialize(trace, view, profiled_request:)
5
+ def initialize(trace, view, context: {})
6
6
  super(trace, view)
7
- @profiled_request = profiled_request
7
+ @start = context[:start]
8
+ @finish = context[:finish]
9
+ @total_duration = context[:total_duration]
10
+ @total_allocations = context[:total_allocations]
8
11
  end
9
12
 
10
13
  def label
@@ -15,7 +18,7 @@ module RailsMiniProfiler
15
18
  label
16
19
  end
17
20
 
18
- def payload
21
+ def content
19
22
  nil
20
23
  end
21
24
 
@@ -38,7 +41,7 @@ module RailsMiniProfiler
38
41
  end
39
42
 
40
43
  def duration_percent
41
- (model.duration.to_f / @profiled_request.duration * 100).round
44
+ (model.duration.to_f / @total_duration * 100).round
42
45
  end
43
46
 
44
47
  def allocations
@@ -46,16 +49,15 @@ module RailsMiniProfiler
46
49
  end
47
50
 
48
51
  def allocations_percent
49
- (model.allocations.to_f / @profiled_request.allocations * 100).round
52
+ (model.allocations.to_f / @total_allocations * 100).round
50
53
  end
51
54
 
52
55
  def from_start
53
- (model.start - @profiled_request.start).to_f / 100
56
+ (model.start - @start).to_f / 100
54
57
  end
55
58
 
56
59
  def from_start_percent
57
- ((model.start - @profiled_request.start).to_f /
58
- (@profiled_request.finish - @profiled_request.start)).to_f * 100
60
+ ((model.start - @start).to_f / (@finish - @start)).to_f * 100
59
61
  end
60
62
  end
61
63
  end
@@ -27,7 +27,6 @@ module RailsMiniProfiler
27
27
  end
28
28
 
29
29
  option(:duration) do |scope, value|
30
- value = value.tr('>', '').to_i * 100
31
30
  scope.where('duration > :duration', duration: value)
32
31
  end
33
32
  end