rails_performance 1.2.0.alpha3 → 1.2.0.alpha5

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: c4cc5606eeacc1d036f322a9eda07cea2d2151c23ad96052f2e7a695ea288e5a
4
- data.tar.gz: 51fe7e76287eb361e0d2135039f4f95c03f559ca575bae8883b1a94c107762e2
3
+ metadata.gz: 62aee36c96f068b8caf8a8f9ba1eb7b0c00f8c6493a8f609f0adaca7e0c11f9b
4
+ data.tar.gz: b61d9ade77df9d29364694937e28fa57a029b497dc327872dc435006d412a136
5
5
  SHA512:
6
- metadata.gz: fc80d1c5713b87b6338778086bc6b4180f36bfd9d38b96753bf92e733f985fa9101ea53c8a426a0cf41c1916dc83266d7f53868b2ceaf6aa4c7c7be11f3ab158
7
- data.tar.gz: 8a54a10c63673d143fe07cfddf03db2000d6f957b3d913edfebf5f0c06f598c5808732dedbb0e3b37e4b280cd00f21b5ba21dbe36248103c5f930015870e81f9
6
+ metadata.gz: cb30056a19056d5b18c6f59af939e22bb4dda67adc0afb08d71ff4b215f4abac53bdd916e359e3655fa2e264be89d1b54af4dd8780bbfd1076e1b9d426c8d50a
7
+ data.tar.gz: f4806fa7db15d691a9ecc95597b7d262ad28a739840ccfe949bf8815a1ac83dfa411a26cc13bb7343009b878f30a250ae9a43fc004b04253e3cb437f6f40aac1
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M21.928 11.607c-.202-.488-.635-.605-.928-.633V8c0-1.103-.897-2-2-2h-6V4.61c.305-.274.5-.668.5-1.11a1.5 1.5 0 0 0-3 0c0 .442.195.836.5 1.11V6H5c-1.103 0-2 .897-2 2v2.997l-.082.006A1 1 0 0 0 1.99 12v2a1 1 0 0 0 1 1H3v5c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5a1 1 0 0 0 1-1v-1.938a1.006 1.006 0 0 0-.072-.455zM5 20V8h14l.001 3.996L19 12v2l.001.005.001 5.995H5z"/><ellipse cx="8.5" cy="12" rx="1.5" ry="2"/><ellipse cx="15.5" cy="12" rx="1.5" ry="2"/><path d="M8 16h8v2H8z"/></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2A10.13 10.13 0 0 0 2 12a10 10 0 0 0 4 7.92V20h.1a9.7 9.7 0 0 0 11.8 0h.1v-.08A10 10 0 0 0 22 12 10.13 10.13 0 0 0 12 2zM8.07 18.93A3 3 0 0 1 11 16.57h2a3 3 0 0 1 2.93 2.36 7.75 7.75 0 0 1-7.86 0zm9.54-1.29A5 5 0 0 0 13 14.57h-2a5 5 0 0 0-4.61 3.07A8 8 0 0 1 4 12a8.1 8.1 0 0 1 8-8 8.1 8.1 0 0 1 8 8 8 8 0 0 1-2.39 5.64z"/><path d="M12 6a3.91 3.91 0 0 0-4 4 3.91 3.91 0 0 0 4 4 3.91 3.91 0 0 0 4-4 3.91 3.91 0 0 0-4-4zm0 6a1.91 1.91 0 0 1-2-2 1.91 1.91 0 0 1 2-2 1.91 1.91 0 0 1 2 2 1.91 1.91 0 0 1-2 2z"/></svg>
@@ -55,6 +55,25 @@ module RailsPerformance
55
55
  db = @datasource.db
56
56
  @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data(params[:from_timei])
57
57
 
58
+ # example
59
+ # :controller=>"HomeController",
60
+ # :action=>"index",
61
+ # :format=>"html",
62
+ # :status=>"200",
63
+ # :method=>"GET",
64
+ # :path=>"/",
65
+ # :request_id=>"9c9bff5f792a5b3f77cb07fa325f8ddf",
66
+ # :datetime=>2023-06-24 21:22:46 +0300,
67
+ # :datetimei=>1687630966,
68
+ # :duration=>207.225830078125,
69
+ # :db_runtime=>2.055999994277954,
70
+ # :view_runtime=>67.8370000096038,
71
+ # :exception=>nil,
72
+ # :backtrace=>nil,
73
+ # :http_referer=>nil,
74
+ # "email"=>nil,
75
+ # "user_agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}]
76
+
58
77
  respond_to do |page|
59
78
  page.html
60
79
  page.js
@@ -92,9 +92,31 @@ module RailsPerformance
92
92
  end
93
93
  end
