rails_performance 0.0.1.1 → 0.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51b705efba63ca09c41d8d2bae1ca38a24ac5b61d02ebf04900b32e4741b6715
4
- data.tar.gz: 738cf597eebf005575d85c9054ea1cbb75d61d60a814ad53c12d782b053b4388
3
+ metadata.gz: 68f35c4eec4521b60ad740040da1a980e517f951444f52563dedf1f9e5958c8a
4
+ data.tar.gz: 0b384d8bda35a86b7fbc384b2834829eb2f8bd92edf01d974bd75d139748f749
5
5
  SHA512:
6
- metadata.gz: a37ee64f11e1670baef0eeeb42ab5d926851f29351a027cecdfcc1ef618f603fd08456e1aaeaae0262179b79a930fe6bbbd5a04995bda83dcdfb0a56b7e2e3f8
7
- data.tar.gz: c2fdee215cef0eb8f070c9249f1d4ffc518ae069d96128bb65e7414dbf4888204d48a6b50a5836919efc7ec98337ee81c20e99f45693670c2e59a9cca65d00ba
6
+ metadata.gz: ad282e2024c5eadf23eade5c6b02dc31255f8bd1fe34b9b03c2557f5a5d2a1ab640f9b23d13d2e2c0dbf081b6fd4cec2b6ac34bacf6e722e81b8c2de69b5c321
7
+ data.tar.gz: 3ef27d25873473bfd87369356ecbd28d57471ce27240513f01d0a546c80ab8790c983b0ad9e9ecc61bddfe0b9c9a64dad8dd274981890dd2e34e69b697724664
@@ -8,7 +8,7 @@ class RailsPerformanceController < ActionController::Base
8
8
  })
9
9
 
10
10
  @data = RailsPerformance::ThroughputReport.new(@datasource.db).data
11
- @global = RailsPerformance::RequestsReport.new(@datasource.db, group: :controller_action_format).data
11
+ @global = RailsPerformance::RequestsReport.new(@datasource.db, group: :controller_action_format, sort: :db_runtime_slowest).data
12
12
  #@full = RailsPerformance::FullReport.new.data(:controller_action).sort{|a, b| b[:count] <=> a[:count]}
13
13
  end
14
14
 
@@ -0,0 +1,8 @@
1
+ module RailsPerformanceHelper
2
+ def round_it(value)
3
+ return nil unless value
4
+ return value if value.is_a?(Integer)
5
+
6
+ value.nan? ? nil : value.round(2)
7
+ end
8
+ end
@@ -19,7 +19,7 @@
19
19
 
20
20
  #chart {
21
21
  width: 100%;
22
- min-height: 600px;
22
+ min-height: 500px;
23
23
  }
24
24
 
25
25
  .card {
@@ -21,11 +21,20 @@
21
21
  <table>
22
22
  <thead>
23
23
  <tr>
24
- <th></th>
24
+ <th colspan='3'>Name</th>
25
+ <th colspan='3'>Average (ms)</th>
26
+ <th colspan='3'>Slowest (ms)</th>
27
+ </tr>
28
+ <tr>
29
+ <th>Controller#Action</th>
25
30
  <th>Format</th>
26
31
  <th>Requests</th>
27
- <th>Average (ms)</th>
28
- <th>Slowest (ms)</th>
32
+ <th>Duration</th>
33
+ <th>Views</th>
34
+ <th>DB</th>
35
+ <th>Duration</th>
36
+ <th>Views</th>
37
+ <th>DB</th>
29
38
  </tr>
30
39
  </thead>
31
40
  <tbody>
@@ -35,8 +44,12 @@
35
44
  <td><%= groups[0] %></td>
36
45
  <td><%= groups[1]&.upcase %></td>
37
46
  <td><%= e[:count] %></td>
38
- <td><%= e[:average].round(2) %></td>
39
- <td><%= e[:slowest].round(2) %></td>
47
+ <td><%= round_it e[:duration_average] %></td>
48
+ <td><%= round_it e[:view_runtime_average] %></td>
49
+ <td><%= round_it e[:db_runtime_average] %></td>
50
+ <td><%= round_it e[:duration_slowest] %></td>
51
+ <td><%= round_it e[:view_runtime_slowest] %></td>
52
+ <td><%= round_it e[:db_runtime_slowest] %></td>
40
53
  </tr>
41
54
  <% end %>
42
55
  </tbody>
@@ -1,10 +1,13 @@
1
1
  module RailsPerformance
2
2
  class BaseReport
3
- attr_reader :db, :group
3
+ attr_reader :db, :group, :sort
4
4
 
5
- def initialize(db, group: nil)
5
+ def initialize(db, group: nil, sort: nil)
6
6
  @db = db
7
7
  @group = group
8
+ @sort = sort
9
+
10
+ set_defaults
8
11
  end
9
12
 
10
13
  def collect
@@ -13,5 +16,8 @@ module RailsPerformance
13
16
  res
14
17
  end
15
18
  end
19
+
20
+ def set_defaults
21
+ end
16
22
  end
17
23
  end
@@ -15,5 +15,11 @@ module RailsPerformance
15
15
  )
