sass-prof 0.1.3 → 0.1.4

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: 9706c5174e837e59861a84bfcb42a389294ad4f7
4
- data.tar.gz: d96d5b64baec68943e213737934298165cdc2e85
3
+ metadata.gz: ce2dfa8698f694afce1ff07c805b90ab6ccd294e
4
+ data.tar.gz: ba69669106f908e26223738a3396baa42b368a87
5
5
  SHA512:
6
- metadata.gz: feda79c8f838f72d9f5cbbda3a32f8ca0c62ba393e7270a10af5682096dfeef0ebd8e243515723e37f30ce55d43b997fd51ca25b548f79b28f280cabf3b65b55
7
- data.tar.gz: 09eb5a9e5d42f729e9ed4f1ef3297bf5d8cb98097c5d3ce985493e2f51bc6a4e362e27eabf8b3affb8853ad30eb108bd09be6ca335b0e4d1609a244be3da5e7f
6
+ metadata.gz: 534e526e5b9067b6640e62692aded25f4a1193e753cfca018bf141e96e4a6add888cfa45e6cc9dbfeb87c7cbd57a883fed5067c4010c3aa3fa2dd4f9c140c70e
7
+ data.tar.gz: 74215c31a2b8a1e98e76491c29e364582ae690da2b64054a8760319ef5f0e5a393158979a27af2a9f089fea1180d0ed8430f9d6ddd60201351442f9a6093f82c
data/.gitignore CHANGED
@@ -1,9 +1,11 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ .sass-cache/
2
+ /spec/stylesheets/
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sass-prof.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sass-prof.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Ezekiel Gabrielse
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ezekiel Gabrielse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,63 +1,63 @@
1
- # Sass Prof
2
-
3
- [![Gem](https://img.shields.io/gem/v/sass-prof.svg?style=flat-square)](https://rubygems.org/gems/sass-prof)
4
-
5
- Sass Prof is a code profiler for [Sass](https://github.com/sass/sass). For each function, Sass Prof will show the execution time for the function, which file called it and what arguments were given when the function was called.
6
-
7
- ## Requirements
8
-
9
- * Sass ~> `3.4.0`
10
-
11
- ## Installation
12
-
13
- 1. Install with `gem install sass-prof`
14
- 2. If you're using Compass, add `require "sass-prof"` to your `config.rb`
15
- 3. Sass Prof will automatically run next time you compile
16
- 4. That's it!
17
-
18
- ## Uninstall
19
- 1. Remove the line `require "sass-prof"` from your `config.rb`
20
-
21
- ## Usage
22
- You may specify a few options within your `config.rb`, such as directing output to a log file.
23
-
24
- ```ruby
25
- require "sass-prof"
26
-
27
- # Instance of Sass::Prof's configuration
28
- prof = Sass::Prof::Config
29
-
30
- # Directs all output to a log file
31
- # Default is `false`
32
- prof.output_file = "sass-prof.log"
33
-
34
- # Adjust output table column width
35
- # Default is `20`
36
- prof.col_width = 40
37
-
38
- # Mutes all output to stdout
39
- # Default is `false`
40
- prof.quiet = true
41
-
42
- # Maximum execution time allowed in ms
43
- # Default is `100`
44
- prof.t_max = 500
45
-
46
- # Enable colored output
47
- # Default is `true`
48
- prof.color = true
49
- ```
50
-
51
- _Please note: your compile times **will be slower** due to the overhead of **Sass Prof**. This library was created to help you find potential bottlenecks within your code. If you find any bugs or inconsistencies, please file an [issue](https://github.com/ezekg/sass-prof/issues) or [pull request](https://github.com/ezekg/sass-prof/pulls)._
52
-
53
- ## Contributing
54
-
55
- 1. Fork it ( https://github.com/[my-github-username]/sass-prof/fork )
56
- 2. Create your feature branch (`git checkout -b my-new-feature`)
57
- 3. Commit your changes (`git commit -am 'Add some feature'`)
58
- 4. Push to the branch (`git push origin my-new-feature`)
59
- 5. Create a new Pull Request
60
-
61
- ## Todo
62
-
63
- - [ ] Support `@mixin`'s
1
+ # Sass Prof
2
+
3
+ [![Gem](https://img.shields.io/gem/v/sass-prof.svg?style=flat-square)](https://rubygems.org/gems/sass-prof)
4
+
5
+ Sass Prof is a code profiler for [Sass](https://github.com/sass/sass). For each function, Sass Prof will show the execution time for the function, which file called it and what arguments were given when the function was called.
6
+
7
+ ## Requirements
8
+
9
+ * Sass ~> `3.4.0`
10
+
11
+ ## Installation
12
+
13
+ 1. Install with `gem install sass-prof`
14
+ 2. If you're using Compass, add `require "sass-prof"` to your `config.rb`
15
+ 3. Sass Prof will automatically run next time you compile
16
+ 4. That's it!
17
+
18
+ ## Uninstall
19
+ 1. Remove the line `require "sass-prof"` from your `config.rb`
20
+
21
+ ## Usage
22
+ You may specify a few options within your `config.rb`, such as directing output to a log file.
23
+
24
+ ```ruby
25
+ require "sass-prof"
26
+
27
+ # Instance of Sass::Prof's configuration
28
+ prof = Sass::Prof::Config
29
+
30
+ # Directs all output to a log file
31
+ # Default is `false`
32
+ prof.output_file = "sass-prof.log"
33
+
34
+ # Adjust output table column width
35
+ # Default is `20`
36
+ prof.col_width = 40
37
+
38
+ # Mutes all output to stdout
39
+ # Default is `false`
40
+ prof.quiet = true
41
+
42
+ # Maximum execution time allowed in ms
43
+ # Default is `100`
44
+ prof.t_max = 500
45
+
46
+ # Enable colored output
47
+ # Default is `true`
48
+ prof.color = true
49
+ ```
50
+
51
+ _Please note: your compile times **will be slower** due to the overhead of **Sass Prof**. This library was created to help you find potential bottlenecks within your code. If you find any bugs or inconsistencies, please file an [issue](https://github.com/ezekg/sass-prof/issues) or [pull request](https://github.com/ezekg/sass-prof/pulls)._
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/ezekg/sass-prof/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
60
+
61
+ ## Todo
62
+
63
+ - [ ] Support `@mixin`'s
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1,5 +1,7 @@
1
- module Sass
2
- module Prof
3
- VERSION = "0.1.3"
4
- end
5
- end
1
+ # encoding: UTF-8
2
+
3
+ module Sass
4
+ module Prof
5
+ VERSION = "0.1.4"
6
+ end
7
+ end
data/lib/sass-prof.rb CHANGED
@@ -1,159 +1,179 @@
1
- lib = File.expand_path "../lib/", __FILE__
2
- $:.unshift lib unless $:.include? lib
3
-
4
- require "sass-prof/version"
5
-
6
- module Sass
7
- module Prof
8
-
9
- class Profiler
10
- attr_accessor :config, :function, :action, :args, :env
11
-
12
- @@t_then = Time.now
13
- @@t_now = Time.now
14
-
15
- def initialize(function, action, args = nil, env = nil)
16
- @config = Sass::Prof::Config
17
- @function = function
18
- @action = action
19
- @args = args
20
- @env = env
21
- end
22
-
23
- def print_report
24
- report = to_table [fn_source, fn_execution_time, fn_action,
25
- fn_signature]
26
-
27
- puts report unless config.quiet
28
-
29
- if config.output_file
30
- File.open(config.output_file, "a+") { |f|
31
- f.puts report.gsub /\e\[(\d+)(;\d+)*m/, "" }
32
- end
33
-
34
- if @@t_total > config.t_max && action == :execute
35
- puts colorize "Max execution time of #{config.t_max}ms reached for"\
36
- " function `#{fn_name}` (took #{@@t_total.round(3)}ms)", :red
37
- exit
38
- end
39
- end
40
-
41
- private
42
-
43
- def fn_execution_time
44
- @@t_now = Time.now
45
-
46
- t_delta = (@@t_now.to_f - @@t_then.to_f) * 1000.0
47
-
48
- @@t_then, @@t_total = @@t_now, t_delta
49
-
50
- color = @@t_total > config.t_max ? :red : :green
51
- colorize t_delta.to_s, color
52
- end
53
-
54
- def fn_name
55
- case
56
- when function.respond_to?(:name)
57
- function.name
58
- else
59
- "unknown function"
60
- end
61
- end
62
-
63
- def fn_args
64
- return nil if args.nil?
65
-
66
- args.to_s[1...args.length-2]
67
- end
68
-
69
- def fn_source
70
- return colorize("unknown file", :red) unless env
71
-
72
- orig_filename = env.options.fetch :original_filename, "unknown file"
73
- filename = env.options.fetch :filename, "unknown file"
74
-
75
- colorize "#{File.basename(orig_filename)}:#{File.basename(filename)}",
76
- :yellow
77
- end
78
-
79
- def fn_action
80
- colorize action.to_s, :yellow
81
- end
82
-
83
- def fn_signature
84
- colorize(fn_name, :blue) << "(" << colorize(fn_args, :purple) << ")"
85
- end
86
-
87
- def colorize(string, color)
88
- return string unless config.color
89
-
90
- colors = Hash.new("37").merge({
91
- :black => "30",
92
- :red => "31",
93
- :green => "32",
94
- :yellow => "33",
95
- :blue => "34",
96
- :purple => "35",
97
- :cyan => "36",
98
- :white => "37",
99
- })
100
-
101
- "\e[0;#{colors.fetch(color)}m#{string}\e[0m"
102
- end
103
-
104
- def to_table(columns)
105
- "[ %s ]" % columns.map { |col|
106
- "%-#{config.col_width}s" % col }.join(" | ")
107
- end
108
- end
109
-
110
- module Config
111
- attr_accessor :t_max, :col_width, :output_file, :quiet, :color
112
-
113
- def t_max
114
- @t_max ||= 100
115
- end
116
-
117
- def col_width
118
- @col_width = 20 if @col_width.nil?
119
- @col_width
120
- end
121
-
122
- def output_file
123
- @output_file = false if @output_file.nil?
124
- @output_file
125
- end
126
-
127
- def quiet
128
- @quiet = false if @quiet.nil?
129
- @quiet
130
- end
131
-
132
- def color
133
- @color = true if @color.nil?
134
- @color
135
- end
136
-
137
- extend self
138
- end
139
- end
140
-
141
- class Tree::Visitors::Perform
142
- alias_method :_visit_function, :visit_function
143
-
144
- def visit_function(node)
145
- Sass::Prof::Profiler.new(node.dup, :declare).print_report
146
- _visit_function node
147
- end
148
- end
149
-
150
- class Script::Tree::Funcall
151
- alias_method :_perform_sass_fn, :perform_sass_fn
152
-
153
- def perform_sass_fn(function, args, splat, environment)
154
- Sass::Prof::Profiler.new(function.dup, :execute, args.dup,
155
- environment.dup).print_report
156
- _perform_sass_fn function, args, splat, environment
157
- end
158
- end
159
- end
1
+ # encoding: UTF-8
2
+
3
+ module Sass
4
+ module Prof
5
+
6
+ class Profiler
7
+ attr_accessor :config, :function, :action, :args, :env
8
+
9
+ @@t_total = 0
10
+ @@t_then = 0
11
+ @@t_now = 0
12
+
13
+ def initialize(function, action, args = nil, env = nil)
14
+ @config = Sass::Prof::Config
15
+ @function = function
16
+ @action = action
17
+ @args = args
18
+ @env = env
19
+ end
20
+
21
+ def print_report
22
+ report = to_table [fn_source, fn_execution_time, fn_action,
23
+ fn_signature]
24
+
25
+ puts report unless config.quiet
26
+
27
+ if config.output_file
28
+ File.open(config.output_file, "a+") { |f|
29
+ f.puts report.gsub /\e\[(\d+)(;\d+)*m/, "" }
30
+ end
31
+
32
+ if @@t_total > config.t_max && action == :execute
33
+ puts colorize "Max execution time of #{config.t_max}ms reached for"\
34
+ " function `#{fn_name}` (took #{@@t_total.round(3)}ms)", :red
35
+ exit
36
+ end
37
+ end
38
+
39
+ def start
40
+ @@t_then = Time.now
41
+ end
42
+
43
+ def stop
44
+ @@t_now = Time.now
45
+ t_delta = (@@t_now.to_f - @@t_then.to_f) * 1000.0
46
+ @@t_then, @@t_total = @@t_now, t_delta
47
+ end
48
+
49
+ private
50
+
51
+ def fn_execution_time
52
+ color = @@t_total > config.t_max ? :red : :green
53
+ colorize @@t_total.to_s, color
54
+ end
55
+
56
+ def fn_name
57
+ case
58
+ when function.respond_to?(:name)
59
+ function.name
60
+ else
61
+ "unknown function"
62
+ end
63
+ end
64
+
65
+ def fn_args
66
+ return nil if args.nil?
67
+
68
+ if args.is_a? Array
69
+ args.map { |a| a.to_s }.join(", ")
70
+ else
71
+ args.to_s[1...args.length-2]
72
+ end
73
+ end
74
+
75
+ def fn_source
76
+ return colorize("unknown file", :red) unless env
77
+
78
+ orig_filename = env.options.fetch :original_filename, "unknown file"
79
+ filename = env.options.fetch :filename, "unknown file"
80
+
81
+ colorize "#{File.basename(orig_filename)}:#{File.basename(filename)}",
82
+ :yellow
83
+ end
84
+
85
+ def fn_action
86
+ colorize action.to_s, :yellow
87
+ end
88
+
89
+ def fn_signature
90
+ colorize(fn_name, :blue) << "(" << colorize(fn_args, :purple) << ")"
91
+ end
92
+
93
+ def colorize(string, color)
94
+ return string unless config.color
95
+
96
+ colors = Hash.new("37").merge({
97
+ :black => "30",
98
+ :red => "31",
99
+ :green => "32",
100
+ :yellow => "33",
101
+ :blue => "34",
102
+ :purple => "35",
103
+ :cyan => "36",
104
+ :white => "37",
105
+ })
106
+
107
+ "\e[0;#{colors.fetch(color)}m#{string}\e[0m"
108
+ end
109
+
110
+ def to_table(columns)
111
+ "[ %s ]" % columns.map { |col|
112
+ "%-#{config.col_width}s" % col }.join(" | ")
113
+ end
114
+ end
115
+
116
+ module Config
117
+ attr_accessor :t_max, :col_width, :output_file, :quiet, :color
118
+
119
+ def t_max
120
+ @t_max ||= 100
121
+ end
122
+
123
+ def col_width
124
+ @col_width = 20 if @col_width.nil?
125
+ @col_width
126
+ end
127
+
128
+ def output_file
129
+ @output_file = false if @output_file.nil?
130
+ @output_file
131
+ end
132
+
133
+ def quiet
134
+ @quiet = false if @quiet.nil?
135
+ @quiet
136
+ end
137
+
138
+ def color
139
+ @color = true if @color.nil?
140
+ @color
141
+ end
142
+
143
+ extend self
144
+ end
145
+ end
146
+
147
+ # class Tree::Visitors::Perform
148
+ # alias_method :_visit_function, :visit_function
149
+ #
150
+ # def visit_function(node)
151
+ # prof = Prof::Profiler.new(node.dup, :allocate)
152
+ # prof.start
153
+ #
154
+ # res = _visit_function node
155
+ #
156
+ # prof.stop
157
+ # prof.print_report
158
+ #
159
+ # res
160
+ # end
161
+ # end
162
+
163
+ class Script::Tree::Funcall
164
+ alias_method :_perform_sass_fn, :perform_sass_fn
165
+
166
+ def perform_sass_fn(function, args, splat, environment)
167
+ prof = Prof::Profiler.new(function.dup, :execute, args.dup,
168
+ environment.dup)
169
+ prof.start
170
+
171
+ res = _perform_sass_fn function, args, splat, environment
172
+
173
+ prof.stop
174
+ prof.print_report
175
+
176
+ res
177
+ end
178
+ end
179
+ end
data/sass-prof.gemspec CHANGED
@@ -1,25 +1,26 @@
1
- # Encoding: UTF-8
2
-
3
- lib = File.expand_path "../lib/", __FILE__
4
- $:.unshift lib unless $:.include? lib
5
-
6
- require "sass-prof/version"
7
-
8
- Gem::Specification.new do |spec|
9
- spec.name = "sass-prof"
10
- spec.version = Sass::Prof::VERSION
11
- spec.authors = ["ezekg"]
12
- spec.email = ["ezekg@yahoo.com"]
13
-
14
- spec.summary = %q{Profiler for Sass libraries.}
15
- spec.description = %q{Sass Prof is a code profiler for Sass. For each function, Sass Prof will show the execution time for the function, which file called it and what arguments were given when the function was called.}
16
- spec.homepage = "https://github.com/ezekg/sass-prof"
17
- spec.license = "MIT"
18
-
19
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.9"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_dependency "sass", "~> 3.4"
25
- end
1
+ # encoding: UTF-8
2
+
3
+ lib = File.expand_path "../lib/", __FILE__
4
+ $:.unshift lib unless $:.include? lib
5
+
6
+ require "sass-prof/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "sass-prof"
10
+ spec.version = Sass::Prof::VERSION
11
+ spec.authors = ["ezekg"]
12
+ spec.email = ["ezekg@yahoo.com"]
13
+
14
+ spec.summary = %q{Profiler for Sass libraries.}
15
+ spec.description = %q{Sass Prof is a code profiler for Sass. For each function, Sass Prof will show the execution time for the function, which file called it and what arguments were given when the function was called.}
16
+ spec.homepage = "https://github.com/ezekg/sass-prof"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "compass", "~> 1.0"
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "sass", "~> 3.4"
26
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezekg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: compass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
103
  version: '0'
90
104
  requirements: []
91
105
  rubyforge_project:
92
- rubygems_version: 2.4.6
106
+ rubygems_version: 2.0.15
93
107
  signing_key:
94
108
  specification_version: 4
95
109
  summary: Profiler for Sass libraries.