better_rails_debugger 0.0.1

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 (74) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +98 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/better_rails_debugger_manifest.js +2 -0
  6. data/app/assets/images/avatars/1.jpg +0 -0
  7. data/app/assets/images/avatars/2.jpg +0 -0
  8. data/app/assets/images/avatars/3.jpg +0 -0
  9. data/app/assets/images/avatars/4.jpg +0 -0
  10. data/app/assets/images/avatars/5.jpg +0 -0
  11. data/app/assets/images/avatars/6.jpg +0 -0
  12. data/app/assets/images/avatars/7.jpg +0 -0
  13. data/app/assets/images/avatars/8.jpg +0 -0
  14. data/app/assets/images/favicon.png +0 -0
  15. data/app/assets/images/logo-symbol.png +0 -0
  16. data/app/assets/images/logo.png +0 -0
  17. data/app/assets/javascripts/better_rails_debugger/Chart.min.js +10 -0
  18. data/app/assets/javascripts/better_rails_debugger/app.js +146 -0
  19. data/app/assets/javascripts/better_rails_debugger/application.js +24 -0
  20. data/app/assets/javascripts/better_rails_debugger/bootstrap.min.js +7 -0
  21. data/app/assets/javascripts/better_rails_debugger/jquery-3.0.0.min.js +4 -0
  22. data/app/assets/javascripts/better_rails_debugger/jquery.min.js +4 -0
  23. data/app/assets/javascripts/better_rails_debugger/moment.min.js +7 -0
  24. data/app/assets/javascripts/better_rails_debugger/pace.min.js +2 -0
  25. data/app/assets/javascripts/better_rails_debugger/popper.min.js +5 -0
  26. data/app/assets/javascripts/better_rails_debugger/popper.min.js.map +1 -0
  27. data/app/assets/javascripts/better_rails_debugger/prism.js +7 -0
  28. data/app/assets/javascripts/better_rails_debugger/views/charts.js +196 -0
  29. data/app/assets/javascripts/better_rails_debugger/views/main.js +533 -0
  30. data/app/assets/javascripts/better_rails_debugger/views/popovers.js +8 -0
  31. data/app/assets/javascripts/better_rails_debugger/views/tooltips.js +5 -0
  32. data/app/assets/javascripts/better_rails_debugger/views/widgets.js +564 -0
  33. data/app/assets/stylesheets/better_rails_debugger/analysis_group_controller.css +4 -0
  34. data/app/assets/stylesheets/better_rails_debugger/application.scss +16 -0
  35. data/app/assets/stylesheets/better_rails_debugger/group_instances_controller.css +4 -0
  36. data/app/assets/stylesheets/better_rails_debugger/memory.css +4 -0
  37. data/app/assets/stylesheets/better_rails_debugger/prism.css +215 -0
  38. data/app/assets/stylesheets/better_rails_debugger/style.min.css +12 -0
  39. data/app/controllers/better_rails_debugger/analysis_groups_controller.rb +75 -0
  40. data/app/controllers/better_rails_debugger/application_controller.rb +5 -0
  41. data/app/controllers/better_rails_debugger/group_instances_controller.rb +29 -0
  42. data/app/controllers/better_rails_debugger/memory_controller.rb +21 -0
  43. data/app/helpers/better_rails_debugger/analysis_groups_helper.rb +4 -0
  44. data/app/helpers/better_rails_debugger/application_helper.rb +4 -0
  45. data/app/helpers/better_rails_debugger/group_instances_helper.rb +4 -0
  46. data/app/helpers/better_rails_debugger/memory_helper.rb +4 -0
  47. data/app/jobs/better_rails_debugger/analysis_recorder_job.rb +35 -0
  48. data/app/jobs/better_rails_debugger/application_job.rb +4 -0
  49. data/app/mailers/better_rails_debugger/application_mailer.rb +6 -0
  50. data/app/models/better_rails_debugger/analysis_group.rb +49 -0
  51. data/app/models/better_rails_debugger/application_record.rb +5 -0
  52. data/app/models/better_rails_debugger/group_instance.rb +42 -0
  53. data/app/models/better_rails_debugger/object_information.rb +19 -0
  54. data/app/views/better_rails_debugger/analysis_groups/_form.html.haml +41 -0
  55. data/app/views/better_rails_debugger/analysis_groups/edit.html.haml +23 -0
  56. data/app/views/better_rails_debugger/analysis_groups/index.html.haml +36 -0
  57. data/app/views/better_rails_debugger/analysis_groups/new.html.haml +23 -0
  58. data/app/views/better_rails_debugger/analysis_groups/show.html.haml +35 -0
  59. data/app/views/better_rails_debugger/group_instances/objects.html.haml +62 -0
  60. data/app/views/better_rails_debugger/memory/index.html.haml +20 -0
  61. data/app/views/better_rails_debugger/memory/show.html.haml +26 -0
  62. data/app/views/better_rails_debugger/shared/_header.html.haml +4 -0
  63. data/app/views/better_rails_debugger/shared/_sidebar.html.haml +5 -0
  64. data/app/views/layouts/better_rails_debugger/application.html.erb +47 -0
  65. data/config/initializers/setup.rb +10 -0
  66. data/config/mongoid.yml +160 -0
  67. data/config/routes.rb +21 -0
  68. data/lib/better_rails_debugger/config.rb +45 -0
  69. data/lib/better_rails_debugger/engine.rb +5 -0
  70. data/lib/better_rails_debugger/memory_analyzer.rb +109 -0
  71. data/lib/better_rails_debugger/version.rb +3 -0
  72. data/lib/better_rails_debugger.rb +16 -0
  73. data/lib/tasks/better_rails_debugger_tasks.rake +4 -0
  74. metadata +247 -0
