-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PROF-10125] Track unscaled allocation counts in allocation profiler #3770
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,14 +137,17 @@ def slot_two_mutex_locked? | |
'cpu-samples' => 'count', | ||
'wall-time' => 'nanoseconds', | ||
'alloc-samples' => 'count', | ||
'alloc-samples-unscaled' => 'count', | ||
'heap-live-samples' => 'count', | ||
'heap-live-size' => 'bytes', | ||
'timeline' => 'nanoseconds', | ||
} | ||
end | ||
|
||
def profile_types_without(type) | ||
all_profile_types.dup.tap { |it| it.delete(type) { raise 'Missing key' } } | ||
def profile_types_without(*types) | ||
result = all_profile_types.dup | ||
types.each { |type| result.delete(type) { raise 'Missing key' } } | ||
result | ||
end | ||
|
||
context 'when all profile types are enabled' do | ||
|
@@ -165,7 +168,8 @@ def profile_types_without(type) | |
let(:alloc_samples_enabled) { false } | ||
|
||
it 'returns a pprof without the alloc-samples type' do | ||
expect(sample_types_from(decoded_profile)).to eq(profile_types_without('alloc-samples')) | ||
expect(sample_types_from(decoded_profile)) | ||
.to eq(profile_types_without('alloc-samples', 'alloc-samples-unscaled')) | ||
end | ||
end | ||
|
||
|
@@ -243,7 +247,14 @@ def sample_types_from(decoded_profile) | |
|
||
context 'when profile has a sample' do | ||
let(:metric_values) do | ||
{ 'cpu-time' => 123, 'cpu-samples' => 456, 'wall-time' => 789, 'alloc-samples' => 4242, 'timeline' => 1111 } | ||
{ | ||
'cpu-time' => 123, | ||
'cpu-samples' => 456, | ||
'wall-time' => 789, | ||
'alloc-samples' => 4242, | ||
'alloc-samples-unscaled' => 2222, | ||
'timeline' => 1111, | ||
} | ||
end | ||
let(:labels) { { 'label_a' => 'value_a', 'label_b' => 'value_b', 'state' => 'unknown' }.to_a } | ||
|
||
|
@@ -258,20 +269,22 @@ def sample_types_from(decoded_profile) | |
it 'encodes the sample with the metrics provided' do | ||
expect(samples.first.values) | ||
.to eq( | ||
:'cpu-time' => 123, | ||
:'cpu-samples' => 456, | ||
:'wall-time' => 789, | ||
:'alloc-samples' => 4242, | ||
:timeline => 1111, | ||
'cpu-time': 123, | ||
'cpu-samples': 456, | ||
'wall-time': 789, | ||
'alloc-samples': 4242, | ||
'alloc-samples-unscaled': 2222, | ||
timeline: 1111, | ||
) | ||
end | ||
|
||
context 'when disabling an optional profile sample type' do | ||
let(:cpu_time_enabled) { false } | ||
|
||
it 'encodes the sample with the metrics provided, ignoring the disabled ones' do | ||
expect(samples.first.values) | ||
.to eq(:'cpu-samples' => 456, :'wall-time' => 789, :'alloc-samples' => 4242, :timeline => 1111) | ||
expect(samples.first.values).to eq( | ||
'cpu-samples': 456, 'wall-time': 789, 'alloc-samples': 4242, 'alloc-samples-unscaled': 2222, timeline: 1111 | ||
) | ||
end | ||
end | ||
|
||
|
@@ -526,7 +539,7 @@ def sample_allocation(obj) | |
# We use the same metric_values in all sample calls in before. So we'd expect | ||
# the summed values to match `@num_allocations * metric_values[profile-type]` | ||
# for each profile-type there in. | ||
expected_summed_values = { :'heap-live-samples' => 0, :'heap-live-size' => 0, } | ||
expected_summed_values = { 'heap-live-samples': 0, 'heap-live-size': 0, 'alloc-samples-unscaled': 0 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static Analysis Violation (ruby-best-practices/symbols-as-keys)⚪ Notice - Best Practices - Link to Results Consider using symbols instead of string hash keys More informationIn Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters. The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets. To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from
Leave feedback in #static-analysis |
||
metric_values.each_pair do |k, v| | ||
expected_summed_values[k.to_sym] = v * @num_allocations | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static Analysis Violation (ruby-best-practices/symbols-as-keys)
⚪ Notice - Best Practices - Link to Results
Consider using symbols instead of string hash keys
More information
In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.
The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.
To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from
values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 }
tovalues = { foo: 42, bar: 99, baz: 123 }
will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.Leave feedback in #static-analysis