better_rails_debugger 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 44960a042bef701c0cf46fb9f41811088f8e26e6
4
- data.tar.gz: fb0817fe00ecf575a21435029f8ce28207fdbb75
3
+ metadata.gz: 378633b02ace347f31f2e5350248b08903e24e87
4
+ data.tar.gz: cf4e8e7b1614196b194ef32060c46a24237bac98
5
5
  SHA512:
6
- metadata.gz: 8fb7362c78580e939169600cba203056d929f01d533f252ff6f4a8fac83a8264a9e018697a1e1633899a7e910ddfaaa78b894b8254e647992348f8cbd93a2ebd
7
- data.tar.gz: c6c02323f036fa8846c12ce581f96a82f2afc076906579beb033e272a81d68baaa3caa6789f3ac36b6c7b6e1b4e4fc449a241f8f4286e1acf0431924deb9733d
6
+ metadata.gz: 454b43fb094ea115cb30bdd1aa700dcb73b5cf5aaae41bbce2019e2c7e9c0cb62c0c2e497ba5fc91f2ffe5ebee5426a595f202f4d23cc13538963a2999474933
7
+ data.tar.gz: ea0d02c5e10418a224e075d0e9eab163b3bc57e9fa4a31f204c6a1d9f1c18e6990ece288207baa946e8c0f671173b134d27a414d86e01c4b3e548e88b7fc7443
data/README.md CHANGED
@@ -43,6 +43,13 @@ bundle exec sidekiq
43
43
 
44
44
  3) Set MongoID database.yml file:
45
45
 
46
+ In rails 5 run:
47
+ ```ruby
48
+ rails g mongoid:config
49
+ ```
50
+
51
+ change the file configuration and/or rename it.
52
+
46
53
  Create an initializer to configure like `config/initializers/better_ruby_debugger.rb`
47
54
 
