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

Count allocations in realtime (ros ticket #3406) #242

Open
ahendrix opened this issue Mar 12, 2013 · 4 comments
Open

Count allocations in realtime (ros ticket #3406) #242

ahendrix opened this issue Mar 12, 2013 · 4 comments

Comments

@ahendrix
Copy link
Member

As a debugging tool, count the allocations performed by each controller in a cycle of the realtime loop.

trac data:

@ahendrix
Copy link
Member Author

[sglaser] Here are the methods I've examined:

  1. malloc hooks ([http://www.gnu.org/s/libc/manual/html_node/Hooks-for-Malloc.html libc])
  2. Linker wrapping ([http://cf.ccmr.cornell.edu/cgi-bin/w3mman2html.cgi?ld(1) ld])
  3. Replace malloc and LD_PRELOAD ([http://stackoverflow.com/questions/262439/create-a-wrapper-function-for-malloc-and-free-in-c wrapper])

Solution 1 doesn't work because malloc hooks don't work in multithreaded applications. Malloc hooks rely on modifying global variables in a non-thread safe way for installing and removing the hooks which inevitably leads to creating infinite recursion into the hooks when the hook installation process goes bad. The infinite recursion can be avoided, but without using locking these leads to the possibility that the hooks will not always be called.

Solution 2 doesn't work because you must choose a priori which libraries to link with the --wrap option. For example, if I link robot_mechanism_controllers with --wrap=malloc but not KDL, then any allocations which occur in the KDL library will not be handled by the malloc wrapper. Every package that gets used in realtime would have to be changed to be linked with the malloc wrapping.

Solution 3 seems like the only possibility, but I haven't attempted to implement it yet.

@ahendrix
Copy link
Member Author

[gunter] Interesting.

Does it help to limit the scope? I.e. to observe only allocations of a particular controller at a particular time. Meaning it would be okay to link with a particular library to get the information?

As nice as it would be to always be able to look at the info, having it be a special debug process seems still VERY useful to me???

-gunter

@ahendrix
Copy link
Member Author

[gerkey] Following up on Gunter's suggestion, it doesn't seem that bad to me to have to explicitly re-link the libs you're using. Presumably, only a select handful of libs get used in realtime, because most libs aren't realtime-safe.

@ahendrix
Copy link
Member Author

[sglaser] Observing only one controller makes the code slightly simpler, but it doesn't change the mechanics of replacing malloc, which is the difficult part. Not observing the libraries the controller depends upon, in my opinion, defeats the purpose of counting the allocations.

I think it's painful to have to change the CMakeLists for every package used in realtime when you want to debug, and I don't expect the LD_PRELOAD solution to be much more difficult than the --wrap solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant