From 862eee701a300ee7d4adbae5266179fa7e6a333c Mon Sep 17 00:00:00 2001 From: ywenc Date: Thu, 9 Jan 2025 10:07:15 -0500 Subject: [PATCH 1/2] Separate samples_by_file and formatting --- lib/vernier/output/file_listing.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/vernier/output/file_listing.rb b/lib/vernier/output/file_listing.rb index cd0ca4e..b85d830 100644 --- a/lib/vernier/output/file_listing.rb +++ b/lib/vernier/output/file_listing.rb @@ -23,9 +23,7 @@ def initialize(profile) @profile = profile end - def output - output = +"" - + def samples_by_file thread = @profile.main_thread if Hash === thread # live profile @@ -76,6 +74,10 @@ def output samples_by_file.transform_keys! do |filename| filename_filter.call(filename) end + end + + def output + output = +"" relevant_files = samples_by_file.select do |k, v| next if k.start_with?("gem:") @@ -92,6 +94,18 @@ def output output << "="*80 << "\n" end + def total + thread = @profile.main_thread + if Hash === thread + # live profile + weights = thread[:weights] + else + weights = thread.weights + end + + weights.sum + end + def format_file(output, filename, all_samples, total:) samples = all_samples[filename] From a95a6c8fd53eff750b0499fe2dc4f91dfa7c0c58 Mon Sep 17 00:00:00 2001 From: ywenc Date: Tue, 21 Jan 2025 18:27:02 -0500 Subject: [PATCH 2/2] Use [] access for both types of threads Co-authored-by: jhawthorn --- lib/vernier/output/file_listing.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/vernier/output/file_listing.rb b/lib/vernier/output/file_listing.rb index b85d830..4c80d22 100644 --- a/lib/vernier/output/file_listing.rb +++ b/lib/vernier/output/file_listing.rb @@ -28,16 +28,15 @@ def samples_by_file if Hash === thread # live profile stack_table = @profile._stack_table - weights = thread[:weights] - samples = thread[:samples] filename_filter = FilenameFilter.new else stack_table = thread.stack_table - weights = thread.weights - samples = thread.samples filename_filter = ->(x) { x } end + weights = thread[:weights] + samples = thread[:samples] + self_samples_by_frame = Hash.new do |h, k| h[k] = SamplesByLocation.new end @@ -96,14 +95,7 @@ def output def total thread = @profile.main_thread - if Hash === thread - # live profile - weights = thread[:weights] - else - weights = thread.weights - end - - weights.sum + thread[:weights].sum end def format_file(output, filename, all_samples, total:)