48
55
  ```ruby
@@ -10,6 +10,28 @@ module BetterRailsDebugger
10
10
  return
11
11
  end
12
12
  @objects = @instance.objects.order(created_at: 'desc').limit(20)
13
+ filter
14
+ @objects = @objects.paginate(page: (params[:page] || 1), per_page: 20)
15
+
16
+ @file_allocations = @instance.files_with_more_allocations(4)
17
+ end
18
+
19
+ def code
20
+ begin
21
+ @object = ObjectInformation.find(params[:object_id])
22
+ rescue Mongoid::Errors::DocumentNotFound
23
+ redirect_to group_instance_path(params[:id]), flash: {error: 'Object not found'}
24
+ return
25
+ end
26
+ # Verify object existence
27
+ theme = Rouge::Themes::Github.new
28
+ formatter = Rouge::Formatters::HTMLInline.new theme
29
+ lexer = Rouge::Lexers::Ruby.new
30
+ render plain: formatter.format(lexer.lex(@object.source_code || ""))
31
+ end
32
+
33
+ private
34
+ def filter
13
35
  if ['asc', 'desc'].include? params[:order] and ['location', 'memsize', 'class'].include? params[:column]
14
36
  if params[:column] == 'location'
15
37
  @objects = @objects.order({source_file: params[:order], source_line: params[:order]})
@@ -26,21 +48,6 @@ module BetterRailsDebugger
26
48
  {class_name: /.*#{params[:filter]}.*/i})
27
49
  pp @objects
28
50
  end
29
- @objects = @objects.paginate(page: (params[:page] || 1), per_page: 20)
30
- end
31
-
32
- def code
33
- begin
34
- @object = ObjectInformation.find(params[:object_id])
35
- rescue Mongoid::Errors::DocumentNotFound
36
- redirect_to group_instance_path(params[:id]), flash: {error: 'Object not found'}
37
- return
38
- end
39
- # Verify object existence
40
- theme = Rouge::Themes::Github.new
41
- formatter = Rouge::Formatters::HTMLInline.new theme
42
- lexer = Rouge::Lexers::Ruby.new
43
- render plain: formatter.format(lexer.lex(@object.source_code || ""))
44
51
  end
45
52
  end
46
53
  end
@@ -18,17 +18,19 @@ module BetterRailsDebugger
18
18
  # Now, with the group present... we can start to work on it
19
19
  # group = instance.analysis_group
20
20
 
21
- theme = Rouge::Themes::Github.new()
22
- formatter = Rouge::Formatters::HTMLInline.new theme
23
- lexer = Rouge::Lexers::Ruby.new
24
-
21
+ allocations_per_file = Hash.new(0)
22
+ memsize_per_file = Hash.new(0)
25
23
  instance.objects.all.each do |object|
24
+ allocations_per_file[object.source_file] += 1
25
+ memsize_per_file[object.source_file] += object.memsize
26
26
  start = (l = object.source_line - 4) >= 0 ? l : 0
27
27
  # TODO: Optimize this
28
28
  object.source_code = IO.readlines(object.source_file)[start..(object.source_line + 4)].join("\n")
29
- # object.formatted_source_code = formatter.format(lexer.lex(object.source_code || ""))
30
29
  object.save
31
30
  end
31
+ instance.allocations_per_file = allocations_per_file.to_json
32
+ instance.memsize_per_file = memsize_per_file.to_json
33
+ instance.save
32
34
 
33
35
  end
34
36
  end
@@ -15,17 +15,25 @@ module BetterRailsDebugger
15
15
  field :total_classes, type: Integer # Total number of used Classes
16
16
  field :total_memory, type: Integer # Total memory used in bytes
17
17
  field :total_files, type: Integer # Total file used on allocation
18
- field :allocations_per_file, type: Hash # Hash with `file => num_allocations`
19
- field :inverse_allocation_per_file, type: Hash # Hash with `allocations => Array<files>`
20
18
 
21
19
  # Internal use
22
20
  field :caller_file, type: String
21
+ field :allocations_per_file, type: String
22
+ field :memsize_per_file, type: String
23
23
 
24
24
  def track_allocation_of?(path)
25
25
  return true if match_file_list?(path) or called_from_caller_file?(path)
26
26
  false
27
27
  end
28
28
 
29
+ def files_with_more_allocations(n)
30
+ JSON.parse(allocations_per_file).to_a.sort_by do |a| a[1] end.reverse[0..n]
31
+ end
32
+
33
+ def files_that_use_more_memory(n)
34
+ JSON.parse(memsize_per_file).to_a.sort_by do |a| a[1] end.reverse[0..n]
35
+ end
36
+
29
37
  private
30
38
  def match_file_list?(path)
31
39
  analysis_group.analise_paths.any? do |regexp|
@@ -0,0 +1,28 @@
1
+ .stats.d-flex
2
+ .card.col-6
3
+ .card-body
4
+ %h4.card-title Files with more allocations
5
+ %table.table
6
+ %thead.bg-secondary.text-white
7
+ %tr.d-flex
8
+ %th.col-10 File
9
+ %th.col-2 Allocations
10
+ %tbody
11
+ - @instance.files_with_more_allocations(4).each do |file|
12
+ %tr.d-flex
13
+ %td.col-10.text-primary= file[0]
14
+ %td.col-2= file[1]
15
+
16
+ .card.col-6
17
+ .card-body
18
+ %h4.card-title Files that consume more memory
19
+ %table.table
20
+ %thead.bg-secondary.text-white
21
+ %tr.d-flex
22
+ %th.col-10 File
23
+ %th.col-2 Allocations
24
+ %tbody
25
+ - @instance.files_that_use_more_memory(4).each do |file|
26
+ %tr.d-flex
27
+ %td.col-10.text-primary= file[0]
28
+ %td.col-2= "~ #{number_to_human_size file[1]}"
@@ -36,6 +36,8 @@
36
36
  those objects that are created from the moment that a request arrive to a controller. Everythinng else, like
37
37
  objects created by Middlewares, are not been tracked because performance.
38
38
 
39
+ = render partial: 'better_rails_debugger/group_instances/stats_summary'
40
+
39
41
  %h3 Filter
40
42
  %form{url: objects_group_instance_path(@instance, column: params[:column], order: params[:order]), method: "get"}
41
43
  .form-group.d-flex
@@ -3,7 +3,6 @@ require "mongoid"
3
3
  require "haml"
4
4
  require "will_paginate_mongoid"
5
5
  require "will_paginate-bootstrap4"
6
- require "rouge"
7
6
  require "font-awesome-rails"
8
7
 
9
8
  require "better_rails_debugger/config"
@@ -19,8 +19,8 @@ module BetterRailsDebugger
19
19
  else
20
20
  ::ObjectSpace.trace_object_allocations do
21
21
  yield
22
- collect_information(identifier, group_id)
23
22
  end
23
+ collect_information(identifier, group_id)
24
24
  end
25
25
  end
26
26
 
@@ -1,3 +1,3 @@
1
1
  module BetterRailsDebugger
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_rails_debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andres Jose Borek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -98,20 +98,6 @@ dependencies:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
- - !ruby/object:Gem::Dependency
102
- name: rouge
103
- requirement: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - "~>"
106
- - !ruby/object:Gem::Version
107
- version: '3.1'
108
- type: :runtime
109
- prerelease: false
110
- version_requirements: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - "~>"
113
- - !ruby/object:Gem::Version
114
- version: '3.1'
115
101
  - !ruby/object:Gem::Dependency
116
102
  name: font-awesome-rails
117
103
  requirement: !ruby/object:Gem::Requirement
@@ -205,6 +191,7 @@ files:
205
191
  - app/views/better_rails_debugger/analysis_groups/index.html.haml
206
192
  - app/views/better_rails_debugger/analysis_groups/new.html.haml
207
193
  - app/views/better_rails_debugger/analysis_groups/show.html.haml
194
+ - app/views/better_rails_debugger/group_instances/_stats_summary.html.haml
208
195
  - app/views/better_rails_debugger/group_instances/objects.html.haml
209
196
  - app/views/better_rails_debugger/memory/index.html.haml
210
197
  - app/views/better_rails_debugger/memory/show.html.haml