File: memory.rake

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

namespace :check do
  desc "Analyse the memory profile of Rouge"
  task :memory do
    require 'memory_profiler'

    dir = Rake.application.original_dir
    source = File.expand_path('lib/rouge/lexer.rb', dir)
    sample = File.read(source, encoding: 'utf-8')
    report = MemoryProfiler.report do
      require 'rouge'
      formatter  = Rouge::Formatters::HTML.new
      ruby_lexer = Rouge::Lexers::Ruby.new
      guessed_lexer = Rouge::Lexer.find_fancy('guess', sample)
      formatter.format ruby_lexer.lex(sample)
      formatter.format guessed_lexer.lex(sample)
    end

    if ENV['CI']
      report.pretty_print(scale_bytes: true, normalize_paths: true)
    else
      results_file = File.expand_path('rouge-memory.tmp', dir)
      t_allocated = report.scale_bytes(report.total_allocated_memsize)
      t_retained  = report.scale_bytes(report.total_retained_memsize)
      puts
      puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
      puts "Total retained:  #{t_retained} (#{report.total_retained} objects)"
      report.pretty_print(to_file: results_file, scale_bytes: true, normalize_paths: true)
      puts
      puts "Detailed report saved to file: #{results_file}"
    end
  end
end

CLOBBER << File.expand_path('rouge-memory.tmp', Rake.application.original_dir)