rails_performance 0.0.1.4 → 0.0.1.5

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.
@@ -1,18 +1,19 @@
1
1
  module RailsPerformance
2
2
  module Reports
3
3
  class BaseReport
4
- attr_reader :db, :group, :sort
4
+ attr_reader :db, :group, :sort, :title
5
5
 
6
- def initialize(db, group: nil, sort: nil)
6
+ def initialize(db, group: nil, sort: nil, title: nil)
7
7
  @db = db
8
8
  @group = group
9
9
  @sort = sort
10
+ @title = title
10
11
 
11
12
  set_defaults
12
13
  end
13
14
 
14
15
  def collect
15
- db.group_by(group).values.inject([]) do |res, (k,v)|
16
+ db.group_by(group).inject([]) do |res, (k,v)|
16
17
  res << yield(k, v)
17
18
  res
18
19
  end
@@ -0,0 +1,28 @@
1
+ module RailsPerformance
2
+ module Reports
3
+ class BreakdownReport < BaseReport
4
+ def set_defaults
5
+ @sort ||= :datetime
6
+ end
7
+
8
+ def data
9
+ db.data.collect do |record|
10
+ {
11
+ controller: record.controller,
12
+ action: record.action,
13
+ format: record.format,
14
+ status: record.status,
15
+ method: record.method,
16
+ path: record.path,
17
+ datetime: Time.parse(record.datetime),
18
+ duration: record.value['duration'],
19
+ db_runtime: record.value['db_runtime'],
20
+ view_runtime: record.value['view_runtime'],
21
+ }
22
+ end.sort{|a, b| b[sort] <=> a[sort]}
23
+ end
24
+ end
25
+
26
+
27
+ end
28
+ end
@@ -10,7 +10,6 @@ module RailsPerformance
10
10
  durations = v.collect{|e| e["duration"]}.compact
11
11
  view_runtimes = v.collect{|e| e["view_runtime"]}.compact
12
12
  db_runtimes = v.collect{|e| e["db_runtime"]}.compact
13
-
14
13
  {
15
14
  group: k,
16
15
  count: v.size,
@@ -16,7 +16,7 @@ module RailsPerformance
16
16
  # puts "stop: #{stop}"
17
17
 
18
18
  # read current values
19
- db.group_by(group).values.each do |(k, v)|
19
+ db.group_by(group).each do |(k, v)|
20
20
  durations = v.collect{|e| e["duration"]}.compact
21
21
  next if durations.empty?
22
22
  all[k] = durations.sum.to_f / durations.count
@@ -17,7 +17,7 @@ module RailsPerformance
17
17
  # puts "stop: #{stop}"
18
18
 
19
19
  # read current values
20
- db.group_by(group).values.each do |(k, v)|
20
+ db.group_by(group).each do |(k, v)|
21
21
  all[k] = v.count
22
22
  end
23
23
 
@@ -1,3 +1,3 @@
1
1
  module RailsPerformance
2
- VERSION = '0.0.1.4'
2
+ VERSION = '0.0.1.5'
3
3
  end
@@ -3,12 +3,13 @@ require "redis-namespace"
3
3
  require_relative "rails_performance/query_builder.rb"
4
4
  require_relative "rails_performance/middleware.rb"
5
5
  require_relative "rails_performance/data_source.rb"
6
- require_relative "rails_performance/record.rb"
6
+ require_relative "rails_performance/models/record.rb"
7
7
  require_relative "rails_performance/utils.rb"
8
8
  require_relative "rails_performance/reports/base_report.rb"
9
9
  require_relative "rails_performance/reports/requests_report.rb"
10
10
  require_relative "rails_performance/reports/response_time_report.rb"
11
11
  require_relative "rails_performance/reports/throughput_report.rb"
12
+ require_relative "rails_performance/reports/breakdown_report.rb"
12
13
 
13
14
  require "rails_performance/engine"
14
15
 
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.4
4
+ version: 0.0.1.5
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-26 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -93,19 +93,25 @@ files:
93
93
  - app/assets/config/rails_performance_manifest.js
94
94
  - app/controllers/rails_performance_controller.rb
95
95
  - app/helpers/rails_performance_helper.rb
96
- - app/views/rails_performance/_css.html.erb
97
- - app/views/rails_performance/_js.html.erb
96
+ - app/views/javascripts/_javascripts.html.erb
97
+ - app/views/javascripts/app.js
98
+ - app/views/layouts/rails_performance.html.erb
99
+ - app/views/rails_performance/breakdown.html.erb
98
100
  - app/views/rails_performance/index.html.erb
101
+ - app/views/stylesheets/_stylesheets.html.erb
102
+ - app/views/stylesheets/bulma.min.css
103
+ - app/views/stylesheets/style.css
99
104
  - config/routes.rb
100
105
  - lib/rails_performance.rb
101
- - lib/rails_performance/collection.rb
102
106
  - lib/rails_performance/data_source.rb
103
107
  - lib/rails_performance/engine.rb
104
108
  - lib/rails_performance/metrics_collector.rb
105
109
  - lib/rails_performance/middleware.rb
110
+ - lib/rails_performance/models/collection.rb
111
+ - lib/rails_performance/models/record.rb
106
112
  - lib/rails_performance/query_builder.rb
107
- - lib/rails_performance/record.rb
108
113
  - lib/rails_performance/reports/base_report.rb
114
+ - lib/rails_performance/reports/breakdown_report.rb
109
115
  - lib/rails_performance/reports/requests_report.rb
110
116
  - lib/rails_performance/reports/response_time_report.rb
111
117
  - lib/rails_performance/reports/throughput_report.rb
@@ -1,114 +0,0 @@
1
- <link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
2
-
3
- <style>
4
- body {
5
- font-family: OpenSans, sans-serif;
6
- margin: 0;
7
- font-size: .8125rem;
8
- font-weight: 400;
9
- line-height: 1.5;
10
- color: #a6b0cf;
11
- text-align: left;
12
- background-color: #282e38;
13
- background: linear-gradient(45deg, #282e38, #382e38);
14
- display: flex;
15
- width: 100%;
16
- flex-direction: column;
17
- align-items: center;
18
- }
19
-
20
- #chart {
21
- width: 100%;
22
- min-height: 500px;
23
- }
24
-
25
- .card {
26
- min-width: 90%;
27
- padding: 1em 2em;
28
- background-color: #323a46;
29
- background-clip: border-box;
30
- border: 0 solid #32394e;
31
- border-radius: .25rem;
32
- box-shadow: 0 0.75rem 6rem rgba(56,65,74,.03);
33
- }
34
-
35
- h1 {
36
- text-align: center;
37
- color: #f6f6f6;
38
- font-size: 14px;
39
- margin: 0 0 7px 0;
40
- padding-top: 14px;
41
- padding-bottom: 14px;
42
- }
43
-
44
- p.hint {
45
- font-size: 10px;
46
- text-align: center;
47
- color: #aaa;
48
- }
49
-
50
- table {
51
- border-collapse: collapse;
52
- border-radius: 10px;
53
- overflow: hidden;
54
- width: 100%;
55
- margin: 0 auto;
56
- position: relative;
57
- border-spacing: 1;
58
- }
59
- table * {
60
- position: relative;
61
- }
62
- table td, table th {
63
- padding-left: 8px;
64
- }
65
- table thead tr {
66
- height: 60px;
67
- }
68
- table tbody tr {
69
- height: 50px;
70
- }
71
- table tbody tr:last-child {
72
- border: 0;
73
- }
74
- table td, table th {
75
- text-align: left;
76
- }
77
- table td.l, table th.l {
78
- text-align: right;
79
- }
80
- table td.c, table th.c {
81
- text-align: center;
82
- }
83
- table td.r, table th.r {
84
- text-align: center;
85
- }
86
-
87
- th {
88
- font-size: 18px;
89
- color: #f5f5f5;
90
- line-height: 1.2;
91
- font-weight: unset;
92
- }
93
-
94
- tbody tr {
95
- font-size: 15px;
96
- color: #f5f5f5;
97
- line-height: 1.2;
98
- font-weight: unset;
99
- }
100
-
101
- tbody tr:hover {
102
- color: white;
103
- background-color: #282e38;
104
- }
105
- table a {
106
- color: white;
107
- }
108
-
109
- .back_link {
110
- color: white;
111
- font-size: 20px;
112
- }
113
-
114
- </style>
@@ -1,138 +0,0 @@
1
- <%= javascript_include_tag 'https://code.highcharts.com/highcharts.js' %>
2
- <%= javascript_include_tag 'https://code.highcharts.com/modules/data.js' %>
3
- <%= javascript_include_tag 'https://code.highcharts.com/modules/exporting.js' %>
4
- <%= javascript_include_tag 'https://code.highcharts.com/modules/export-data.js' %>
5
- <%= javascript_include_tag 'https://code.highcharts.com/modules/accessibility.js' %>
6
-
7
- <script>
8
- function showTIRChart(div, data) {
9
- Highcharts.chart(div, {
10
- time: {
11
- timezone: 'Europe/Kiev'
12
- },
13
- chart: {
14
- type: 'column',
15
- zoomType: 'x',
16
- backgroundColor: '#323a46'
17
- },
18
- title: {
19
- text: ''
20
- },
21
- xAxis: {
22
- type: 'datetime',
23
- labels: {
24
- style: {
25
- color: "#a6b0cf"
26
- }
27
- }
28
- },
29
- yAxis: {
30
- min: 0,
31
- title: {
32
- text: 'RPM',
33
- style: {
34
- color: "#f6f6f6"
35
- }
36
- },
37
- labels: {
38
- style: {
39
- color: "#a6b0cf"
40
- }
41
- }
42
- },
43
- legend: {
44
- enabled: false
45
- },
46
- exporting: {
47
- buttons: {
48
- contextButton: {
49
- theme: {
50
- fill: "#a6b0cf"
51
- }
52
- }
53
- }
54
- },
55
- plotOptions: {
56
- column: {
57
- color: '#ff5b5b',
58
- borderColor: '#ff5b5b',
59
- }
60
- },
61
- series: [{
62
- type: 'column',
63
- name: 'Requests per minute',
64
- data: data
65
- }]
66
- });
67
- };
68
-
69
- function showRTChart(div, data) {
70
- Highcharts.chart(div, {
71
- time: {
72
- timezone: 'Europe/Kiev'
73
- },
74
- chart: {
75
- type: 'area',
76
- zoomType: 'x',
77
- backgroundColor: '#323a46'
78
- },
79
- title: {
80
- text: ''
81
- },
82
- tooltip: {
83
- formatter: function() {
84
- if (this.y == 0) {
85
- return null;
86
- }
87
-
88
- return this.y + ' ms';
89
- }
90
- },
91
- xAxis: {
92
- type: 'datetime',
93
- labels: {
94
- style: {
95
- color: "#a6b0cf"
96
- }
97
- }
98
- },
99
- yAxis: {
100
- min: 0,
101
- title: {
102
- text: 'Time',
103
- style: {
104
- color: "#f6f6f6"
105
- }
106
- },
107
- labels: {
108
- style: {
109
- color: "#a6b0cf"
110
- }
111
- }
112
- },
113
- legend: {
114
- enabled: false
115
- },
116
- exporting: {
117
- buttons: {
118
- contextButton: {
119
- theme: {
120
- fill: "#a6b0cf"
121
- }
122
- }
123
- }
124
- },
125
- plotOptions: {
126
- area: {
127
- color: '#ff5b5b',
128
- borderColor: '#ff5b5b',
129
- }
130
- },
131
- series: [{
132
- type: 'area',
133
- name: 'Response Time',
134
- data: data
135
- }]
136
- });
137
- };
138
- </script>
@@ -1,36 +0,0 @@
1
- module RailsPerformance
2
- class Collection
3
- attr_reader :data
4
-
5
- def initialize
6
- @data = []
7
- end
8
-
9
- def add(record)
10
- @data << record
11
- end
12
-
13
- def group_by(type)
14
- @data = case type
15
- when :controller_action, :controller_action_format, :datetime, :path
16
- @data.group_by(&type)
17
- else
18
- []
19
- end
20
- self
21
- end
22
-
23
- def values
24
- return [] if @data.empty?
25
- result = {}
26
- @data.each do |key, records|
27
- result[key] ||= []
28
- records.each do |record|
29
- result[key] << record.value
30
- end
31
- end
32
- result
33
- end
34
-
35
- end
36
- end
@@ -1,45 +0,0 @@
1
- module RailsPerformance
2
- class Record
3
-
4
- attr_reader :controller, :action, :format, :status, :datetime, :datetimei, :method, :path
5
-
6
- # key = performance|
7
- # controller|HomeController|
8
- # action|index|
9
- # format|html|
10
- # status|200|
11
- # datetime|20200124T0523|
12
- # datetimei|1579861423|
13
- # method|GET|
14
- # path|/|
15
- # END
16
- # = {"view_runtime":8.444603008683771,"db_runtime":0,"duration":9.216095000000001}
17
- # value = JSON
18
- def initialize(key, value)
19
- @json = value
20
-
21
- items = key.split("|")
22
-
23
- @controller = items[2]
24
- @action = items[4]
25
- @format = items[6]
26
- @status = items[8]
27
- @datetime = items[10]
28
- @datetimei = items[12]
29
- @method = items[14]
30
- @path = items[16]
31
- end
32
-
33
- def value
34
- @value ||= JSON.parse(@json)
35
- end
36
-
37
- def controller_action
38
- "#{controller}##{action}"
39
- end
40
-
41
- def controller_action_format
42
- "#{controller}##{action}|#{format}"
43
- end
44
- end
45
- end