@@ -0,0 +1,4 @@
1
+ module BetterRailsDebugger
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module BetterRailsDebugger
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,49 @@
1
+ module BetterRailsDebugger
2
+ class AnalysisGroup
3
+ include Mongoid::Document
4
+
5
+ include ::Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ before_save :generate_analise_paths
9
+
10
+ field :name, type: String
11
+
12
+ has_many :group_instances, class_name: "::BetterRailsDebugger::GroupInstance", inverse_of: :analysis_group, dependent: :delete_all
13
+
14
+ # Settings
15
+
16
+ ## Memory options
17
+ field :collect_memory_information, type: Boolean, default: true # Disable this, disable all memory tracking options
18
+ field :analise_memory_in_code, type: Boolean, default: true
19
+ field :analise_memory_in_gems, type: Boolean, default: false
20
+ field :record_objects_in, type: String, default: ""
21
+ field :times_to_run, type: Integer, default: 0 # 0: Infinite
22
+ field :analyze_repeated_instances, type: Boolean, default: true # if false, Check the identifier and do run the analyzer if already exist one with the same identifier
23
+
24
+ # Internal use
25
+ field :analise_paths, type: Array, default: []
26
+
27
+ private
28
+ def generate_analise_paths
29
+ if analise_memory_in_gems
30
+ analise_paths << /.*\/gems\/.*/
31
+ end
32
+
33
+ record_objects_in.to_s.split(/\n/).each do |line|
34
+ pp 'Line', line
35
+ line = line.strip
36
+ # Check if file exist
37
+ if File.exist? line
38
+ pp 'File exist'
39
+ if File.directory? line
40
+ pp 'File is a dir'
41
+ analise_paths << /#{line}.*/
42
+ elsif File.file? line
43
+ analise_paths << /#{line}$/
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module BetterRailsDebugger
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ module BetterRailsDebugger
2
+ class GroupInstance
3
+ include ::Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ belongs_to :analysis_group, class_name: "::BetterRailsDebugger::AnalysisGroup"
7
+ has_many :objects, class_name: "::BetterRailsDebugger::ObjectInformation", inverse_of: :group_instance, dependent: :delete_all
8
+
9
+ # Basic information
10
+ field :identifier, type: String
11
+ field :metadata, type: Hash
12
+
13
+ # Status information
14
+ field :processed, type: Boolean
15
+ field :total_classes, type: Integer # Total number of used Classes
16
+ field :total_memory, type: Integer # Total memory used in bytes
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
+
21
+ # Internal use
22
+ field :caller_file, type: String
23
+
24
+ def track_allocation_of?(path)
25
+ return true if match_file_list?(path) or called_from_caller_file?(path)
26
+ false
27
+ end
28
+
29
+ private
30
+ def match_file_list?(path)
31
+ analysis_group.analise_paths.any? do |regexp|
32
+ regexp.match?(path)
33
+ end
34
+ end
35
+
36
+ def called_from_caller_file?(path)
37
+ return false if !analysis_group.analise_memory_in_code
38
+ return true if analysis_group.analise_memory_in_code and /#{caller_file}/.match?(path)
39
+ false
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ module BetterRailsDebugger
2
+ class ObjectInformation
3
+ include ::Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ belongs_to :group_instance, class_name: "::BetterRailsDebugger::GroupInstance"
7
+
8
+ field :ruby_object_id, type: Integer
9
+ field :source_file, type: String
10
+ field :source_line, type: Integer
11
+ field :memsize, type: Integer
12
+ field :class_name, type: String
13
+
14
+ # Internal use
15
+ field :source_code, type: String
16
+ field :formatted_source_code, type: String
17
+
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ = form_for @group do |f|
2
+ .form-group.d-flex
3
+ = f.label :name, class: 'sr-only', class: 'col-2'
4
+ = f.text_field :name, min: 3, class: 'form-control form-control-lg col-10'
5
+
6
+ %fielset.form-group
7
+ %legend Settings
8
+ .form-group.d-flex.justify-content-start
9
+ = f.label :times_to_run, class: 'col-2'
10
+ .col-10
11
+ = f.number_field :times_to_run
12
+ .text-secondary.d-inline Set 0 or any negative value to be infinite
13
+ .form-group.d-flex.justify-content-start
14
+ = f.label :analyze_repeated_instances, class: 'col-2'
15
+ .col-10
16
+ = f.check_box :analyze_repeated_instances
17
+ .text-secondary.d-inline if false, check the identifier and do not run the analyzer if already exist one
18
+ .form-group.d-flex.justify-content-start
19
+ = f.label :collect_memory_information, class: 'col-2'
20
+ .col-10
21
+ = f.check_box :collect_memory_information
22
+ .text-secondary.d-inline Disabling this option, is going to disable all memory options
23
+
24
+ .form-group.d-flex.justify-content-start
25
+ = f.label :record_objects_in, class: 'col-2'
26
+ .col-10
27
+ = f.text_area :record_objects_in, rows: 3, class: 'form-control col-4'
28
+ .text-secondary Every line must be a file or a directory, everything else is going to be omitted.
29
+
30
+ .form-group.d-flex.justify-content-start
31
+ = f.label :analise_memory_in_code, class: 'col-2'
32
+ .col-10
33
+ = f.check_box :analise_memory_in_code
34
+ .text-secondary.d-inline Enable this is you want to debug a memory bloat
35
+ .form-group.d-flex.justify-content-start
36
+ = f.label :analise_memory_in_gems, class: 'col-2'
37
+ .col-10
38
+ = f.check_box :analise_memory_in_gems
39
+ .text-danger.d-inline Analise memory of all gems in the block it's really slow
40
+
41
+ %button.btn.btn-primary{:type => "submit"} Confirm
@@ -0,0 +1,23 @@
1
+ .card
2
+ .card-header
3
+ Edit Analysis Group
4
+ .card-body
5
+
6
+ - content_for :header_nav do
7
+ %ul.nav.navbar-nav.d-md-down-none
8
+ %li.nav-item
9
+ %a.nav-link.navbar-toggler.sidebar-toggler{:href => "#"} ☰
10
+ %li.nav-item.px-3
11
+ %a.nav-link{:href => analysis_groups_path} List
12
+
13
+ %ul.navbar-nav.ml-md-auto
14
+
15
+
16
+ - content_for :breadcrum do
17
+ %ol.breadcrumb
18
+ %li.breadcrumb-item.active
19
+ %a{:href => analysis_groups_path} Analysis Groups
20
+ %li.breadcrumb-item.active
21
+ %a{:href => "#"} New
22
+
23
+ = render 'better_rails_debugger/analysis_groups/form'
@@ -0,0 +1,36 @@
1
+ .card
2
+ .card-header
3
+ Analysis Groups
4
+ .card-body
5
+
6
+ - content_for :header_nav do
7
+ %ul.nav.navbar-nav.d-md-down-none
8
+ %li.nav-item
9
+ %a.nav-link.navbar-toggler.sidebar-toggler{:href => "#"} ☰
10
+ %li.nav-item.px-3
11
+ %a.nav-link{:href => new_analysis_group_path} New
12
+
13
+ %ul.navbar-nav.ml-md-auto
14
+
15
+
16
+ - content_for :breadcrum do
17
+ %ol.breadcrumb
18
+ %li.breadcrumb-item.active
19
+ %a{:href => "#"} Analysis Groups
20
+
21
+ %table.table.border.border-secondary.border-top-0
22
+ %thead.bg-secondary.text-white
23
+ %tr.d-flex
24
+ %th.col-8 Name
25
+ %th.col-2 ID
26
+ %th.col-2 Actions
27
+ %tbody
28
+ - @groups.each do |group|
29
+ %tr.d-flex
30
+ %td.col-8= link_to group.name, analysis_group_path(group.id)
31
+ %td.col-2= group.id
32
+ %td.col-2
33
+ = link_to "Inspect", analysis_group_path(group.id), class: 'btn btn-sm btn-secondary'
34
+ = link_to "Edit", edit_analysis_group_path(group.id), class: 'btn btn-sm btn-info'
35
+ = link_to "Delete", analysis_group_path(group.id), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-danger'
36
+ = will_paginate @groups, renderer: WillPaginate::ActionView::BootstrapLinkRenderer
@@ -0,0 +1,23 @@
1
+ .card
2
+ .card-header
3
+ New Analysis Group
4
+ .card-body
5
+
6
+ - content_for :header_nav do
7
+ %ul.nav.navbar-nav.d-md-down-none
8
+ %li.nav-item
9
+ %a.nav-link.navbar-toggler.sidebar-toggler{:href => "#"} ☰
10
+ %li.nav-item.px-3
11
+ %a.nav-link{:href => analysis_groups_path} List
12
+
13
+ %ul.navbar-nav.ml-md-auto
14
+
15
+
16
+ - content_for :breadcrum do
17
+ %ol.breadcrumb
18
+ %li.breadcrumb-item.active
19
+ %a{:href => analysis_groups_path} Analysis Groups
20
+ %li.breadcrumb-item.active
21
+ %a{:href => "#"} New
22
+
23
+ = render 'better_rails_debugger/analysis_groups/form'
@@ -0,0 +1,35 @@
1
+ .card
2
+ .card-header
3
+ = @group.name
4
+ .card-body
5
+
6
+ - content_for :header_nav do
7
+ %ul.nav.navbar-nav.d-md-down-none
8
+ %li.nav-item
9
+ %a.nav-link.navbar-toggler.sidebar-toggler{:href => "#"} ☰
10
+ %li.nav-item.px-3
11
+ %a.nav-link{:href => analysis_groups_path} List
12
+
13
+ %ul.navbar-nav.ml-md-auto
14
+
15
+
16
+ - content_for :breadcrum do
17
+ %ol.breadcrumb
18
+ %li.breadcrumb-item
19
+ %a{:href => analysis_groups_path} Analysis Groups
20
+ %li.breadcrumb-item
21
+ %a{:href => "#"}= @group.name
22
+
23
+ %table.table.border.border-secondary.border-top-0
24
+ %thead.bg-secondary.text-white
25
+ %tr.d-flex
26
+ %th.col-8 Identifier
27
+ %th.col-2 Date
28
+ %th.col-2 Actions
29
+ %tbody
30
+ - @instances.each do |instance|
31
+ %tr.d-flex
32
+ %td.col-8= link_to instance.identifier, objects_group_instance_path(instance.id)
33
+ %th.col-2= instance.created_at.strftime("%c")
34
+ %td.col-2= link_to "Objects", objects_group_instance_path(instance.id), class: 'btn btn-sm btn-information'
35
+ = will_paginate @instances, renderer: WillPaginate::ActionView::BootstrapLinkRenderer
@@ -0,0 +1,62 @@
1
+ .card
2
+ .card-header
3
+ = @instance.identifier
4
+ = "-"
5
+ = @instance.created_at.strftime("%c")
6
+ .card-body
7
+
8
+ - content_for :header_nav do
9
+ %ul.nav.navbar-nav.d-md-down-none
10
+ %li.nav-item
11
+ %a.nav-link.navbar-toggler.sidebar-toggler{:href => "#"} ☰
12
+ %li.nav-item.px-3
13
+ %a.nav-link{:href => group_instance_path(@instance)} List
14
+
15
+ %ul.navbar-nav.ml-md-auto
16
+
17
+
18
+ - content_for :breadcrum do
19
+ %ol.breadcrumb
20
+ %li.breadcrumb-item
21
+ %a{:href => analysis_groups_path} Analysis Groups
22
+ %li.breadcrumb-item
23
+ %a{:href => analysis_group_path(@instance.analysis_group.id)}= @instance.analysis_group.name
24
+ %li.breadcrumb-item
25
+ %a{:href => "#"}= @instance.identifier
26
+
27
+ .alert.alert-warning{:role => "alert"}
28
+ %h4.alert-heading
29
+ DISCLAIMER
30
+ %p
31
+ Remember that Memsize is a
32
+ %a.alert-link{:href => "http://ruby-doc.org/stdlib-2.5.0/libdoc/objspace/rdoc/ObjectSpace.html#method-c-memsize_of"} HINT.
33
+ The used memory is not the sum of every object listed here because different reasons.
34
+ %p
35
+ Better Rails Debugger only track the creation of Ruby objects, not the creation of C-Ruby objects, and oly
36
+ those objects that are created from the moment that a request arrive to a controller. Everythinng else, like
37
+ objects created by Middlewares, are not been tracked because performance.
38
+
39
+ %table.table.border.border-secondary.border-top-0
40
+ %thead.bg-secondary.text-white
41
+ %tr.d-flex
42
+ %th.col-8 Location
43
+ %th.col-2 Memsize
44
+ %th.col-2 Class
45
+
46
+ %tbody
47
+ - @objects.each do |object|
48
+ %tr.d-flex
49
+ %td.col-8
50
+ %i.fa.fa-eye.fa-2x.text-secondary{"aria-controls" => "collapseExample", "aria-expanded" => "false", "data-toggle" => "collapse", :href => "##{object.id}"}
51
+ %span.text-primary
52
+ =object.source_file
53
+ %span= ":"
54
+ %span.text-success=object.source_line
55
+ %td.col-2= number_to_human_size object.memsize
56
+ %td.col-2.text-danger= object.class_name
57
+ %tr.collapse.out{id: object.id}
58
+ %td{:colspan => 3}
59
+ %pre.line-numbers{:"data-start" => object.source_line - 6, :"data-line" => object.source_line}
60
+ %code.language-ruby= object.source_code
61
+
62
+ = will_paginate @objects, renderer: WillPaginate::ActionView::BootstrapLinkRenderer
@@ -0,0 +1,20 @@
1
+ .card
2
+ .card-header
3
+ Memory per request
4
+ .card-body
5
+
6
+ %table.table.border.border-secondary.border-top-0
7
+ %thead.bg-secondary.text-white
8
+ %th Request URL
9
+ %th Request IP
10
+ %th Total Objects
11
+ %th Actions
12
+
13
+ %tbody
14
+ - @requests.each do |request|
15
+ %tr
16
+ %td= request.url
17
+ %td= request.ip
18
+ %td= request.objects.count
19
+ %td= link_to "Inspect", memory_path(request.id)
20
+ = will_paginate @requests, renderer: WillPaginate::ActionView::BootstrapLinkRenderer
@@ -0,0 +1,26 @@
1
+ .card
2
+ .card-header
3
+ Request
4
+ = @request.url
5
+ = " - "
6
+ = @request.ip
7
+ at
8
+ = @request.created_at
9
+ .card-body
10
+
11
+
12
+ %table.table.border.border-secondary.border-top-0
13
+ %thead.bg-secondary.text-white
14
+ %th Object class
15
+ %th Location
16
+ %th Memsize
17
+ %th Actions
18
+
19
+ %tbody
20
+ - @request.objects.each do |object|
21
+ %tr
22
+ %td= object.class_name
23
+ %td= "#{object.source_file}:#{object.source_line}"
24
+ %td= object.memsize
25
+ %td
26
+ =# will_paginate @requests, renderer: WillPaginate::ActionView::BootstrapLinkRenderer
@@ -0,0 +1,4 @@
1
+ %header.app-header.navbar
2
+ %button.navbar-toggler.mobile-sidebar-toggler.d-lg-none{:type => "button"} ☰
3
+ %a.navbar-brand{:href => "#"} BRD
4
+ = content_for :header_nav
@@ -0,0 +1,5 @@
1
+ .sidebar
2
+ %nav.sidebar-nav
3
+ %ul.nav
4
+ %li.nav-item
5
+ %a.nav-link{:href => analysis_groups_path} Analysis Group
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Better rails debugger</title>
5
+ <%= stylesheet_link_tag "better_rails_debugger/application", media: "all" %>
6
+ <%= javascript_include_tag "better_rails_debugger/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body class="app header-fixed sidebar-fixed">
10
+
11
+ <%= render partial: 'better_rails_debugger/shared/header' %>
12
+
13
+ <div class="app-body">
14
+
15
+ <%= render partial: 'better_rails_debugger/shared/sidebar' %>
16
+
17
+ <main class="main">
18
+ <%=
19
+ # https://coreui.io/docs/components/bootstrap-breadcrumb/
20
+ content_for :breadcrum %>
21
+ <div class="container-fluid">
22
+ <% if flash[:notice] %>
23
+ <div class="alert alert-primary" role="alert">
24
+ <%= flash[:notice] %>
25
+ </div>
26
+ <% end %>
27
+
28
+ <% if flash[:error] %>
29
+ <div class="alert alert-danger" role="alert">
30
+ <%= flash[:error] %>
31
+ </div>
32
+ <% end %>
33
+
34
+
35
+ <%= yield %>
36
+ </div>
37
+ </main>
38
+ </div>
39
+
40
+ <footer class="app-footer d-flex">
41
+ <span class="text-left">
42
+ Thanks to <a href="https://www.coreui.io/" target="_blank">CoreUI</a> team for this amazing template.
43
+ </span>
44
+ </footer>
45
+
46
+ </body>
47
+ </html>