sass-prof 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/lib/sass/prof/version.rb +5 -0
- data/lib/sass/prof.rb +150 -0
- data/sass-prof.gemspec +23 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8c7227a6056e4190559289cce3732ac60bd1e77
|
4
|
+
data.tar.gz: 7fd772926246efbb3fabd0860e5ab27029bb3a87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b0e1399f9afb14770220663071b66639bc3dc1d1971d6fe5fbb43b817eec7bb19161d86a5895decef3d5abc75f08bd767e253bbd9e8f24744bf4a2eef53fad6
|
7
|
+
data.tar.gz: 2e69778738c3402045b91e0c652059f6f8277fc9d2a963eb777bf6f757776d50b0dcbabd65891c9d370a072bae815222d25c8aa396857a3f4a9c2cd0c864dd48
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +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.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
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. 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
|
+
# Mutes all output to stdout
|
35
|
+
# Default is `false`
|
36
|
+
prof.quiet = true
|
37
|
+
|
38
|
+
# Maximum execution time allowed in ms
|
39
|
+
# Default is `100`
|
40
|
+
prof.t_max = 500
|
41
|
+
|
42
|
+
# Enable colored output
|
43
|
+
# Default is `true`
|
44
|
+
prof.color = true
|
45
|
+
```
|
46
|
+
|
47
|
+
_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)._
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/[my-github-username]/sass-prof/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/sass/prof.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require "sass/prof/version"
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Prof
|
5
|
+
|
6
|
+
class Profiler
|
7
|
+
attr_accessor :config, :function, :action, :args, :env
|
8
|
+
|
9
|
+
@@t_then = Time.now
|
10
|
+
@@t_now = Time.now
|
11
|
+
|
12
|
+
def initialize(function, action, args = nil, env = nil)
|
13
|
+
@config = Sass::Prof::Config
|
14
|
+
@function = function
|
15
|
+
@action = action
|
16
|
+
@args = args
|
17
|
+
@env = env
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_report
|
21
|
+
report = to_table [fn_source, fn_execution_time, fn_action,
|
22
|
+
fn_signature]
|
23
|
+
|
24
|
+
puts report unless config.quiet
|
25
|
+
|
26
|
+
if config.output_file
|
27
|
+
File.open(config.output_file, "a+") { |f|
|
28
|
+
f.puts report.gsub /\e\[(\d+)(;\d+)*m/, "" }
|
29
|
+
end
|
30
|
+
|
31
|
+
if @@t_total > config.t_max && action == :execute
|
32
|
+
puts colorize "Max execution time of #{config.t_max}ms reached for"\
|
33
|
+
" function `#{fn_name}` (took #{@@t_total.round(3)}ms)", :red
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def fn_execution_time
|
41
|
+
@@t_now = Time.now
|
42
|
+
|
43
|
+
t_delta = (@@t_now.to_f - @@t_then.to_f) * 1000.0
|
44
|
+
|
45
|
+
@@t_then, @@t_total = @@t_now, t_delta
|
46
|
+
|
47
|
+
color = @@t_total > config.t_max ? :red : :green
|
48
|
+
colorize t_delta.to_s, color
|
49
|
+
end
|
50
|
+
|
51
|
+
def fn_name
|
52
|
+
case
|
53
|
+
when function.respond_to?(:name)
|
54
|
+
function.name
|
55
|
+
else
|
56
|
+
"unknown function"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def fn_args
|
61
|
+
return nil if args.nil?
|
62
|
+
|
63
|
+
args.to_s[1...args.length-2]
|
64
|
+
end
|
65
|
+
|
66
|
+
def fn_source
|
67
|
+
return colorize("unknown file", :red).ljust 80 unless env
|
68
|
+
|
69
|
+
orig_filename = env.options.fetch :original_filename, "unknown file"
|
70
|
+
filename = env.options.fetch :filename, "unknown file"
|
71
|
+
|
72
|
+
colorize "#{File.basename(orig_filename)}:#{File.basename(filename)}",
|
73
|
+
:yellow
|
74
|
+
end
|
75
|
+
|
76
|
+
def fn_action
|
77
|
+
colorize action.to_s, :yellow
|
78
|
+
end
|
79
|
+
|
80
|
+
def fn_signature
|
81
|
+
colorize(fn_name, :blue) << "(" << colorize(fn_args, :purple) << ")"
|
82
|
+
end
|
83
|
+
|
84
|
+
def colorize(string, color)
|
85
|
+
return string unless config.color
|
86
|
+
|
87
|
+
colors = Hash.new("37").merge({
|
88
|
+
:black => "30",
|
89
|
+
:red => "31",
|
90
|
+
:green => "32",
|
91
|
+
:yellow => "33",
|
92
|
+
:blue => "34",
|
93
|
+
:purple => "35",
|
94
|
+
:cyan => "36",
|
95
|
+
:white => "37",
|
96
|
+
})
|
97
|
+
|
98
|
+
"\e[0;#{colors.fetch(color)}m#{string}\e[0m"
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_table(columns, cs = 12)
|
102
|
+
"[ %s ]" % columns.map { |col| "%#{cs}s" % col }.join(" | ")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
module Config
|
107
|
+
attr_accessor :t_max, :output_file, :quiet, :color
|
108
|
+
|
109
|
+
def t_max
|
110
|
+
@t_max ||= 100
|
111
|
+
end
|
112
|
+
|
113
|
+
def output_file
|
114
|
+
@output_file = false if @output_file.nil?
|
115
|
+
@output_file
|
116
|
+
end
|
117
|
+
|
118
|
+
def quiet
|
119
|
+
@quiet = false if @quiet.nil?
|
120
|
+
@quiet
|
121
|
+
end
|
122
|
+
|
123
|
+
def color
|
124
|
+
@color = true if @color.nil?
|
125
|
+
@color
|
126
|
+
end
|
127
|
+
|
128
|
+
extend self
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class Tree::Visitors::Perform
|
133
|
+
alias_method :_visit_function, :visit_function
|
134
|
+
|
135
|
+
def visit_function(node)
|
136
|
+
Sass::Prof::Profiler.new(node.dup, :declare).print_report
|
137
|
+
_visit_function node
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class Script::Tree::Funcall
|
142
|
+
alias_method :_perform_sass_fn, :perform_sass_fn
|
143
|
+
|
144
|
+
def perform_sass_fn(function, args, splat, environment)
|
145
|
+
Sass::Prof::Profiler.new(function.dup, :execute, args.dup,
|
146
|
+
environment.dup).print_report
|
147
|
+
_perform_sass_fn function, args, splat, environment
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/sass-prof.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sass/prof/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sass-prof"
|
8
|
+
spec.version = Sass::Prof::VERSION
|
9
|
+
spec.authors = ["ezekg"]
|
10
|
+
spec.email = ["ezekg@yahoo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Profiler for Sass libraries.}
|
13
|
+
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.}
|
14
|
+
spec.homepage = "https://github.com/ezekg/sass-prof"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_dependency "sass", "~> 3.4"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sass-prof
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ezekg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description: Sass Prof is a code profiler for Sass. For each function, Sass Prof will
|
56
|
+
show the execution time for the function, which file called it and what arguments
|
57
|
+
were given when the function was called.
|
58
|
+
email:
|
59
|
+
- ezekg@yahoo.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- .rspec
|
66
|
+
- .travis.yml
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/sass/prof.rb
|
72
|
+
- lib/sass/prof/version.rb
|
73
|
+
- sass-prof.gemspec
|
74
|
+
homepage: https://github.com/ezekg/sass-prof
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Profiler for Sass libraries.
|
98
|
+
test_files: []
|