16
16
  end
17
17
 
18
+ # initializer 'rails_performance.helpers' do
19
+ # ActiveSupport.on_load :action_view do
20
+ # ActionView::Base.send :include, RailsPerformance::RailsPerformanceHelper
21
+ # end
22
+ # end
23
+
18
24
  end
19
25
  end
@@ -19,6 +19,8 @@ module RailsPerformance
19
19
  def call(event_name, started, finished, event_id, payload)
20
20
  event = ActiveSupport::Notifications::Event.new(event_name, started, finished, event_id, payload)
21
21
 
22
+ #finished = Time.now - rand(180).minutes
23
+
22
24
  record = {
23
25
  controller: event.payload[:controller],
24
26
  action: event.payload[:action],
@@ -1,14 +1,26 @@
1
1
  module RailsPerformance
2
2
  class RequestsReport < BaseReport
3
+ def set_defaults
4
+ @sort ||= :count
5
+ end
6
+
3
7
  def data
4
8
  collect do |k, v|
9
+ durations = v.collect{|e| e["duration"]}.compact
10
+ view_runtimes = v.collect{|e| e["view_runtime"]}.compact
11
+ db_runtimes = v.collect{|e| e["db_runtime"]}.compact
12
+
5
13
  {
6
- group: k,
7
- average: v.sum{|e| e["duration"]}.to_f / v.size,
8
- count: v.size,
9
- slowest: v.max_by{|e| e["duration"]}.try(:[], "duration")
14
+ group: k,
15
+ count: v.size,
16
+ duration_average: durations.sum.to_f / durations.size,
17
+ view_runtime_average: view_runtimes.sum.to_f / view_runtimes.size,
18
+ db_runtime_average: db_runtimes.sum.to_f / db_runtimes.size,
19
+ duration_slowest: durations.max,
20
+ view_runtime_slowest: view_runtimes.max,
21
+ db_runtime_slowest: db_runtimes.max,
10
22
  }
11
- end.sort{|a, b| b[:count] <=> a[:count]}
23
+ end.sort{|a, b| b[sort] <=> a[sort]}
12
24
  end
13
25
  end
14
26
  end
@@ -1,8 +1,8 @@
1
1
  module RailsPerformance
2
2
  class ThroughputReport < BaseReport
3
3
 
4
- def initialize(ds)
5
- super(ds, group: :datetime)
4
+ def set_defaults
5
+ @group ||= :datetime
6
6
  end
7
7
 
8
8
  def data
@@ -1,3 +1,3 @@
1
1
  module RailsPerformance
2
- VERSION = '0.0.1.1'
2
+ VERSION = '0.0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.1
4
+ version: 0.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-24 00:00:00.000000000 Z
11
+ date: 2020-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -92,6 +92,7 @@ files:
92
92
  - Rakefile
93
93
  - app/assets/config/rails_performance_manifest.js
94
94
  - app/controllers/rails_performance_controller.rb
95
+ - app/helpers/rails_performance_helper.rb
95
96
  - app/views/rails_performance/_css.html.erb
96
97
  - app/views/rails_performance/_js.html.erb
97
98
  - app/views/rails_performance/index.html.erb