flameboyant 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/flameboyant.rb +39 -5
- data/lib/flameboyant/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cdf0814212e66528f188fd7291cd0a4f26e1708
|
4
|
+
data.tar.gz: 096c42ed6c136de874d4bba088a2fdd12024cf69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6687511ebd6e140045c3dd39d7335476c05162dee7dcbb1a37415451dac6fafa5c0b43caa424fde0b9e3643fca4be4532d90e79e82413f3386a13e2d432b27ff
|
7
|
+
data.tar.gz: a55d206938b89414b1e01dd05b4cdc48a3ef5c0cf586442426626cfe7e477a63f7452a7b0deadd7e7955925931956738681f41051c0bc522ea569f80d2f0a553
|
data/README.md
CHANGED
@@ -27,14 +27,29 @@ Flameboyant.profile do
|
|
27
27
|
end
|
28
28
|
```
|
29
29
|
|
30
|
+
If you're profiling in development mode, we recommend turning on `cache_classes`
|
31
|
+
and `eager_load` in `RAILS_ROOT/config/environments/development.rb`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
config.cache_classes = true
|
35
|
+
config.eager_load = true
|
36
|
+
```
|
37
|
+
|
30
38
|
## `profile` Options
|
31
39
|
+ name (String, optional) :: The output file will be prefixed with this name.
|
32
40
|
+ width (Integer, optional) :: defaults to 1920.
|
33
41
|
|
34
|
-
When running
|
42
|
+
When running under Rails, SVG files are written to `Rails.root/tmp/flames`
|
35
43
|
|
36
44
|
## Installation
|
37
45
|
|
46
|
+
*Requires Perl!* This Rubygem requires Perl. Data is recorded via Ruby and
|
47
|
+
sent to a Perl script to generate the CSV. One day, maybe we'll convert the Perl
|
48
|
+
script into a Ruby or Crystal script. Until then make sure you have Perl
|
49
|
+
installed in your system. OSX already has Perl installed. If you're on another
|
50
|
+
operating system, please search online for "install Perl on YOUR_OS" to get further
|
51
|
+
instructions.
|
52
|
+
|
38
53
|
Add this line to your application's Gemfile:
|
39
54
|
|
40
55
|
```ruby
|
data/lib/flameboyant.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'flameboyant/version'
|
2
2
|
require 'ruby-prof-flamegraph'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
# rubocop:disable all
|
5
6
|
module Flameboyant
|
@@ -9,9 +10,7 @@ module Flameboyant
|
|
9
10
|
GRAPHER = File.join(__dir__, 'flamegraph.pl')
|
10
11
|
|
11
12
|
def profile(name: nil, width: 1920, &block)
|
12
|
-
|
13
|
-
|
14
|
-
RubyProf::FlameGraphPrinter
|
13
|
+
base_name = "#{name}_#{timestamp}"
|
15
14
|
|
16
15
|
block_result = nil
|
17
16
|
log 'starting profile'
|
@@ -24,8 +23,9 @@ module Flameboyant
|
|
24
23
|
|
25
24
|
FileUtils.mkdir_p(dest_dir)
|
26
25
|
|
27
|
-
dst_data = dest_dir.join("#{
|
28
|
-
dst_svg = dest_dir.join("#{
|
26
|
+
dst_data = dest_dir.join("#{base_name}.txt")
|
27
|
+
dst_svg = dest_dir.join("#{base_name}.svg")
|
28
|
+
dst_html = dest_dir.join("#{base_name}.html")
|
29
29
|
|
30
30
|
log "writing: #{dst_data}"
|
31
31
|
File.open(dst_data, 'w') do |f|
|
@@ -38,9 +38,43 @@ module Flameboyant
|
|
38
38
|
log "removing: #{dst_data}"
|
39
39
|
FileUtils.rm(dst_data)
|
40
40
|
end
|
41
|
+
# write html contents
|
42
|
+
File.open(dst_html, 'w') {|f| f << create_html_page(dst_svg)}
|
43
|
+
log "created: #{dst_html} <⌘ - Click> to open in your browser."
|
44
|
+
|
45
|
+
# return original results
|
41
46
|
block_result
|
42
47
|
end
|
43
48
|
|
49
|
+
def create_html_page(dst_svg)
|
50
|
+
basename = File.basename(dst_svg)
|
51
|
+
<<-HTML
|
52
|
+
<!DOCTYPE html>
|
53
|
+
<html>
|
54
|
+
<head>
|
55
|
+
<meta name="viewport" content="initial-scale=1">
|
56
|
+
<title>Flame: #{basename}</title>
|
57
|
+
|
58
|
+
<style type="text/css">
|
59
|
+
html, body {
|
60
|
+
padding: 0;
|
61
|
+
margin: 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
.full-width {
|
65
|
+
max-width: 100%;
|
66
|
+
width: 100%;
|
67
|
+
height: auto;
|
68
|
+
}
|
69
|
+
</style>
|
70
|
+
</head>
|
71
|
+
<body>
|
72
|
+
<object class="full-width" type="image/svg+xml" data="#{URI.encode(basename)}">Your browser does not support SVGs</object>
|
73
|
+
</body>
|
74
|
+
</html>
|
75
|
+
HTML
|
76
|
+
end
|
77
|
+
|
44
78
|
def dest_dir
|
45
79
|
if defined? Rails
|
46
80
|
Rails.root.join('tmp', 'flames')
|
data/lib/flameboyant/version.rb
CHANGED