Class: Jekyll::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/profiler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Profiler

Returns a new instance of Profiler.


33
34
35
# File 'lib/jekyll/profiler.rb', line 33

def initialize(site)
  @site = site
end

Class Method Details

.tabulate(table_rows) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll/profiler.rb', line 12

def self.tabulate(table_rows)
  require "terminal-table"

  rows   = table_rows.dup
  header = rows.shift
  footer = rows.pop
  output = +"\n"

  table = Terminal::Table.new do |t|
    t << header
    t << :separator
    rows.each { |row| t << row }
    t << :separator
    t << footer
    t.style = TERMINAL_TABLE_STYLES
    t.align_column(0, :left)
  end

  output << table.to_s << "\n"
end

Instance Method Details

#profile_processObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jekyll/profiler.rb', line 37

def profile_process
  profile_data = { "PHASE" => "TIME" }
  total_time = 0

  [:reset, :read, :generate, :render, :cleanup, :write].each do |method|
    start_time = Time.now
    @site.send(method)
    end_time = (Time.now - start_time).round(4)
    profile_data[method.to_s.upcase] = format("%.4f", end_time)
    total_time += end_time
  end

  profile_data["TOTAL TIME"] = format("%.4f", total_time)

  Jekyll.logger.info "\nBuild Process Summary:"
  Jekyll.logger.info Profiler.tabulate(Array(profile_data))

  Jekyll.logger.info "\nSite Render Stats:"
  @site.print_stats
end