Skip to content
Permalink
Browse files

Profile allocations from a build session (#7646)

Merge pull request 7646
  • Loading branch information...
ashmaroli authored and jekyllbot committed May 15, 2019
1 parent a430c22 commit af055b917c24a534e912c04f01975fe3354d2568
Showing with 73 additions and 4 deletions.
  1. +4 −0 .travis.yml
  2. +1 −0 Gemfile
  3. +6 −4 appveyor.yml
  4. +57 −0 rake/profile.rake
  5. +5 −0 script/memprof
@@ -19,6 +19,9 @@ matrix:
- rvm: *ruby1
env: TEST_SUITE=profile-docs
name: "Profile Docs"
- rvm: *ruby1
env: TEST_SUITE=memprof
name: "Profile Memory Allocation"
exclude:
- rvm: *jruby
env: TEST_SUITE=cucumber
@@ -42,6 +45,7 @@ after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

notifications:
email: false
slack:
secure: "\
dNdKk6nahNURIUbO3ULhA09/vTEQjK0fNbgjVjeYPEvROHgQBP1cIP3AJy8aWs8rl5Yyow4Y\
@@ -23,6 +23,7 @@ group :test do
gem "httpclient"
gem "jekyll_test_plugin"
gem "jekyll_test_plugin_malicious"
gem "memory_profiler"
gem "nokogiri", "~> 1.7"
gem "rspec"
gem "rspec-mocks"
@@ -13,16 +13,18 @@ build: off
environment:
BUNDLE_WITHOUT: "benchmark:development"
matrix:
- RUBY_FOLDER_VER: "26"
- RUBY_FOLDER_VER: "24"
TEST_SUITE: "test"
- RUBY_FOLDER_VER: "26"
TEST_SUITE: "cucumber"
TEST_SUITE: "test"
- RUBY_FOLDER_VER: "26"
TEST_SUITE: "default-site"
- RUBY_FOLDER_VER: "26"
TEST_SUITE: "profile-docs"
- RUBY_FOLDER_VER: "24"
TEST_SUITE: "test"
- RUBY_FOLDER_VER: "26"
TEST_SUITE: "memprof"
- RUBY_FOLDER_VER: "26"
TEST_SUITE: "cucumber"

install:
- SET PATH=C:\Ruby%RUBY_FOLDER_VER%-x64\bin;%PATH%
@@ -0,0 +1,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: 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)
Jekyll.logger.info "\nDetailed Report saved into:", report_file.cyan
end
end
end
@@ -0,0 +1,5 @@
#!/bin/bash

file="memprof.txt"
mode="core"
bundle exec rake profile:memory[$file,$mode]

0 comments on commit af055b9

Please sign in to comment.
You can’t perform that action at this time.