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

Optimize calls via the RCUTILS_LOG macros. #369

Merged
merged 2 commits into from
Aug 3, 2022

Conversation

clalancette
Copy link
Contributor

It turns out that when we call RCUTILS_LOG_DEBUG (and friends),
we were calling rcutils_logging_logger_is_enabled_for() twice;
once in the macro itself (where we want to avoid evaluating
conditions if the logger is disabled), and once in the rcutils_log()
call. Since rcutils_logging_logger_is_enabled_for() is a pretty
expensive function, this means we were doing unnecessary work.

Improve this by splitting rcutils_log() into rcutils_log() and
rcutils_log_internal(), the latter of which does not do the
enabled check. Then change the macros to call the internal
version of the API, which avoids the double check while still
maintaining the safety guarantees we want if a user calls
rcutils_log() directly.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

It turns out that when we call RCUTILS_LOG_DEBUG (and friends),
we were calling rcutils_logging_logger_is_enabled_for() twice;
once in the macro itself (where we want to avoid evaluating
conditions if the logger is disabled), and once in the rcutils_log()
call.  Since rcutils_logging_logger_is_enabled_for() is a pretty
expensive function, this means we were doing unnecessary work.

Improve this by splitting rcutils_log() into rcutils_log() and
rcutils_log_internal(), the latter of which does not do the
enabled check.  Then change the macros to call the internal
version of the API, which avoids the double check while still
maintaining the safety guarantees we want if a user calls
rcutils_log() directly.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor Author

clalancette commented Jul 29, 2022

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@fujitatomoya
Copy link
Collaborator

related to #364

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm! but adding test would be ideal.

@clalancette
Copy link
Contributor Author

lgtm! but adding test would be ideal.

I ended up not adding tests because I think everything here is already covered elsewhere. That is, the tests in https://github.com/ros2/rcutils/blob/rolling/test/test_logging.cpp end up testing rcutils_log, and the tests in https://github.com/ros2/rcutils/blob/rolling/test/test_logging_macros.cpp test the logging macros (which indirectly test rcutils_log_internal).

That said, let me know if you still think I should add additional tests.

@fujitatomoya
Copy link
Collaborator

@clalancette thanks for the comment, i am good to go with green CI.

@clalancette
Copy link
Contributor Author

Here's another CI try:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@clalancette clalancette merged commit f0bee9e into rolling Aug 3, 2022
@clalancette clalancette deleted the clalancette/avoid-double-enabled-for branch August 3, 2022 19:30
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.

2 participants