File: profile.rake

package info (click to toggle)
jekyll 4.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,356 kB
  • sloc: ruby: 16,765; javascript: 1,455; sh: 214; xml: 29; makefile: 9
file content (57 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require "jekyll"

namespace :profile do
  desc "Profile allocations from a build session"
  task :memory, [:file, :mode] do |_t, args|
    args.with_defaults(file: "memprof.txt", mode: "lite")

    build_phases = [:reset, :read, :generate, :render, :cleanup, :write]
    safe_mode    = false

    if args.mode == "lite"
      build_phases -= [:render, :generate]
      safe_mode     = true
    end

    require "memory_profiler"

    report = MemoryProfiler.report do
      site = Jekyll::Site.new(
        Jekyll.configuration(
          "source"      => File.expand_path("../docs", __dir__),
          "destination" => File.expand_path("../docs/_site", __dir__),
          "safe"        => safe_mode
        )
      )

      Jekyll.logger.info "Source:", site.source
      Jekyll.logger.info "Destination:", site.dest
      Jekyll.logger.info "Plugins and Cache:", site.safe ? "disabled" : "enabled"
      Jekyll.logger.info "Profiling phases:", build_phases.join(", ").cyan
      Jekyll.logger.info "Profiling..."

      build_phases.each { |phase| site.send phase }

      Jekyll.logger.info "", "and done. Generating results.."
      Jekyll.logger.info ""
    end

    if ENV["CI"]
      report.pretty_print(scale_bytes: true, color_output: false, normalize_paths: true)
    else
      FileUtils.mkdir_p("tmp")
      report_file = File.join("tmp", args.file)

      total_allocated_output = report.scale_bytes(report.total_allocated_memsize)
      total_retained_output  = report.scale_bytes(report.total_retained_memsize)

      Jekyll.logger.info "Total allocated: #{total_allocated_output} (#{report.total_allocated} objects)".cyan
      Jekyll.logger.info "Total retained:  #{total_retained_output} (#{report.total_retained} objects)".cyan

      report.pretty_print(to_file: report_file, scale_bytes: true, normalize_paths: true)
      Jekyll.logger.info "\nDetailed Report saved into:", report_file.cyan
    end
  end
end