super_profile 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cucumber/formatter/super_profile.rb +81 -0
- data/lib/rspec/super_profile.rb +80 -0
- data/lib/super_profile.rb +12 -0
- metadata +59 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'cucumber/formatter/io'
|
2
|
+
require 'cucumber/formatter/progress'
|
3
|
+
|
4
|
+
module Cucumber
|
5
|
+
module Formatter
|
6
|
+
class SuperProfile < Cucumber::Formatter::Progress
|
7
|
+
|
8
|
+
include Cucumber::Formatter::Io
|
9
|
+
|
10
|
+
attr_reader :step_mother
|
11
|
+
|
12
|
+
def initialize(step_mother, path_or_io, options)
|
13
|
+
super
|
14
|
+
@example_times = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def before_features(features)
|
18
|
+
top = (SHOW_TOP==-1 ? 'all' : "top #{SHOW_TOP}")
|
19
|
+
@io.print "Super Profiling enabled: show #{top} tests > #{SHOW_ABOVE} seconds.\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
def before_steps(*args)
|
23
|
+
super
|
24
|
+
@time = Time.now
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_steps(*args)
|
28
|
+
super
|
29
|
+
my_time = Time.now - @time
|
30
|
+
|
31
|
+
@example_times << [
|
32
|
+
!@exception_raised,
|
33
|
+
@scenario[:file_colon_line],
|
34
|
+
@scenario[:name],
|
35
|
+
Time.now - @time
|
36
|
+
] if @scenario
|
37
|
+
|
38
|
+
# @io.print "feature took #{my_time}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def scenario_name(keyword, name, file_colon_line, source_indent)
|
42
|
+
@scenario = {name: name, file_colon_line: file_colon_line}
|
43
|
+
end
|
44
|
+
|
45
|
+
def after_features(features)
|
46
|
+
super
|
47
|
+
dump_example_times
|
48
|
+
dump_file_times
|
49
|
+
@io.flush
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def dump_example_times
|
55
|
+
@io.print "\n\nSuperProfile Report:\n"
|
56
|
+
sorted_by_time(@example_times)[0..SHOW_TOP].each do |passed, loc, desc, time|
|
57
|
+
@io.print "#{sprintf("%.3f", time)}s\t#{loc}\t#{desc} #{'FAIL' unless passed}\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def dump_file_times
|
62
|
+
@io.print "\n\nFiles:\n"
|
63
|
+
|
64
|
+
file_times = Hash.new(0)
|
65
|
+
@example_times.each do |passed, loc, desc, time|
|
66
|
+
file_times[loc.split(':').first]+=time
|
67
|
+
end
|
68
|
+
|
69
|
+
sorted_by_time(file_times).each do |file, time|
|
70
|
+
@io.print "#{sprintf("%.3f", time)}s\t#{file}\n"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#sorted by last ascending, reject beyond limit
|
75
|
+
def sorted_by_time(times)
|
76
|
+
times.to_a.sort_by{|x| x.last}.reverse.reject{|x| x.last < SHOW_ABOVE}
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rspec/core/formatters/base_formatter' # for relative_path
|
2
|
+
require 'rspec/core/formatters/progress_formatter'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
class SuperProfile < RSpec::Core::Formatters::ProgressFormatter
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@example_times = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def start(*args)
|
13
|
+
top = (SHOW_TOP==-1 ? 'all' : "top #{SHOW_TOP}")
|
14
|
+
@output.puts "Super Profiling enabled: top #{top} tests > #{SHOW_ABOVE} seconds."
|
15
|
+
end
|
16
|
+
|
17
|
+
def example_started(*args)
|
18
|
+
@time = Time.now
|
19
|
+
end
|
20
|
+
|
21
|
+
def example_passed(example)
|
22
|
+
super
|
23
|
+
@example_times << [
|
24
|
+
true,
|
25
|
+
# RSpec::Core::Formatters::BaseFormatter.relative_path(example.location),
|
26
|
+
RSpec::Core::Metadata::relative_path(example.location),
|
27
|
+
example.description,
|
28
|
+
Time.now - @time
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def example_failed(example)
|
33
|
+
super
|
34
|
+
@example_times << [
|
35
|
+
false,
|
36
|
+
# RSpec::Core::Formatters::BaseFormatter.relative_path(example.location),
|
37
|
+
RSpec::Core::Metadata::relative_path(example.location),
|
38
|
+
example.description,
|
39
|
+
Time.now - @time
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
# improve upon this....
|
44
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
45
|
+
super(duration, example_count, failure_count, pending_count)
|
46
|
+
|
47
|
+
dump_example_times
|
48
|
+
dump_file_times
|
49
|
+
@output.flush
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def dump_example_times
|
55
|
+
@output.puts "\nSuperProfile Report:\n"
|
56
|
+
sorted_by_time(@example_times)[0..SHOW_TOP].each do |passed, loc, desc, time|
|
57
|
+
@output.puts "#{cyan(sprintf("%.3f", time))}s\t#{loc}\t#{desc} #{red('FAIL') unless passed}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def dump_file_times
|
62
|
+
@output.puts "\n\nFiles:\n"
|
63
|
+
|
64
|
+
file_times = Hash.new(0)
|
65
|
+
@example_times.each do |passed, loc, desc, time|
|
66
|
+
file_times[loc.split(':').first]+=time
|
67
|
+
end
|
68
|
+
|
69
|
+
sorted_by_time(file_times).each do |file, time|
|
70
|
+
@output.puts "#{green(sprintf("%.3f", time))}s\t#{file}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#sorted by last ascending, reject beyond limit
|
75
|
+
def sorted_by_time(times)
|
76
|
+
times.to_a.sort_by{|x| x.last}.reverse.reject{|x| x.last < SHOW_ABOVE}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
SHOW_TOP ||= (ENV['PROFILE_SHOW_TOP'] || -1).to_i # only show the x
|
3
|
+
SHOW_ABOVE ||= (ENV['PROFILE_SHOW_MIN'] || 0.1).to_f # only show examples that take longer than x seconds
|
4
|
+
|
5
|
+
require 'cucumber/formatter/super_profile'
|
6
|
+
require 'rspec/super_profile'
|
7
|
+
|
8
|
+
require 'cucumber/cli/options'
|
9
|
+
Cucumber::Cli::Options::BUILTIN_FORMATS["SuperProfile"] = [
|
10
|
+
"Cucumber::Formatter::SuperProfile",
|
11
|
+
"Extended profile for Cucumber"
|
12
|
+
]
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: super_profile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Mishkin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec-core
|
16
|
+
requirement: &70118534455560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70118534455560
|
25
|
+
description: enhanced speed profile formatter for rspec and cucumber
|
26
|
+
email:
|
27
|
+
- bmishkin@mac.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/cucumber/formatter/super_profile.rb
|
33
|
+
- lib/rspec/super_profile.rb
|
34
|
+
- lib/super_profile.rb
|
35
|
+
homepage: https://github.com/bmishkin/super_profile
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.10
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: enhanced speed profile formatter for rspec and cucumber
|
59
|
+
test_files: []
|