ghazel-fiveruns_tuneup 0.8.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG +33 -0
  2. data/CONTRIBUTORS +5 -0
  3. data/README.rdoc +65 -0
  4. data/assets/images/arrows.gif +0 -0
  5. data/assets/images/edit.png +0 -0
  6. data/assets/images/fade.png +0 -0
  7. data/assets/images/fade_down.png +0 -0
  8. data/assets/images/head.gif +0 -0
  9. data/assets/images/logo.gif +0 -0
  10. data/assets/images/logo_clear.png +0 -0
  11. data/assets/images/magnify.png +0 -0
  12. data/assets/images/pin.png +0 -0
  13. data/assets/images/pip.gif +0 -0
  14. data/assets/images/pointer.gif +0 -0
  15. data/assets/images/pushed_pin.png +0 -0
  16. data/assets/images/schema.png +0 -0
  17. data/assets/images/signin.gif +0 -0
  18. data/assets/images/spinner.gif +0 -0
  19. data/assets/images/warning.gif +0 -0
  20. data/assets/javascripts/init.js +12 -0
  21. data/assets/javascripts/prototype.js +2515 -0
  22. data/assets/javascripts/tuneup.js +115 -0
  23. data/assets/stylesheets/tuneup.css +209 -0
  24. data/init.rb +2 -0
  25. data/install.rb +13 -0
  26. data/lib/bumpspark_helper.rb +52 -0
  27. data/lib/fiveruns/tuneup.rb +154 -0
  28. data/lib/fiveruns/tuneup/asset_tags.rb +54 -0
  29. data/lib/fiveruns/tuneup/configuration.rb +25 -0
  30. data/lib/fiveruns/tuneup/custom_methods.rb +8 -0
  31. data/lib/fiveruns/tuneup/environment.rb +29 -0
  32. data/lib/fiveruns/tuneup/instrumentation/action_controller/base.rb +59 -0
  33. data/lib/fiveruns/tuneup/instrumentation/action_view/base.rb +81 -0
  34. data/lib/fiveruns/tuneup/instrumentation/action_view/partial_template.rb +28 -0
  35. data/lib/fiveruns/tuneup/instrumentation/active_record/base.rb +126 -0
  36. data/lib/fiveruns/tuneup/instrumentation/cgi/session.rb +30 -0
  37. data/lib/fiveruns/tuneup/instrumentation/utilities.rb +187 -0
  38. data/lib/fiveruns/tuneup/multipart.rb +75 -0
  39. data/lib/fiveruns/tuneup/routing.rb +25 -0
  40. data/lib/fiveruns/tuneup/runs.rb +86 -0
  41. data/lib/fiveruns/tuneup/schema.rb +43 -0
  42. data/lib/fiveruns/tuneup/step.rb +221 -0
  43. data/lib/fiveruns/tuneup/version.rb +89 -0
  44. data/lib/fiveruns_tuneup.rb +11 -0
  45. data/lib/tuneup_controller.rb +46 -0
  46. data/lib/tuneup_helper.rb +181 -0
  47. data/rails/init.rb +14 -0
  48. data/tasks/assets.rake +32 -0
  49. data/test/test_helper.rb +3 -0
  50. data/test/tuneup_test.rb +0 -0
  51. data/uninstall.rb +6 -0
  52. data/views/tuneup/_data.html.erb +15 -0
  53. data/views/tuneup/_flash.html.erb +6 -0
  54. data/views/tuneup/_link.html.erb +1 -0
  55. data/views/tuneup/_schema.html.erb +17 -0
  56. data/views/tuneup/_sql.html.erb +23 -0
  57. data/views/tuneup/_step.html.erb +17 -0
  58. data/views/tuneup/panel/_show.html.erb +4 -0
  59. data/views/tuneup/sandbox.html.erb +6 -0
  60. metadata +124 -0
