autobench 0.0.1alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +16 -0
  3. data/README.md +123 -0
  4. data/bin/autobench +180 -0
  5. data/bin/autobench-config +162 -0
  6. data/lib/autobench.rb +28 -0
  7. data/lib/autobench/client.rb +78 -0
  8. data/lib/autobench/common.rb +49 -0
  9. data/lib/autobench/config.rb +62 -0
  10. data/lib/autobench/render.rb +102 -0
  11. data/lib/autobench/version.rb +3 -0
  12. data/lib/autobench/yslow.rb +75 -0
  13. data/lib/phantomas/README.md +296 -0
  14. data/lib/phantomas/core/formatter.js +65 -0
  15. data/lib/phantomas/core/helper.js +64 -0
  16. data/lib/phantomas/core/modules/requestsMonitor/requestsMonitor.js +214 -0
  17. data/lib/phantomas/core/pads.js +16 -0
  18. data/lib/phantomas/core/phantomas.js +418 -0
  19. data/lib/phantomas/lib/args.js +27 -0
  20. data/lib/phantomas/lib/modules/_coffee-script.js +2 -0
  21. data/lib/phantomas/lib/modules/assert.js +326 -0
  22. data/lib/phantomas/lib/modules/events.js +216 -0
  23. data/lib/phantomas/lib/modules/http.js +55 -0
  24. data/lib/phantomas/lib/modules/path.js +441 -0
  25. data/lib/phantomas/lib/modules/punycode.js +510 -0
  26. data/lib/phantomas/lib/modules/querystring.js +214 -0
  27. data/lib/phantomas/lib/modules/tty.js +7 -0
  28. data/lib/phantomas/lib/modules/url.js +625 -0
  29. data/lib/phantomas/lib/modules/util.js +520 -0
  30. data/lib/phantomas/modules/ajaxRequests/ajaxRequests.js +15 -0
  31. data/lib/phantomas/modules/assetsTypes/assetsTypes.js +21 -0
  32. data/lib/phantomas/modules/cacheHits/cacheHits.js +28 -0
  33. data/lib/phantomas/modules/caching/caching.js +66 -0
  34. data/lib/phantomas/modules/cookies/cookies.js +54 -0
  35. data/lib/phantomas/modules/domComplexity/domComplexity.js +130 -0
  36. data/lib/phantomas/modules/domQueries/domQueries.js +148 -0
  37. data/lib/phantomas/modules/domains/domains.js +49 -0
  38. data/lib/phantomas/modules/globalVariables/globalVariables.js +44 -0
  39. data/lib/phantomas/modules/headers/headers.js +48 -0
  40. data/lib/phantomas/modules/localStorage/localStorage.js +14 -0
  41. data/lib/phantomas/modules/requestsStats/requestsStats.js +71 -0
  42. data/lib/phantomas/modules/staticAssets/staticAssets.js +40 -0
  43. data/lib/phantomas/modules/waterfall/waterfall.js +62 -0
  44. data/lib/phantomas/modules/windowPerformance/windowPerformance.js +36 -0
  45. data/lib/phantomas/package.json +27 -0
  46. data/lib/phantomas/phantomas.js +35 -0
  47. data/lib/phantomas/run-multiple.js +177 -0
  48. data/lib/yslow.js +5 -0
  49. metadata +135 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c5f2e2376802ee01016f1887d3ff724f3547ee0
