log_analyzer 0.1.6 → 0.2.0

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: 2a7d0498d34ec406651952a710ae56890b702554
4
- data.tar.gz: 95431b32fd3962ee0e02e81865bc6bdc827bc459
3
+ metadata.gz: 4d42a245ae56e949f0059dcb0cde4aa5f89dca03
4
+ data.tar.gz: a069aa6274eb4c632ab1a27a0290e9de2ba53e7f
5
5
  SHA512:
6
- metadata.gz: f0ec3c9d14dd5c3555fba87638445100bddf5b23fc7c8a1e0146c2efd66cb9df6647ec595db67064ac7094d0621bb973f47725e324d7828b08a9e8f934528851
7
- data.tar.gz: 3d2246398ab3fb555fa6f6c941d0d4a78ab8ff9bd46cb0b63b55eae3eb4abaeab1cb8595b8ce2614b1feb59a4a10e340cb0c61b26fae7e71836a59066b90f394
6
+ metadata.gz: 46e10a656b85cef9074279beb4005c89e2f428de3309c1d0f3eadccd1ddcab9c9a30355a9a896347864dd15e16dc3342b4ac7c9030077163fd927bf24386cb33
7
+ data.tar.gz: 721bac1c7f168b31b302f42a9e5d39c6f864d9ad56606145a78c9c5a075b84c04c026c235f7eb9c3024ec824c5a6063ec439c4ebd3e1ce9834abe3f5c5655baf
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'simplecov', require: false, group: :test
7
+ gem 'rspec'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_analyzer (0.1.6)
4
+ log_analyzer (0.2.0)
5
5
  colorize
6
6
  rake
7
7
  terminal-table
@@ -50,7 +50,7 @@ DEPENDENCIES
50
50
  bundler (> 1.14)
51
51
  log_analyzer!
52
52
  pry
53
- rspec (~> 3.0)
53
+ rspec
54
54
  simplecov
55
55
 
56
56
  BUNDLED WITH
data/README.md CHANGED
@@ -8,13 +8,13 @@ See how fast is rendering in your Ruby on Rails app. Based on information from l
8
8
 
9
9
  You can see columns:
10
10
 
11
+ * Type - type of file (partial or view = P or V)
11
12
  * View - name of view
12
13
  * Count - number of renders
13
14
  * Avg - average time of rendering (in milliseconds)
14
15
  * Max - maximum time of rendering
15
16
  * Min - minimum time of rendering
16
17
 
17
-
18
18
  ## Installation
19
19
 
20
20
  Could be installed as standalone (without adding to Gemfile).
@@ -41,8 +41,12 @@ Samples:
41
41
  * `log_analyzer log/development.log -s count`
42
42
  * `log_analyzer log/production.log`
43
43
  * `log_analyzer -f log/production.log -s name`
44
- * `log_analyzer -f log/production.log -s time`
44
+ * `log_analyzer -f log/production.log -s time -f v`
45
45
  * `log_analyzer -file log/production.log -sort count`
46
+ * `log_analyzer -file log/production.log -sort count -filter view`
47
+ * `log_analyzer -file log/production.log -sort count -filter partial`
48
+ * `log_analyzer -file log/production.log -sort time -filter P`
49
+ * `log_analyzer --help`
46
50
 
47
51
  **Based on results you can get an idea what to optimize. For example optimizing most often rendering view could give huge benefit. Now with this tool you can find out what are the numbers.**
48
52
 
data/bin/log_analyzer CHANGED
@@ -19,6 +19,10 @@ parser = OptionParser.new do |opts|
19
19
  options[:sort] = v
20
20
  end
21
21
 
22
+ opts.on("-f filter", "--filter=all", "Select filter: all/partial/view. Default: all") do |v|
23
+ options[:filter] = v
24
+ end
25
+
22
26
  opts.on('-h', '--help', 'Displays Help') do
23
27
  puts opts
24
28
  exit
@@ -27,8 +31,15 @@ end
27
31
 
28
32
  parser.parse!
29
33
 
30
- options[:file] = ARGV[0] if ARGV.size == 1
31
- options[:sort] ||= :time # default order
34
+ options[:file] = ARGV[0] if ARGV.size == 1 # user first argument as filename
35
+ options[:sort] ||= :time # default order
36
+ options[:filter] ||= :all # default order
37
+
38
+ LogAnalyzer::Configuration.configure do |config|
39
+ config.filter = options[:filter]
40
+ end
41
+
42
+ # puts "Running with: #{options.inspect}" # debug
32
43
 
33
44
  if options[:file] && options[:sort]
34
45
  analyzer = LogAnalyzer.analyze(filename: options[:file])
@@ -6,7 +6,9 @@ module LogAnalyzer
6
6
  DANGER_DEFAULT = 800 # ms
7
7
  WARNING_DEFAULT = 400 # ms
8
8
  INFO_DEFAULT = 100 # ms
