log_analyzer 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile +1 -0
 - data/Gemfile.lock +2 -2
 - data/README.md +6 -2
 - data/bin/log_analyzer +13 -2
 - data/lib/log_analyzer/analyzer.rb +33 -16
 - data/lib/log_analyzer/configuration.rb +47 -0
 - data/lib/log_analyzer/stat.rb +3 -2
 - data/lib/log_analyzer/version.rb +1 -1
 - data/lib/log_analyzer.rb +1 -0
 - metadata +2 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4d42a245ae56e949f0059dcb0cde4aa5f89dca03
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a069aa6274eb4c632ab1a27a0290e9de2ba53e7f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 46e10a656b85cef9074279beb4005c89e2f428de3309c1d0f3eadccd1ddcab9c9a30355a9a896347864dd15e16dc3342b4ac7c9030077163fd927bf24386cb33
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 721bac1c7f168b31b302f42a9e5d39c6f864d9ad56606145a78c9c5a075b84c04c026c235f7eb9c3024ec824c5a6063ec439c4ebd3e1ce9834abe3f5c5655baf
         
     | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        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] 
     | 
| 
       31 
     | 
    
         
            -
            options[:sort] 
     | 
| 
      
 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 
     | 
    
         
            -
                         
     | 
| 
       24 
     | 
    
         
            -
                        @stats[ 
     | 
| 
      
 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 
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                 
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                   
     | 
| 
       64 
     | 
    
         
            -
                     
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
    
        data/lib/log_analyzer/stat.rb
    CHANGED
    
    
    
        data/lib/log_analyzer/version.rb
    CHANGED
    
    
    
        data/lib/log_analyzer.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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
         
     |