4
+ data.tar.gz: 2e96794b47c4a29d977cbd4bc47735a765090935
5
+ SHA512:
6
+ metadata.gz: cf4ff282040334a17e19b8097f67d38809933223eabe5b5c528a382a4ba3fc56dec0262cf20f9dbb028c3c00ce7ccdceecf0e7feb302cd66b2949a780357f005
7
+ data.tar.gz: 80d4181decbd594c9d7b664fbf3bd7ccaa40ae352305fe18f09b72f372f6f513bb2f581c1f8552111f05a821fa24a33bf472de143fcd967fb10ea1a676de85b6
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "httperfrb", "~> 0.3.11"
5
+
6
+ group :test do
7
+ gem "rake", "~> 10.1.0"
8
+ gem "minitest", "~> 5.0.5"
9
+ end
10
+
11
+ group :development do
12
+ gem "pry"
13
+ gem "pry-doc"
14
+ end
15
+
16
+ # vim:ft=ruby:
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # autobench
2
+
3
+ > NOTE: This is still very much under development and I've written the README to define how I plan for it to work.
4
+ >
5
+ > TODOs:
6
+ >
7
+ > * Currently, yslow.js and phantomas do not work, unless
8
+ > you're running this from within the root directoy. I'm
9
+ > still trying to figure out why.
10
+
11
+ ### TODO: Installation
12
+
13
+ gem install autobench
14
+
15
+ # or...
16
+
17
+ bundle init
18
+ echo "gem 'autobench'" >> Gemfile
19
+ bundle install --path vendor/bundle
20
+
21
+ ### Usage
22
+
23
+ #### `autobench`
24
+
25
+ Usage: autobench [options]
26
+
27
+ Required Arguments:
28
+ -c, --config FILENAME configuration file
29
+
30
+ Optional Arguments:
31
+
32
+ Note: server, port, uri and runs overide what's in
33
+ your configuation file.
34
+
35
+ -s, --server SERVER target server
36
+ -p, --port PORT target port
37
+ -u, --uri URI target uri
38
+ -i, --runs RUNS itterations against target
39
+ -f, --format [json|yaml|csv] raw output format
40
+ -r, --results [dirname] results directory (default: /tmp)
41
+
42
+ Module Exclusion:
43
+ -R, --without-render Do not include render (httperf).
44
+ -Y, --without-yslow Do not include yslow (yslow.js).
45
+ -C, --without-client Do not include client (phantomas).
46
+
47
+ Misc. Arguments:
48
+ -q, --quiet Print no things.
49
+ -h, --help Show this message
50
+
51
+ #### `autobench-config`
52
+
53
+ The purpose of this is to generate a base configuration for your page, containing
54
+ all possible values in their current state.
55
+
56
+ > Note: I recommend looking over each configuration and removing those you don't
57
+ > care about. Also, you should bump most up just a bit to account for standard
58
+ > network variance.
59
+
60
+ Usage: autobench-config [options]
61
+
62
+ Required Arguments:
63
+ -o, --output FILENAME configuration output file
64
+
65
+ Optional Arguments:
66
+
67
+ Note: server, port, uri and runs overide defaults:
68
+ - server: 'localhost'
69
+ - port: 80
70
+ - uri: '/'
71
+ - runs: 9
72
+
73
+ -s, --server SERVER target server
74
+ -p, --port PORT target port
75
+ -u, --uri URI target uri
76
+ -i, --runs RUNS itterations against target
77
+
78
+ Module Exclusion:
79
+ -R, --without-render Do not include render (httperf).
80
+ -Y, --without-yslow Do not include yslow (yslow.js).
81
+ -C, --without-client Do not include client (phantomas).
82
+
83
+ Misc. Arguments:
84
+ -h, --help Show this message
85
+
86
+ ### Minitest Integration
87
+
88
+ > #### TODO
89
+ > Advanced Examples
90
+
91
+ require "minitest/autorun"
92
+ require "autobench"
93
+
94
+ class TestBenchmarks < Minitest::Test
95
+ def setup
96
+ @autobench = Autobench.new( "./path/to/config.yml", { ... config overides ... } )
97
+ end
98
+
99
+ def test_autobench_render
100
+ @autobench.render.benchmark
101
+ assert @autobench.render["connection_time_median"] < 500 # ms
102
+
103
+ # or...
104
+ assert @autobench.render.passed?
105
+ end
106
+
107
+ def test_autobench_yslow
108
+ @autobench.yslow.benchmark
109
+ assert @autobench.yslow["overall"] >= 95 # score
110
+
111
+ # or...
112
+ assert @autobench.yslow.passed?
113
+ end
114
+
115
+ def test_autobench_client
116
+ @autobench.client.benchmark
117
+ assert @autobench["requests"] < 100 # connections
118
+
119
+ # or...
120
+ assert @autobench.client.passed?
121
+ end
122
+ end
123
+
data/bin/autobench ADDED
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+
4
+ ################################################################################
5
+ # Really, Autobench was designed to be hooked up to test frameworks,
6
+ # however, here's a hacky/ugly script to run it via command line.
7
+ ################################################################################
8
+
9
+ require 'optparse'
10
+ require 'benchmark'
11
+ require 'json'
12
+ require 'yaml'
13
+ require 'csv'
14
+ require 'autobench'
15
+
16
+ # opts
17
+ @quiet = false
18
+ @format = "json"
19
+ @resdir = "/tmp"
20
+ options = {}
21
+ benchmarks = {
22
+ # defaults
23
+ :render => true,
24
+ :yslow => true,
25
+ :client => true
26
+ }
27
+ optparser = OptionParser.new do |opts|
28
+ opts.banner = "Usage: autobench [options]"
29
+
30
+ opts.separator ""
31
+ opts.separator "Required Arguments:"
32
+
33
+ opts.on("-c", "--config FILENAME", "configuration file") do |p|
34
+ options["config"] = p
35
+ end
36
+
37
+ opts.separator ""
38
+ opts.separator "Optional Arguments:"
39
+ opts.separator ""
40
+ opts.separator " Note: server, port, uri and runs overide what's in"
41
+ opts.separator " your configuation file."
42
+ opts.separator ""
43
+
44
+
45
+ opts.on("-s", "--server SERVER", "target server") do |p|
46
+ options["server"] = p
47
+ end
48
+
49
+ opts.on("-p", "--port PORT", Integer, "target port") do |p|
50
+ options["port"] = p
51
+ end
52
+
53
+ opts.on("-u", "--uri URI", "target uri") do |p|
54
+ options["uri"] = p
55
+ end
56
+
57
+ opts.on("-i", "--runs RUNS", Integer, "itterations against target") do |p|
58
+ options["runs"] = p
59
+ end
60
+
61
+ opts.on("-f", "--format [json|yaml|csv]", "raw output format") do |p|
62
+ @format = p
63
+ end
64
+
65
+ opts.on("-r", "--results [dirname]", "results directory (default: /tmp)") do |p|
66
+ @resdir = File.expand_path(p)
67
+ end
68
+
69
+ opts.separator ""
70
+ opts.separator "Module Exclusion:"
71
+ opts.on("-R", "--without-render", "Do not include render (httperf).") do
72
+ benchmarks[:render] = false
73
+ end
74
+
75
+ opts.on("-Y", "--without-yslow", "Do not include yslow (yslow.js).") do
76
+ benchmarks[:yslow] = false
77
+ end
78
+
79
+ opts.on("-C", "--without-client", "Do not include client (phantomas).") do
80
+ benchmarks[:client] = false
81
+ end
82
+
83
+ opts.separator ""
84
+ opts.separator "Misc. Arguments:"
85
+ opts.on("-q", "--quiet", "Print no things.") do
86
+ @quiet = true
87
+ end
88
+
89
+ opts.on("-h", "--help", "Show this message") do
90
+ puts opts
91
+ exit
92
+ end
93
+ end
94
+ optparser.parse!
95
+
96
+ unless options.has_key?("config")
97
+ puts optparser
98
+ exit
99
+ end
100
+
101
+ def say msg
102
+ unless @quiet
103
+ puts msg
104
+ end
105
+ end
106
+
107
+ # utils
108
+
109
+ def dump run
110
+ outfile = File.join(@resdir, "autobench-#{run}-#{Time.now.to_i}.#{@format.gsub('yaml','yml')}")
111
+ results = @autobench.send(run).full_results
112
+ File.open(outfile, "w") do |f|
113
+ case @format
114
+ when "json"
115
+ f.write(JSON.pretty_generate(results))
116
+ when "yaml"
117
+ f.write(results.to_yaml)
118
+ when "csv"
119
+ f.write(
120
+ CSV.generate { |csv|
121
+ csv << results.keys
122
+ csv << results.values
123
+ }
124
+ )
125
+ else
126
+ raise "unknown format `#{@format}`, try `yaml`, `json` or `csv`"
127
+ exit 556
128
+ end
129
+ end
130
+ say "=> Raw results (#{@format}): #{outfile}"
131
+ end
132
+
133
+ def handle_results test_text, run, time_taken
134
+ @total_time = @total_time + time_taken
135
+
136
+ say "Ran #{test_text}"
137
+ say "=> Duration: #{time_taken}"
138
+
139
+ if @autobench.send(run).thresholds?
140
+ say "=> Successes:"
141
+ say @autobench.send(run).successes
142
+
143
+ say "=> Failures:"
144
+ say @autobench.send(run).failures
145
+
146
+ if @autobench.send(run).passed?
147
+ say "=> PASS!"
148
+ else
149
+ @exit_status = @exit_status + 1
150
+ say "=> FAIL!"
151
+ end
152
+ end
153
+ dump(run)
154
+ say " "
155
+ end
156
+
157
+ # action
158
+ @autobench = Autobench.new(options.delete("config"), options)
159
+ @exit_status = 0
160
+ @total_time = 0
161
+
162
+ { :render => "Render (httperf)",
163
+ :yslow => "YSlow (yslow.js)",
164
+ :client => "Client (phantomas)"
165
+ }.each do |run, desc|
166
+ if benchmarks[run]
167
+ render_time = Benchmark.realtime do
168
+ @autobench.send(run).benchmark
169
+ end
170
+ handle_results(desc, run, render_time)
171
+ end
172
+ end
173
+
174
+ say "Complete!"
175
+ say "=> Duration: #{@total_time}"
176
+ say "=> #{(@exit_status == 0 ? "Success" : "Failure")}!"
177
+
178
+ exit @exit_status
179
+
180
+ # vim: ft=ruby
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+
4
+ ################################################################################
5
+ # Really, Autobench was designed to be hooked up to test frameworks,
6
+ # however, here's a hacky/ugly script to run it via command line.
7
+ ################################################################################
8
+
9
+ require 'optparse'
10
+ require 'yaml'
11
+ require 'benchmark'
12
+ require 'autobench'
13
+
14
+ # opts
15
+ options = {
16
+ "server" => "localhost",
17
+ "port" => 80,
18
+ "uri" => "/",
19
+ "runs" => 9
20
+ }
21
+ benchmarks = {
22
+ # defaults
23
+ :render => true,
24
+ :yslow => true,
25
+ :client => true
26
+ }
27
+ optparser = OptionParser.new do |opts|
28
+ opts.banner = "Usage: autobench-config [options]"
29
+
30
+ opts.separator ""
31
+ opts.separator "Required Arguments:"
32
+
33
+ opts.on("-o", "--output FILENAME", "configuration output file") do |p|
34
+ @output = p
35
+ end
36
+
37
+ opts.separator ""
38
+ opts.separator "Optional Arguments:"
39
+ opts.separator ""
40
+ opts.separator " Note: server, port, uri and runs overide defaults:"
41
+ opts.separator " - server: 'localhost'"
42
+ opts.separator " - port: 80"
43
+ opts.separator " - uri: '/'"
44
+ opts.separator " - runs: 9"
45
+ opts.separator ""
46
+
47
+
48
+ opts.on("-s", "--server SERVER", "target server") do |p|
49
+ options["server"] = p
50
+ end
51
+
52
+ opts.on("-p", "--port PORT", Integer, "target port") do |p|
53
+ options["port"] = p
54
+ end
55
+
56
+ opts.on("-u", "--uri URI", "target uri") do |p|
57
+ options["uri"] = p
58
+ end
59
+
60
+ opts.on("-i", "--runs RUNS", Integer, "itterations against target") do |p|
61
+ options["runs"] = p
62
+ end
63
+
64
+ opts.separator ""
65
+ opts.separator "Module Exclusion:"
66
+ opts.on("-R", "--without-render", "Do not include render (httperf).") do
67
+ benchmarks[:render] = false
68
+ end
69
+
70
+ opts.on("-Y", "--without-yslow", "Do not include yslow (yslow.js).") do
71
+ benchmarks[:yslow] = false
72
+ end
73
+
74
+ opts.on("-C", "--without-client", "Do not include client (phantomas).") do
75
+ benchmarks[:client] = false
76
+ end
77
+
78
+ opts.separator ""
79
+ opts.separator "Misc. Arguments:"
80
+
81
+ opts.on("-h", "--help", "Show this message") do
82
+ puts opts
83
+ exit
84
+ end
85
+ end
86
+ optparser.parse!
87
+
88
+ unless defined?(@output)
89
+ puts optparser
90
+ exit
91
+ end
92
+
93
+ def say msg
94
+ puts msg
95
+ end
96
+
97
+ # utils
98
+
99
+ def dump_data
100
+ File.open(@output, "w") do |f|
101
+ f.write(@data.to_yaml)
102
+ end
103
+ say "=> Results: #{@output}"
104
+ end
105
+
106
+ def handle_results test_text, run, time_taken
107
+ @total_time = @total_time + time_taken
108
+
109
+ say "Collected data: #{test_text}"
110
+ say "=> Duration: #{time_taken}"
111
+ say " "
112
+
113
+ if run == :yslow
114
+ @data["thresholds"]["yslow"] = @autobench.yslow.full_results.inject({}){ |memo,(k,v)| memo[ @autobench.yslow.mappings.select { |key, val| val == k }.keys.first ] = v; memo }
115
+ else
116
+ @data["thresholds"][run.to_s] = @autobench.send(run).full_results
117
+ end
118
+
119
+ end
120
+
121
+ # action
122
+ @autobench = Autobench.new(options)
123
+ @exit_status = 0
124
+ @total_time = 0
125
+
126
+ @data = options.merge({
127
+ "thresholds" => {
128
+ "render" => {},
129
+ "yslow" => {},
130
+ "client" => {}
131
+ }
132
+ })
133
+
134
+ %w[ phantomjs node httperf ].each do |bin_name|
135
+ if (bin_path = %x{which #{bin_name}}.strip) && bin_path != ""
136
+ @data["paths"] ||= {}
137
+ @data["paths"][bin_name] = bin_path
138
+ else
139
+ say "WARNING: #{bin_name} not found."
140
+ end
141
+ end
142
+
143
+ { :render => "Render (httperf)",
144
+ :yslow => "YSlow (yslow.js)",
145
+ :client => "Client (phantomas)"
146
+ }.each do |run, desc|
147
+ if benchmarks[run]
148
+ render_time = Benchmark.realtime do
149
+ @autobench.send(run).benchmark
150
+ end
151
+ handle_results(desc, run, render_time)
152
+ end
153
+ end
154
+
155
+ dump_data
156
+
157
+ say "Complete!"
158
+ say "=> Duration: #{@total_time}"
159
+
160
+ exit
161
+
162
+ # vim: ft=ruby