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

Adds maliput profiler #538

Merged
merged 10 commits into from Jan 27, 2023
Merged

Adds maliput profiler #538

merged 10 commits into from Jan 27, 2023

Conversation

francocipollone
Copy link
Collaborator

@francocipollone francocipollone commented Jan 19, 2023

🎉 New feature

Summary

It adds a profiler to maliput's api.

  • By default it is disabled, for enabling maliput should be compiled using MALIPUT_PROFILER_ENABLE cmake argument
  • It is not causing any performance drop when it is disabled as the correct use of macros/defines is implemented.
  • It relies on ign-common's profiler component.
  • No hard dependency:
    • Dependency is only added if the argument above is passed.
    • Dependency is not replicated downstream to avoid recompiling in downstream packages.
  • README is updated to help enabling the profiler.
  • Code being profiled(more could be covered in the future if necessity arises):
    • API
      • RoadGeometry
      • Lane
    • routing
    • utility::generateobj

For reviewers

  • Commits added to facilitate revision, review commit by commit!

Test it

  • sudo apt install libignition-common3-dev
  • Compile from source
  • Run delphyne_gazoo
    • Or delphyne_gazoo -m maliput_osm
  • Run ign_remotery_viz

image

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if it affects the public API)

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>
Copy link
Collaborator

@agalbachicar agalbachicar left a 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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Comment on lines +54 to +57
/// \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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

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__)

Copy link
Collaborator Author

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.

Copy link
Collaborator

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)

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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
image

Copy link
Collaborator

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.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
francocipollone and others added 2 commits January 25, 2023 12:26
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>
Copy link
Collaborator

@agalbachicar agalbachicar left a comment

Choose a reason for hiding this comment

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

LGTM

@francocipollone francocipollone merged commit 3aaae01 into main Jan 27, 2023
@francocipollone francocipollone deleted the francocipollone/profiler branch January 27, 2023 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants