-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix and optimize query profiling #57095
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -62,7 +62,8 @@ macro_rules! define_categories { | |
let total_time = ($(self.times.$name + )* 0) as f32; | ||
|
||
$( | ||
let (hits, total) = self.query_counts.$name; | ||
let (hits, computed) = self.query_counts.$name; | ||
let total = hits + computed; | ||
let (hits, total) = if total > 0 { | ||
(format!("{:.2}", | ||
(((hits as f32) / (total as f32)) * 100.0)), total.to_string()) | ||
|
@@ -86,7 +87,8 @@ macro_rules! define_categories { | |
let mut json = String::from("["); | ||
|
||
$( | ||
let (hits, total) = self.query_counts.$name; | ||
let (hits, computed) = self.query_counts.$name; | ||
let total = hits + computed; | ||
|
||
//normalize hits to 0% | ||
let hit_percent = | ||
|
@@ -168,14 +170,14 @@ impl SelfProfiler { | |
self.timer_stack.push(category); | ||
} | ||
|
||
pub fn record_query(&mut self, category: ProfileCategory) { | ||
let (hits, total) = *self.data.query_counts.get(category); | ||
self.data.query_counts.set(category, (hits, total + 1)); | ||
pub fn record_computed_queries(&mut self, category: ProfileCategory, count: usize) { | ||
let (hits, computed) = *self.data.query_counts.get(category); | ||
self.data.query_counts.set(category, (hits, computed + count as u64)); | ||
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. An issue for another PR: This looks like we could get missed updates here (and below) with parallel queries. |
||
} | ||
|
||
pub fn record_query_hit(&mut self, category: ProfileCategory) { | ||
let (hits, total) = *self.data.query_counts.get(category); | ||
self.data.query_counts.set(category, (hits + 1, total)); | ||
let (hits, computed) = *self.data.query_counts.get(category); | ||
self.data.query_counts.set(category, (hits + 1, computed)); | ||
} | ||
|
||
pub fn end_activity(&mut self, category: ProfileCategory) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a remark: There should probably be a third category here for things that could be re-used but are not stored in the cache. Not sure how to best handle this.