94
94
 
95
+ def bot_icon(user_agent)
96
+ return nil if user_agent.blank?
97
+
98
+ # TODO: clean this up
99
+ # user_agent = "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
100
+
101
+ browser = Browser.new(user_agent)
102
+
103
+ if browser.bot?
104
+ content_tag(:span, class: "user-agent-icon", title: browser.bot&.name) do
105
+ icon("bot")
106
+ end
107
+ else
108
+ content_tag(:span, class: "user-agent-icon user-agent-icon-user") do
109
+ icon("user")
110
+ end
111
+ end
112
+ end
113
+
95
114
  def icon(name)
96
- # https://www.iconfinder.com/iconsets/vivid
97
- raw File.read(File.expand_path(File.dirname(__FILE__) + "/../../assets/images/#{name}.svg"))
115
+ @icons ||= {}
116
+ @icons[name] ||= begin
117
+ # https://www.iconfinder.com/iconsets/vivid
118
+ raw File.read(File.expand_path(File.dirname(__FILE__) + "/../../assets/images/#{name}.svg"))
119
+ end
98
120
  end
99
121
 
100
122
  def insert_css_file(file)
@@ -7,6 +7,7 @@
7
7
  <% end %>
8
8
  </td>
9
9
  <td><%= format_datetime e[:datetime] %></td>
10
+ <td><%= bot_icon e["user_agent"] %></td>
10
11
  <td>
11
12
  <% controller_action_info = e[:controller] + '#' + e[:action]%>
12
13
  <%= link_to truncate(controller_action_info, length: 40), rails_performance.rails_performance_summary_path({controller_eq: e[:controller], action_eq: e[:action]}), remote: true, title: controller_action_info %>
@@ -30,4 +30,4 @@
30
30
  var data2 = <%= raw @response_time_report_data.to_json %>;
31
31
  showRTChart('response_time_report_chart', data2);
32
32
  </script>
33
- <% end %>
33
+ <% end %>
@@ -19,6 +19,7 @@
19
19
  <tr>
20
20
  <th data-sort="string"></th>
21
21
  <th data-sort="string">Datetime</th>
22
+ <th></th>
22
23
  <th data-sort="string">Controller#action</th>
23
24
  <th data-sort="string">Method</th>
24
25
  <th data-sort="string">Format</th>
@@ -13,6 +13,7 @@
13
13
  <tr>
14
14
  <th data-sort="string"></th>
15
15
  <th data-sort="string">Datetime</th>
16
+ <th></th>
16
17
  <th data-sort="string">Controller#action</th>
17
18
  <th data-sort="string">Method</th>
18
19
  <th data-sort="string">Format</th>
@@ -56,6 +56,15 @@
56
56
  height: 24px;
57
57
  }
58
58
 
59
+ .user-agent-icon svg {
60
+ width: 12px;
61
+ height: 12px;
62
+ }
63
+
64
+ .user-agent-icon-user svg path {
65
+ fill: hsl(141, 53%, 53%) !important;
66
+ }
67
+
59
68
  .chart {
60
69
  height: 245px;
61
70
  }
@@ -21,7 +21,7 @@ module RailsPerformance
21
21
  def db
22
22
  result = RailsPerformance::Models::Collection.new
23
23
  (0..(RailsPerformance::Utils.days + 1)).to_a.reverse.each do |e|
24
- RailsPerformance::DataSource.new(q: self.q.merge({ on: (Time.now - e.days).to_date }), type: type).add_to(result)
24
+ RailsPerformance::DataSource.new(q: self.q.merge({ on: (Time.current - e.days).to_date }), type: type).add_to(result)
25
25
  end
26
26
  result
27
27
  end
@@ -7,7 +7,7 @@ module RailsPerformance
7
7
  return yield unless RailsPerformance.enabled
8
8
 
9
9
  begin
10
- now = Time.now
10
+ now = Time.current
11
11
  status = 'success'
12
12
  result = yield
13
13
  result
@@ -19,7 +19,7 @@ module RailsPerformance
19
19
  tag_name: tag_name,
20
20
  namespace_name: namespace_name,
21
21
  status: status,
22
- duration: (Time.now - now) * 1000,
22
+ duration: (Time.current - now) * 1000,
23
23
  datetime: now.strftime(RailsPerformance::FORMAT),
24
24
  datetimei: now.to_i,
25
25
  ).save
@@ -6,7 +6,7 @@ module RailsPerformance
6
6
  callbacks do |lifecycle|
7
7
  lifecycle.around(:invoke_job) do |job, *args, &block|
8
8
  begin
9
- now = Time.now
9
+ now = Time.current
10
10
  block.call(job, *args)
11
11
  status = 'success'
12
12
  rescue Exception => error
@@ -16,7 +16,7 @@ module RailsPerformance
16
16
  meta_data = RailsPerformance::Gems::DelayedJobExt::Plugin.meta(job.payload_object)
17
17
  record = RailsPerformance::Models::DelayedJobRecord.new(
18
18
  jid: job.id,
19
- duration: (Time.now - now) * 1000,
19
+ duration: (Time.current - now) * 1000,
20
20
  datetime: now.strftime(RailsPerformance::FORMAT),
21
21
  datetimei: now.to_i,
22
22
  source_type: meta_data[0],
@@ -7,7 +7,7 @@ module RailsPerformance
7
7
  # TODO change to set
8
8
  CurrentRequest.current.ignore.add(:performance)
9
9
 
10
- now = Time.now
10
+ now = Time.current
11
11
  CurrentRequest.current.data ||= {}
12
12
  CurrentRequest.current.record ||= RailsPerformance::Models::GrapeRecord.new(request_id: CurrentRequest.current.request_id)
13
13
  CurrentRequest.current.record.datetimei ||= now.to_i
@@ -6,7 +6,7 @@ module RailsPerformance
6
6
  ::Rake::Task.class_eval do
7
7
  def invoke_with_rails_performance(*args)
8
8
  begin
9
- now = Time.now
9
+ now = Time.current
10
10
  status = 'success'
11
11
  invoke_without_new_rails_performance(*args)
12
12
  rescue Exception => ex
@@ -18,7 +18,7 @@ module RailsPerformance
18
18
  task: RailsPerformance::Gems::RakeExt.find_task_name(*args),
19
19
  datetime: now.strftime(RailsPerformance::FORMAT),
20
20
  datetimei: now.to_i,
21
- duration: (Time.now - now) * 1000,
21
+ duration: (Time.current - now) * 1000,
22
22
  status: status,
23
23
  ).save
24
24
  end
@@ -6,7 +6,7 @@ module RailsPerformance
6
6
  end
7
7
 
8
8
  def call(worker, msg, queue)
9
- now = Time.now
9
+ now = Time.current
10
10
  record = RailsPerformance::Models::SidekiqRecord.new(
11
11
  enqueued_ati: msg['enqueued_at'].to_i,
12
12
  datetimei: msg['created_at'].to_i,
@@ -26,7 +26,7 @@ module RailsPerformance
26
26
  raise ex
27
27
  ensure
28
28
  # store in ms instead of seconds
29
- record.duration = (Time.now - now) * 1000
29
+ record.duration = (Time.current - now) * 1000
30
30
  record.save
31
31
  result
32
32
  end
@@ -41,7 +41,7 @@ module RailsPerformance
41
41
  def call!(env)
42
42
  @status, @headers, @response = @app.call(env)
43
43
 
44
- #t = Time.now
44
+ #t = Time.current
45
45
  if !RailsPerformance.skip
46
46
  if !CurrentRequest.current.ignore.include?(:performance) # grape is executed first, and than ignore regular future storage of "controller"-like request
47
47
  if data = CurrentRequest.current.data
@@ -66,7 +66,7 @@ module RailsPerformance
66
66
  end
67
67
  end
68
68
  end
69
- #puts "==> store performance data: #{(Time.now - t).round(3)}ms"
69
+ #puts "==> store performance data: #{(Time.current - t).round(3)}ms"
70
70
 
71
71
  [@status, @headers, @response]
72
72
  end
@@ -29,6 +29,42 @@ module RailsPerformance
29
29
  time
30
30
  end
31
31
  end
32
+
33
+ def calculate_data
34
+ now = Time.current
35
+ stop = Time.at(60 * ((now.to_i)/ 60))
36
+ offset = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(now).utc_offset
37
+ current = stop - RailsPerformance.duration
38
+
39
+ @data = []
40
+ all = {}
41
+
42
+ # puts "current: #{current}"
43
+ # puts "stop: #{stop}"
44
+
45
+ # read current values
46
+ db.group_by(group).each do |(k, v)|
47
+ yield(all, k, v)
48
+ end
49
+
50
+ # puts '----'
51
+ # puts all
52
+ # puts '----'
53
+ # puts "offset: #{offset}"
54
+ # puts '======='
55
+
56
+ # add blank columns
57
+ while current <= stop
58
+ key = (current).strftime(RailsPerformance::FORMAT)
59
+ views = all[key].presence || 0
60
+ # puts "#{key} -> #{views}"
61
+ @data << [(current.to_i + offset) * 1000, views.round(2)]
62
+ current += 1.minute
63
+ end
64
+
65
+ # sort by time
66
+ @data.sort!
67
+ end
32
68
  end
33
69
  end
34
70
  end
@@ -6,32 +6,11 @@ module RailsPerformance
6
6
  end
7
7
 
8
8
  def data
9
- all = {}
10
- stop = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.at(60 * (Time.now.to_i / 60)))
11
- offset = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.now).utc_offset
12
- current = stop - RailsPerformance.duration
13
- @data = []
14
-
15
- # puts "current: #{current}"
16
- # puts "stop: #{stop}"
17
-
18
- # read current values
19
- db.group_by(group).each do |(k, v)|
9
+ calculate_data do |all, k, v|
20
10
  durations = v.collect{|e| e["duration"]}.compact