9
- HEADER = ['View', 'Count', 'AVG (ms)', 'Max', 'Min'].freeze
9
+ HEADER = ['Type', 'View', 'Count', 'AVG (ms)', 'Max', 'Min'].freeze
10
+ PARTIAL_LABEL = " P ".on_green.black.freeze
11
+ VIEW_LABEL = " V ".on_yellow.black.freeze
10
12
 
11
13
  attr_reader :filename
12
14
  attr_reader :stats
@@ -20,13 +22,18 @@ module LogAnalyzer
20
22
  IO.foreach(filename).each do |line|
21
23
  if line =~ MATCHER
22
24
  if $1 && $2
23
- @stats[$1] ||= Stat.new
24
- @stats[$1].push($2)
25
+ view = $1
26
+ @stats[view] ||= Stat.new(type: find_type(view))
27
+ @stats[view].push($2)
25
28
  end
26
29
  end
27
30
  end
28
31
  end
29
32
 
33
+ def find_type(view)
34
+ view.split('/'.freeze).last[0] == '_' ? 'P'.freeze : 'V'.freeze
35
+ end
36
+
30
37
  def order(by: :time)
31
38
  case by.to_sym
32
39
  when :name
@@ -39,12 +46,15 @@ module LogAnalyzer
39
46
  end
40
47
 
41
48
  def visualize(limit: 100)
42
- length = (0..DEFAULT_TABLE_WIDTH - 20).freeze
43
- table = Terminal::Table.new \
49
+ length = (0..DEFAULT_TABLE_WIDTH - 20).freeze
50
+ filters = LogAnalyzer::Configuration.configuration.filters
51
+ table = Terminal::Table.new \
44
52
  headings: HEADER,
45
53
  width: DEFAULT_TABLE_WIDTH do |t|
46
54
  stats.each do |path, stat|
55
+ next unless filters.include?(stat.type)
47
56
  t.add_row [
57
+ type_label(stat.type),
48
58
  path[length],
49
59
  stat.count,
50
60
  avg_label(stat.avg),
@@ -58,17 +68,24 @@ module LogAnalyzer
58
68
  puts table
59
69
  end
60
70
 
61
- def avg_label(avg)
62
- str = avg.to_s
63
- if avg > DANGER_DEFAULT
64
- str.white.on_red
65
- elsif avg > WARNING_DEFAULT
66
- str.red
67
- elsif avg > INFO_DEFAULT
68
- str.yellow
69
- else
70
- str.green
71
+ private
72
+
73
+ def type_label(type)
74
+ type == LogAnalyzer::Configuration::PARTIALS ? PARTIAL_LABEL : VIEW_LABEL
71
75
  end
72
- end
76
+
77
+ def avg_label(avg)
78
+ str = avg.to_s
79
+ if avg > DANGER_DEFAULT
80
+ str.white.on_red
81
+ elsif avg > WARNING_DEFAULT
82
+ str.red
83
+ elsif avg > INFO_DEFAULT
84
+ str.yellow
85
+ else
86
+ str.green
87
+ end
88
+ end
89
+
73
90
  end
74
91
  end
@@ -0,0 +1,47 @@
1
+ module LogAnalyzer
2
+
3
+ class Configuration
4
+ ALL = 'A'.freeze # ALL
5
+ PARTIALS = 'P'.freeze # Partials
6
+ VIEWS = 'V'.freeze # Views
7
+
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ attr_accessor :filter
13
+
14
+ def initialize
15
+ @filter = ALL
16
+ end
17
+
18
+ def filter=(other)
19
+ @filter = other.upcase[0]
20
+ end
21
+
22
+ def self.configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ def self.reset
27
+ @configuration = Configuration.new
28
+ end
29
+
30
+ def self.configure
31
+ yield(configuration)
32
+ end
33
+
34
+ def filters
35
+ @filters ||= case filter
36
+ when VIEWS
37
+ [VIEWS]
38
+ when PARTIALS
39
+ [PARTIALS]
40
+ else
41
+ [PARTIALS, VIEWS]
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -1,9 +1,10 @@
1
1
  module LogAnalyzer
2
2
  class Stat
3
- attr_reader :data
3
+ attr_reader :data, :type
4
4
 
5
- def initialize
5
+ def initialize(type:)
6
6
  @data = []
7
+ @type = type
7
8
  end
8
9
 
9
10
  def push(time)
@@ -1,3 +1,3 @@
1
1
  module LogAnalyzer
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/log_analyzer.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "terminal-table"
2
2
  require "colorize"
3
3
  require "log_analyzer/version"
4
+ require "log_analyzer/configuration"
4
5
  require "log_analyzer/stat"
5
6
  require "log_analyzer/analyzer"
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -138,6 +138,7 @@ files:
138
138
  - bin/log_analyzer
139
139
  - lib/log_analyzer.rb
140
140
  - lib/log_analyzer/analyzer.rb
141
+ - lib/log_analyzer/configuration.rb
141
142
  - lib/log_analyzer/stat.rb
142
143
  - lib/log_analyzer/version.rb
143
144
  - log_analyzer.gemspec