@@ -0,0 +1,54 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+
4
+ module AssetTags
5
+
6
+ def add_asset_tags_to(response)
7
+ return unless show_for?(response)
8
+ before, after = response.body.split(/<\/head>/i, 2)
9
+ if after
10
+ insertion = %(
11
+ <!-- START FIVERUNS TUNEUP ASSETS -->
12
+ <link rel="stylesheet" type="text/css" href="/stylesheets/tuneup/tuneup.css" />
13
+ <script type="text/javascript"> var TuneUp = {}; </script>
14
+ <script type="text/javascript" src="/javascripts/tuneup/init.js"></script>
15
+ <!-- END FIVERUNS TUNEUP ASSETS -->
16
+ )
17
+ add_content_length(response, insertion.size)
18
+ body = [before, insertion, '</head>', after].join('').html_safe!
19
+ response.body.replace(body)
20
+ log :error, "Inserted asset tags"
21
+ else
22
+ log :error, "Could not find closing </head> tag for insertion"
23
+ end
24
+ end
25
+
26
+ def show_for?(response)
27
+ return false unless response.body
28
+ return true if response.headers['ETag'] && response.headers['Content-Type'].to_s.include?('html')
29
+ return false unless response.headers['Status'] && response.headers['Status'].include?('200')
30
+ true
31
+ end
32
+
33
+ def insert_prototype
34
+ "<script type='text/javascript' src='/javascripts/tuneup/prototype.js'></script>"
35
+ end
36
+
37
+ # Modify the Content-Length header, regardless if String/Fixnum, and
38
+ # keep it the same type
39
+ def add_content_length(response, delta)
40
+ length = response.headers["Content-Length"]
41
+ response.headers["Content-Length"] = case length
42
+ when Fixnum
43
+ length + delta
44
+ when String
45
+ (length.to_i + delta).to_s
46
+ else
47
+ length # Shouldn't happen
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ module Fiveruns::Tuneup
2
+
3
+ class Configuration
4
+
5
+ attr_writer :log_directory
6
+ def log_directory
7
+ @log_directory ||= begin
8
+ rails_log = RAILS_DEFAULT_LOGGER.instance_eval { @log.path rescue @logdev.filename }
9
+ File.dirname(rails_log)
10
+ rescue
11
+ Dir::tmpdir
12
+ end
13
+ end
14
+
15
+ def environments
16
+ @environments ||= %w(development)
17
+ end
18
+
19
+ def instrument?
20
+ environments.map(&:to_s).include?(RAILS_ENV)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,8 @@
1
+ module Fiveruns::Tuneup::CustomMethods
2
+
3
+ # Manually instrument methods
4
+ def tuneup(*args)
5
+ Fiveruns::Tuneup.add_custom_methods(self, *args)
6
+ end
7
+
8
+ end
@@ -0,0 +1,29 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Environment
4
+
5
+ def environment
6
+ {
7
+ 'application_name' => application_name,
8
+ 'rails_env' => rails_env,
9
+ 'rails_version' => rails_version
10
+ }
11
+ end
12
+
13
+ def rails_env
14
+ RAILS_ENV || 'development'
15
+ end
16
+
17
+ def rails_version
18
+ Fiveruns::Tuneup::Version.rails.to_s
19
+ end
20
+
21
+ def application_name
22
+ app_name = RAILS_ROOT.split('/').last
23
+ return app_name unless app_name == 'current'
24
+ File.join(RAILS_ROOT, '..').split('/').last
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Instrumentation
4
+ module ActionController
5
+ module Base
6
+ def self.included(base)
7
+ Fiveruns::Tuneup.instrument base, ClassMethods, InstanceMethods
8
+ end
9
+ module ClassMethods
10
+ def cache_page_with_fiveruns_tuneup(*args, &block)
11
+ Fiveruns::Tuneup.step "Cache page", :controller do
12
+ cache_page_without_fiveruns_tuneup(*args, &block)
13
+ end
14
+ end
15
+ def expire_page_with_fiveruns_tuneup(*args, &block)
16
+ Fiveruns::Tuneup.step "Expire cached page", :controller do
17
+ expire_page_without_fiveruns_tuneup(*args, &block)
18
+ end
19
+ end
20
+ end
21
+ module InstanceMethods
22
+ def perform_action_with_fiveruns_tuneup(*args, &block)
23
+ Fiveruns::Tuneup.run(self, request) do
24
+ action = (request.parameters['action'] || 'index').to_s
25
+ if Fiveruns::Tuneup.recording?
26
+ Fiveruns::Tuneup.instrument_filters(self)
27
+ Fiveruns::Tuneup.instrument_action_methods(self)
28
+ Fiveruns::Tuneup.instrument_custom_methods
29
+ end
30
+ result = Fiveruns::Tuneup.step "Perform #{action.capitalize} action in #{self.class.name}", :controller, false do
31
+ perform_action_without_fiveruns_tuneup(*args, &block)
32
+ end
33
+ end
34
+ end
35
+ def process_with_fiveruns_tuneup(request, response, *args, &block)
36
+ result = process_without_fiveruns_tuneup(request, response, *args, &block)
37
+ if !request.xhr? && response.content_type && response.content_type.include?('html') && controller_name != 'tuneup'
38
+ Fiveruns::Tuneup.add_asset_tags_to(response)
39
+ end
40
+ result
41
+ end
42
+
43
+ def write_fragment_with_fiveruns_tuneup(*args, &block)
44
+ Fiveruns::Tuneup.step "Cache fragment", :controller do
45
+ write_fragment_without_fiveruns_tuneup(*args, &block)
46
+ end
47
+ end
48
+ def expire_fragment_with_fiveruns_tuneup(*args, &block)
49
+ Fiveruns::Tuneup.step "Expire fragment cache", :controller do
50
+ expire_fragment_without_fiveruns_tuneup(*args, &block)
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,81 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Instrumentation
4
+ module ActionView
5
+ module Base
6
+
7
+ BASIC_TEMPLATE_PATH = File.join(RAILS_ROOT, 'app', 'views')
8
+
9
+ def self.included(base)
10
+ Fiveruns::Tuneup.instrument base, InstanceMethods
11
+ end
12
+
13
+ def self.normalize_path(path)
14
+ return path unless path
15
+ if path[0, BASIC_TEMPLATE_PATH.size] == BASIC_TEMPLATE_PATH
16
+ path[(BASIC_TEMPLATE_PATH.size + 1)..-1]
17
+ else
18
+ if (components = path.split(File::SEPARATOR)).size > 2
19
+ components[-2, 2].join(File::SEPARATOR)
20
+ else
21
+ components.join(File::SEPARATOR)
22
+ end
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+ def render_file_with_fiveruns_tuneup(path, *args, &block)
28
+ name = Fiveruns::Tuneup::Instrumentation::ActionView::Base.normalize_path(path)
29
+ Fiveruns::Tuneup.step "Render file #{name}", :view do
30
+ render_file_without_fiveruns_tuneup(path, *args, &block)
31
+ end
32
+ end
33
+ def update_page_with_fiveruns_tuneup(*args, &block)
34
+ path = block.to_s.split('/').last.split(':').first rescue ''
35
+ name = Fiveruns::Tuneup::Instrumentation::ActionView::Base.normalize_path(path)
36
+ Fiveruns::Tuneup.step "Render page update #{name}", :view do
37
+ update_page_without_fiveruns_tuneup(*args, &block)
38
+ end
39
+ end
40
+ def render_with_fiveruns_tuneup(*args, &block)
41
+ record = true
42
+ options = args.first || {}
43
+ path = case options
44
+ when String
45
+ # Pre-Rails 2.1, don't record this as it causes duplicate records
46
+ if Fiveruns::Tuneup::Version.rails < Fiveruns::Tuneup::Version.new(2,1,0)
47
+ record = false
48
+ else
49
+ "Render #{options}"
50
+ end
51
+ when :update
52
+ name = block.to_s.split('/').last.split(':').first rescue ''
53
+ "Render page update #{name}"
54
+ when Hash
55
+ if options[:file]
56
+ "Render #{options[:file]}"
57
+ elsif options[:partial]
58
+ record = false
59
+ elsif options[:inline]
60
+ "Render inline"
61
+ elsif options[:text]
62
+ "Render text"
63
+ end
64
+ end
65
+ path ||= 'Render'
66
+
67
+ if record
68
+ Fiveruns::Tuneup.step path, :view do
69
+ render_without_fiveruns_tuneup(*args, &block)
70
+ end
71
+ else
72
+ render_without_fiveruns_tuneup(*args, &block)
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,28 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Instrumentation
4
+ module ActionView
5
+ module PartialTemplate
6
+
7
+ def self.included(base)
8
+ Fiveruns::Tuneup.instrument base, InstanceMethods
9
+ end
10
+
11
+ def self.relevant?
12
+ Fiveruns::Tuneup::Version.rails < Fiveruns::Tuneup::Version.new(2,1,0) ? false : true
13
+ end
14
+
15
+ module InstanceMethods
16
+
17
+ def render_with_fiveruns_tuneup(*args, &block)
18
+ Fiveruns::Tuneup.step "Render partial #{path}", :view do
19
+ render_without_fiveruns_tuneup(*args, &block)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,126 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Instrumentation
4
+ module ActiveRecord
5
+ module Base
6
+
7
+ def self.record(model, name, raw_sql=nil, &operation)
8
+ sql = nil
9
+ Fiveruns::Tuneup.exclude do
10
+ model.silence do
11
+ sql = Fiveruns::Tuneup::Step::SQL.new(raw_sql, model.connection) if raw_sql
12
+ Fiveruns::Tuneup.add_schema_for(model.table_name, model.connection)
13
+ end
14
+ end
15
+ Fiveruns::Tuneup.step(name, :model, true, sql, model.table_name, &operation)
16
+ end
17
+
18
+ def self.included(base)
19
+ Fiveruns::Tuneup.instrument base, InstanceMethods, ClassMethods
20
+ end
21
+
22
+ module ClassMethods
23
+
24
+ #
25
+ # FINDS
26
+ #
27
+
28
+ def find_with_fiveruns_tuneup(*args, &block)
29
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Find #{self.name}" do
30
+ find_without_fiveruns_tuneup(*args, &block)
31
+ end
32
+ end
33
+ def find_by_sql_with_fiveruns_tuneup(conditions, &block)
34
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Find #{self.name} by SQL", sanitize_sql(conditions) do
35
+ find_by_sql_without_fiveruns_tuneup(conditions, &block)
36
+ end
37
+ end
38
+
39
+ #
40
+ # CREATE
41
+ #
42
+
43
+ def create_with_fiveruns_tuneup(*args, &block)
44
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Create #{self.name}" do
45
+ create_without_fiveruns_tuneup(*args, &block)
46
+ end
47
+ end
48
+
49
+ #
50
+ # UPDATES
51
+ #
52
+
53
+ def update_with_fiveruns_tuneup(*args, &block)
54
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Update #{self.name}" do
55
+ update_without_fiveruns_tuneup(*args, &block)
56
+ end
57
+ end
58
+ def update_all_with_fiveruns_tuneup(*args, &block)
59
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Update #{self.name} (All)" do
60
+ update_all_without_fiveruns_tuneup(*args, &block)
61
+ end
62
+ end
63
+
64
+ #
65
+ # DELETES
66
+ #
67
+
68
+ def destroy_with_fiveruns_tuneup(*args, &block)
69
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Destroy #{self.name}" do
70
+ destroy_without_fiveruns_tuneup(*args, &block)
71
+ end
72
+ end
73
+ def destroy_all_with_fiveruns_tuneup(*args, &block)
74
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Destroy #{self.name} (All)" do
75
+ destroy_all_without_fiveruns_tuneup(*args, &block)
76
+ end
77
+ end
78
+ def delete_with_fiveruns_tuneup(*args, &block)
79
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Delete #{self.name}" do
80
+ delete_without_fiveruns_tuneup(*args, &block)
81
+ end
82
+ end
83
+ def delete_all_with_fiveruns_tuneup(*args, &block)
84
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self, "Delete #{self.name} (All)" do
85
+ delete_all_without_fiveruns_tuneup(*args, &block)
86
+ end
87
+ end
88
+ end
89
+ module InstanceMethods
90
+
91
+ #
92
+ # UPDATES
93
+ #
94
+
95
+ def update_with_fiveruns_tuneup(*args, &block)
96
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self.class, "Update #{self.class.name}" do
97
+ update_without_fiveruns_tuneup(*args, &block)
98
+ end
99
+ end
100
+ def save_with_fiveruns_tuneup(*args, &block)
101
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self.class, "Save #{self.class.name}" do
102
+ save_without_fiveruns_tuneup(*args, &block)
103
+ end
104
+ end
105
+ def save_with_fiveruns_tuneup!(*args, &block)
106
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self.class, "Save #{self.class.name}" do
107
+ save_without_fiveruns_tuneup!(*args, &block)
108
+ end
109
+ end
110
+
111
+ #
112
+ # DELETES
113
+ #
114
+
115
+ def destroy_with_fiveruns_tuneup(*args, &block)
116
+ Fiveruns::Tuneup::Instrumentation::ActiveRecord::Base.record self.class, "Destroy #{self.class.name}" do
117
+ destroy_without_fiveruns_tuneup(*args, &block)
118
+ end
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,30 @@
1
+ module Fiveruns
2
+ module Tuneup
3
+ module Instrumentation
4
+ module CGI
5
+ module Session
6
+ def self.included(base)
7
+ Fiveruns::Tuneup.instrument base, InstanceMethods
8
+ end
9
+ module InstanceMethods
10
+ def initialize_with_fiveruns_tuneup(*args, &block)
11
+ Fiveruns::Tuneup.step "Create session", :model do
12
+ initialize_without_fiveruns_tuneup(*args, &block)
13
+ end
14
+ end
15
+ def close_with_fiveruns_tuneup(*args, &block)
16
+ Fiveruns::Tuneup.step "Close session", :model do
17
+ close_without_fiveruns_tuneup(*args, &block)
18
+ end
19
+ end
20
+ def delete_with_fiveruns_tuneup(*args, &block)
21
+ Fiveruns::Tuneup.step "Delete session", :model do
22
+ delete_without_fiveruns_tuneup(*args, &block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end