21
11
  next if durations.empty?
22
12
  all[k] = durations.sum.to_f / durations.count
23
13
  end
24
-
25
- # add blank columns
26
- while current <= stop
27
- views = all[current.strftime(RailsPerformance::FORMAT)] || 0
28
- # time = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(current)
29
- @data << [(current.to_i + offset) * 1000, views.round(2)]
30
- current += 1.minute
31
- end
32
-
33
- # sort by time
34
- @data.sort!
35
14
  end
36
15
  end
37
16
  end
@@ -6,33 +6,18 @@ module RailsPerformance
6
6
  @group ||= :datetime
7
7
  end
8
8
 
9
+ # def prepare_query(query = {})
10
+ # RailsPerformance::Rails::QueryBuilder.compose_from({})
11
+ # end
12
+ # @datasource = RailsPerformance::DataSource.new(**prepare_query({}), type: :requests)
13
+ # db = @datasource.db
9
14
  # RailsPerformance::Reports::ThroughputReport.new(db).data
10
15
  # Time.at(RailsPerformance::Reports::ThroughputReport.new(db).data.last[0] / 1000)
11
16
 
12
17
  def data
13
- all = {}
14
- stop = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.at(60 * (Time.now.to_i / 60)))
15
- offset = RailsPerformance::Reports::BaseReport::time_in_app_time_zone(Time.now).utc_offset
16
- current = stop - RailsPerformance.duration
17
- @data = []
18
-
19
- # puts "current: #{current}"
20
- # puts "stop: #{stop}"
21
-
22
- # read current values
23
- db.group_by(group).each do |(k, v)|
18
+ calculate_data do |all, k, v|
24
19
  all[k] = v.count
25
20
  end
26
-
27
- # add blank columns
28
- while current <= stop
29
- views = all[current.strftime(RailsPerformance::FORMAT)] || 0
30
- @data << [(current.to_i + offset) * 1000, views.round(2)]
31
- current += 1.minute
32
- end
33
-
34
- # sort by time
35
- @data.sort!
36
21
  end
37
22
 
38
23
  end
@@ -27,7 +27,7 @@ module RailsPerformance
27
27
  end
28
28
 
29
29
  def trace(options = {})
30
- @tracings << options.merge(time: Time.now.to_i)
30
+ @tracings << options.merge(time: Time.current.to_i)
31
31
  end
32
32
 
33
33
  end
@@ -8,7 +8,7 @@ module RailsPerformance
8
8
 
9
9
  # write to current slot
10
10
  # time - date -minute
11
- def Utils.field_key(now = Time.now)
11
+ def Utils.field_key(now = Time.current)
12
12
  now.strftime("%H:%M")
13
13
  end
14
14
 
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = '1.2.0.alpha3'
2
+ VERSION = '1.2.0.alpha5'
3
3
  SCHEMA = '1.0.1'
4
4
  end
@@ -1,5 +1,6 @@
1
1
  require "redis"
2
2
  require "redis-namespace"
3
+ require "browser"
3
4
  require_relative "./rails_performance/version.rb"
4
5
  require_relative "rails_performance/rails/query_builder.rb"
5
6
  require_relative "rails_performance/rails/middleware.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.alpha3
4
+ version: 1.2.0.alpha5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: browser
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: sqlite3
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +233,7 @@ files:
219
233
  - Rakefile
220
234
  - app/assets/config/rails_performance_manifest.js
221
235
  - app/assets/images/activity.svg
236
+ - app/assets/images/bot.svg
222
237
  - app/assets/images/close.svg
223
238
  - app/assets/images/export.svg
224
239
  - app/assets/images/git.svg
@@ -227,6 +242,7 @@ files:
227
242
  - app/assets/images/import.svg
228
243
  - app/assets/images/menu.svg
229
244
  - app/assets/images/stat.svg
245
+ - app/assets/images/user.svg
230
246
  - app/controllers/rails_performance/base_controller.rb
231
247
  - app/controllers/rails_performance/rails_performance_controller.rb
232
248
  - app/helpers/rails_performance/application_helper.rb