-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and make file listing work for live
- Loading branch information
Showing
6 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Vernier | ||
module Output | ||
class FilenameFilter | ||
def initialize | ||
@pwd = "#{Dir.pwd}/" | ||
@gem_regex = %r{\A#{Regexp.union(Gem.path)}/gems/} | ||
@gem_match_regex = %r{\A#{Regexp.union(Gem.path)}/gems/([a-zA-Z](?:[a-zA-Z0-9\.\_]|-[a-zA-Z])*)-([0-9][0-9A-Za-z\-_\.]*)/(.*)\z} | ||
@rubylibdir = "#{RbConfig::CONFIG["rubylibdir"]}/" | ||
end | ||
|
||
attr_reader :pwd, :gem_regex, :gem_match_regex, :rubylibdir | ||
|
||
def call(filename) | ||
if filename.match?(gem_regex) | ||
gem_match_regex =~ filename | ||
"gem:#$1-#$2:#$3" | ||
elsif filename.start_with?(pwd) | ||
filename.delete_prefix(pwd) | ||
elsif filename.start_with?(rubylibdir) | ||
path = filename.delete_prefix(rubylibdir) | ||
"rubylib:#{RUBY_VERSION}:#{path}" | ||
else | ||
filename | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class TestOutputFileListing < Minitest::Test | ||
def test_complex_profile | ||
result = Vernier.trace do | ||
# Proper Ruby sleep | ||
sleep 0.01 | ||
|
||
# Sleep inside rb_thread_call_without_gvl | ||
GVLTest.sleep_without_gvl(0.01) | ||
|
||
# Sleep with GVL held | ||
GVLTest.sleep_holding_gvl(0.01) | ||
|
||
# Ruby busy sleep | ||
target = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 0.01 | ||
while Process.clock_gettime(Process::CLOCK_MONOTONIC) < target | ||
end | ||
end | ||
|
||
output = Vernier::Output::FileListing.new(result).output | ||
assert_match(/\d+\.\d% \| *\d\.\d% \| *\d+ +sleep 0\.01/, output) | ||
assert_match(/\d+\.\d% \| *\d\.\d% \| *\d+ +GVLTest\.sleep_without_gvl/, output) | ||
assert_match(/\d+\.\d% \| *\d\.\d% \| *\d+ +GVLTest\.sleep_holding_gvl/, output) | ||
assert_match(/\d+\.\d% \| *\d\.\d% \| *\d+ +while Process\.clock_gettime/, output) | ||
end | ||
|
||
def test_parsed_profile | ||
profile = Vernier::ParsedProfile.read_file(fixture_path("gvl_sleep.vernier.json")) | ||
output = Vernier::Output::FileListing.new(profile).output | ||
assert_includes output, <<TEXT | ||
24.8% | 0.0% | 44 run(:cfunc_sleep_gvl) | ||
24.7% | 0.0% | 45 run(:cfunc_sleep_idle) | ||
24.6% | 0.0% | 46 run(:ruby_sleep_gvl) | ||
24.7% | 0.0% | 47 run(:sleep_idle) | ||
TEXT | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters