Skip to content
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

Add command statistics time #1659

Closed
wants to merge 23 commits into from
Closed

Add command statistics time #1659

wants to merge 23 commits into from

Conversation

Mixficsol
Copy link
Collaborator

fix #977

@@ -388,7 +391,7 @@ class PaddingCmd : public Cmd {
private:
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
uint64_t offset) override;
};

class PKPatternMatchDelCmd : public Cmd {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is difficult to provide a comprehensive code review without the context and full codebase. However, based on the provided code patch, here are some observations:

  1. In the FlushallCmd and PaddingCmd classes, there seems to be a change in formatting for the ToBinlog function's parameters. The indentation for the second line of the function definition has been adjusted. This change doesn't affect the functionality but could be a formatting preference.

  2. In the InfoCmd class, a new enumeration value kInfoCommandstats has been added. Make sure that this addition is aligned with the intended functionality and matches other related code.

  3. A new member variable kCommandstatsSection and a corresponding method InfoCommandstats have been added to the InfoCmd class. Again, ensure that these additions align with the desired behavior and integrate correctly with other sections of code.

  4. Without the full implementation of the classes and their dependencies, it's challenging to identify potential bugs or improvement suggestions. Consider sharing more details or specific areas of concern if you require a more in-depth analysis.

Remember to thoroughly test the changes and consider the impact on the overall project when making updates to existing code.

Cmd.cmd_time_consuming = 0;
cmdstat_map[name] = Cmd;
++iter;
}
}

std::shared_ptr<Cmd> PikaCmdTableManager::GetCmd(const std::string& opt) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the code patch looks fine. Here are a few suggestions for improvement and potential bug risks:

  1. In the constructor PikaCmdTableManager::PikaCmdTableManager(), it's unclear where the PikaConf object pointed to by g_pika_conf is initialized. Make sure it's properly initialized before this constructor is called to avoid potential null pointer dereference issues.

  2. Consider using the range-based for loop instead of the iterator loop in the constructor to simplify the code. Here's an example:

for (const auto& cmd : *cmds_) {
  pikaCommandStatistics Cmd;
  Cmd.cmd_name = cmd.first;
  Cmd.cmd_count = 0;
  Cmd.cmd_time_consuming = 0;
  cmdstat_map[Cmd.cmd_name] = Cmd;
}
  1. It's good practice to use const auto& when iterating over containers if you don't intend to modify the elements. So, consider changing auto iter to const auto& iter in the loop.

  2. The usage of cmdstat_map within the constructor assumes that it's a global variable accessible from this context. Ensure that it's properly defined and accessible at the scope where the constructor is declared.

  3. Verify that there are no naming conflicts with existing variables or types. Ensure that pikaCommandStatistics is not already defined elsewhere to avoid redefinition errors.

  4. Be cautious with multi-threaded access to cmdstat_map if it's accessed from multiple threads concurrently. Synchronization mechanisms, such as locks or mutexes, might be necessary to avoid data races and ensure thread safety.

  5. Consider using modern C++ features like emplace_back instead of push_back when constructing cmds_ to improve performance.

These suggestions should help improve the code and address potential issues. Reviewing the surrounding code and context may reveal additional improvements or bug risks.

@Mixficsol Mixficsol closed this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

redis API: support commands_duration_seconds_total
2 participants