-
Notifications
You must be signed in to change notification settings - Fork 44
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
Put stats collection under static variable #790
Conversation
Signed-off-by: Alan Jowett <[email protected]>
WalkthroughThe changes involve significant modifications to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range comments (1)
src/crab_utils/stats.hpp (1)
Line range hint
36-70
: Consider splitting statistics and timing functionalityThe
CrabStats
class currently handles both counting and timing concerns, which violates the Single Responsibility Principle. Consider splitting this into two specialized classes:
CrabCounter
for counting statisticsCrabTimer
for stopwatch functionalityThis would make the code more maintainable and easier to test.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (2)
src/crab_utils/stats.cpp
(0 hunks)src/crab_utils/stats.hpp
(2 hunks)
💤 Files with no reviewable changes (1)
- src/crab_utils/stats.cpp
🔇 Additional comments (2)
src/crab_utils/stats.hpp (2)
48-52
: 🛠️ Refactor suggestion
Optimize the count
method implementation
The current implementation can be improved in several ways:
- Make it more concise
- Avoid creating map entries when disabled
- Add documentation
- static void count(const std::string& name) {
- if (enabled) {
- ++(*counters)[name];
- }
- }
+ /// Increments the counter for the specified name if statistics are enabled.
+ /// @param name The name of the counter to increment
+ static void count(const std::string& name) {
+ if (enabled && counters->count(name)) {
+ ++(*counters)[name];
+ }
+ }
Likely invalid or redundant comment.
56-70
: 🛠️ Refactor suggestion
Improve stopwatch methods implementation
The stopwatch methods share similar issues that should be addressed:
- Avoid creating map entries when disabled
- Add documentation
- Consider adding state transition validation
+ /// Starts the stopwatch for the specified name if statistics are enabled.
+ /// @param name The name of the stopwatch to start
static void start(const std::string& name) {
- if (enabled) {
+ if (enabled && sw->count(name)) {
(*sw)[name].start();
}
}
+ /// Stops the stopwatch for the specified name if statistics are enabled.
+ /// @param name The name of the stopwatch to stop
static void stop(const std::string& name) {
- if (enabled) {
+ if (enabled && sw->count(name)) {
(*sw)[name].stop();
}
}
+ /// Resumes the stopwatch for the specified name if statistics are enabled.
+ /// @param name The name of the stopwatch to resume
static void resume(const std::string& name) {
- if (enabled) {
+ if (enabled && sw->count(name)) {
(*sw)[name].resume();
}
}
Additionally, consider adding state validation to prevent invalid transitions (e.g., stopping an unstarted stopwatch).
Signed-off-by: Alan Jowett <[email protected]>
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
src/crab_utils/stats.hpp
(2 hunks)
🔇 Additional comments (2)
src/crab_utils/stats.hpp (2)
50-54
: LGTM! Efficient implementation with proper guarding
The implementation correctly uses the enabled
flag to prevent unnecessary operations, and the inline definition can improve performance.
50-72
: Verify removal of old method implementations
The methods have been moved from cpp to hpp. Let's verify that the old implementations were properly removed.
✅ Verification successful
Methods correctly moved to header file
The verification confirms that the implementations of count()
, start()
, stop()
, and resume()
methods are now correctly defined in the header file (stats.hpp) and are not present in stats.cpp. The stats.cpp file only contains other method implementations and the necessary thread-local storage definitions. This is a valid refactoring with no issues found.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if old method implementations exist in stats.cpp
# Search for old method implementations in stats.cpp
rg -A 3 "void CrabStats::(count|start|stop|resume)\(" src/crab_utils/stats.cpp
Length of output: 80
Script:
#!/bin/bash
# Let's first check if stats.cpp exists and see its content
fd -t f "stats.cpp" src/crab_utils/
# If it exists, let's see its content
fd -t f "stats.cpp" src/crab_utils/ -x cat {}
# Let's also check for any other potential implementations in other files
rg -A 3 "CrabStats::(count|start|stop|resume)"
Length of output: 8093
Signed-off-by: Alan Jowett <[email protected]>
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.
Actionable comments posted: 0
🧹 Outside diff range comments (1)
src/crab_utils/stats.hpp (1)
Performance profiling is still available but needs compile-time configuration
The statistics collection is used extensively in the SplitDBM implementation for performance profiling, but the current change makes it a compile-time configuration through
constexpr bool enabled
. This is a performance optimization that allows the compiler to completely eliminate profiling overhead in production builds.Key findings:
- The feature is used consistently throughout
split_dbm.cpp
for profiling various operations- Performance testing is documented in
scripts/README.md
showing active usage- No compile-time configuration mechanism is exposed to enable statistics
Recommendation:
- Add documentation on how to enable statistics collection by changing the
enabled
flag- Consider making this configurable through a build flag rather than requiring code changes
🔗 Analysis chain
Line range hint
36-72
: Verify the impact on existing performance profiling capabilities.Since stats collection is now disabled by default, we should verify if there are any existing callers that rely on these statistics and ensure there's documentation on how to enable stats when needed.
Let me check the actual usage and documentation to make a more informed decision.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any direct usage of CrabStats methods rg -l "CrabStats::(count|start|stop|resume)" --type cpp # Search for any performance profiling related documentation rg -l "performance|profiling|statistics" --type mdLength of output: 199
Script:
#!/bin/bash # Check the actual usage in split_dbm files rg "CrabStats::(count|start|stop|resume)" src/crab/split_dbm.cpp src/crab/split_dbm.hpp -B 2 -A 2 # Check if there's any configuration or documentation about enabling stats rg "performance|profiling|statistics" scripts/README.md -B 2 -A 2 # Check stats.cpp implementation for any enable/disable mechanism cat src/crab_utils/stats.cppLength of output: 8267
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
src/crab_utils/stats.hpp
(2 hunks)
🔇 Additional comments (3)
src/crab_utils/stats.hpp (3)
36-38
: LGTM: The enabled flag implementation looks good.
The implementation aligns well with the PR objectives. The documentation clearly explains the purpose, and using constexpr
with false
ensures unused code is optimized out at compile-time.
50-54
: LGTM: Efficient implementation with zero overhead when disabled.
The use of if constexpr
ensures the counter increment code is completely eliminated at compile-time when stats are disabled, resulting in optimal performance.
58-72
: LGTM: Clean and efficient stopwatch method implementations.
The implementations are straightforward and efficient:
- Each method has a clear, single responsibility
if constexpr
ensures zero runtime overhead when disabled- The simple, direct approach makes the code easy to understand and maintain
This pull request includes changes to the
CrabStats
class to add anenabled
flag and refactor several methods to check this flag before performing their operations. Additionally, some methods have been moved from the.cpp
file to the.hpp
file and made inline.Enhancements to
CrabStats
class:enabled
flag to theCrabStats
class to control whether statistics are collected. (src/crab_utils/stats.hpp
)count
,start
,stop
, andresume
methods to check theenabled
flag before executing their logic. These methods were also moved to the header file and made inline. (src/crab_utils/stats.hpp
)Code cleanup:
count
,start
,stop
, andresume
method definitions from theCrabStats
class implementation file. (src/crab_utils/stats.cpp
)Summary by CodeRabbit
New Features
Bug Fixes
CrabStats
functionality.Refactor