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
Adds maliput profiler #538
Conversation
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
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.
PTAL.
/// This allows us to enable/disable profiling at compile time and avoid adding a dependency on ignition common. | ||
|
||
#ifndef MALIPUT_PROFILER_ENABLE | ||
/// Always set this variable to some value |
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.
We should use @def MALIPUT_PROFILER_ENABLE ....
Which value should we use?
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.
This states that if the MALIPUT_PROFILER_ENABLE
is not defined then set it to zero. (as it is done in the very line below)
And the define is expected to bet set via preprocessor : cmake-ars --> compile definition
/// \brief Convenience wrapper for scoped profiling sample. Use MALIPUT_PROFILE | ||
#define MALIPUT_PROFILE_L(name, line) IGN_PROFILE_L(name, line) | ||
/// \brief Scoped profiling sample. Sample will stop at end of scope. | ||
#define MALIPUT_PROFILE(name) IGN_PROFILE(name) |
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.
Is it possible to use __FUNC__
/ __PRETTY_FUNCTION__
(even better but not sure if it is available in clang ) ?
That will allow to reduce the cost to implement the profiling everywhere, meaning that we don't need to review spelling mistakes and so on and the compiler will do it for us.
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.
Maybe we could create a new macro like
#define MALIPUT_PROFILE_FUNC() IGN_PROFILE(__FUNCTION__)
- Using FUNCTION only gives you the name of the method, without carrying about namespacing. So I wouldn't use it
- Using PRETTY_FUNCTION is possible, I tried it using compiler explorer for both gcc and clang. The firm of the method is quite complete: namespaces + return type + argument. The only issue here is that when using the profiler UI in order to analyze data it isn't that user friendly with long names, it is basically a mess. (I can try this out and post a picture here using the profiler)
Finally, we are using the profiler for analyzing entire method execution, however, it could be used por different part of a method. For example, check this usecase in gz-sim::simulationrunner
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.
I like the macro #define MALIPUT_PROFILE_FUNC() IGN_PROFILE(__FUNCTION__)
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.
What about also adding the option with pretty_function? Check 22ff1d8
In the api I am still using the MALIPUT_PROFILE
macro as it is better described.
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.
I think it is OK, but I would use it everywhere we are using the name of the function only to avoid spelling mistakes. Also, the macro could be (I hope the compiler shakes my right hand):
#define MALIPUT_PROFILE_FUNC() IGN_PROFILE(__FUNCTION__)
#define MALIPUT_PROFILE_FUNC_MSG(msg) IGN_PROFILE(__FUNCTION_": "#msg)
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.
Out of curiosity, are these __FUNCTION__
and __PRETTY_FUNCTION
in any of the standards? Never saw them before. If they are not, not sure guys how you deal with this platform constraints decisions in maliput.
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.
Out of curiosity, are these
__FUNCTION__
and__PRETTY_FUNCTION
in any of the standards? Never saw them before. If they are not, not sure guys how you deal with this platform constraints decisions in maliput.
Good question, __FUNCTION__
is part of the C++ standard already. Regarding __PRETTY_FUNCTION__
apparently it is not in the standard (at least yet) however gcc and clang have support for this. Given that we state to support both gcc and clang compilers, I think that there is no harm in using them.
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.
#define MALIPUT_PROFILE_FUNC_MSG(msg) IGN_PROFILE(__FUNCTION_": "#msg)
The issue with #define MALIPUT_PROFILE_FUNC_MSG(msg) IGN_PROFILE(__FUNCTION_": "#msg)
is the argument:
IGN_PROFILER is expecting a char *
and :
__FUNCTION__": "#msg
__FUNCTION__ + ": " + #msg
aren't correct.
There is an alternative of concatenating as a string and converting to const char * but making this conversion/operation every time that the method is called isn't ideal.
#define MALIPUT_PROFILE_FUNC_MSG(msg) IGN_PROFILE((static_cast<std::string>(__FUNCTION__) + std::string(": ") + static_cast<std::string>(msg)).c_str())
I replaced all the occurrences with MALIPUT_PROFILE_FUNC()
Check 209cc9d
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.
Good catch. Let's keep it as is then.
Co-authored-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
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.
LGTM
🎉 New feature
Summary
It adds a profiler to maliput's api.
MALIPUT_PROFILER_ENABLE
cmake argumentFor reviewers
Test it
sudo apt install libignition-common3-dev
delphyne_gazoo
delphyne_gazoo -m maliput_osm
ign_remotery_viz
Checklist