GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Enable native memory profiling on the async-profiler by Baraa-Hasheesh · Pull Request #1323 · async-profiler/async-profiler Conversation
Contributor
DescriptionEnable Native memory profiling on the async-profiler shared objects Previously this profiling was removed as to solve #1266 This PR keeps that fix by reading the GOT entry before it is overwritten by the profiler & uses it to call the correct malloc via the dynamic linker Related issuesN/A Motivation and contextAllow async-profiler to detect memory leaks inside it self How has this been tested?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
apangin
reviewed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did oppressive some some sigfaults on MacOs that made me add all the existing I will double check which if statements can be removed (I believe I can remove all other than the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reduced the checks here 3dfc520 I've kept checks before calling realloc & after calling I also moved the symbols to their own function as I noticed that MacOs was optimizing some of them out when removing the if checks,
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, newer GCC versions still optimize
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @apangin the implementation does look great,
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not standard
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Using RTLD_NEXT previously was doing that, as it was resolving the wrong I did try using RTLD_DEFAULT & a dlopen handle to evaluate the symbols but both resulted in test failures As such I decided on using the lazy dynamic symbols as it was the safest choice as it will be equivalent to the current state of async profiler of using the dynamic linker. The dlopen handle caused the following test to fail (evaluating wrong malloc) The RTLD_DEFAULT caused the following tests to fail (Infinite callback loop)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked that Unfortunately, current code and the proposed
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| calloc_t _orig_calloc; | ||
| realloc_t _orig_realloc; | ||
| posix_memalign_t _orig_posix_memalign; | ||
| aligned_alloc_t _orig_aligned_alloc; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
All file-local variables and functions must be declared static.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
handled here a4a36cd
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| typedef void* (*calloc_t)(size_t,size_t); | ||
| typedef void* (*realloc_t)(void*, size_t); | ||
| typedef int (*posix_memalign_t)(void**, size_t, size_t); | ||
| typedef void* (*aligned_alloc_t)(size_t, size_t); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Too many typedefs. It's possible to avoid all these definitions just by declaring _orig_* function with a proper type once and then using decltype.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
handled here a4a36cd
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| _orig_calloc = (calloc_t)*lib->findImport(im_calloc); | ||
| _orig_realloc = (realloc_t)*lib->findImport(im_realloc); | ||
| _orig_posix_memalign = (posix_memalign_t)*lib->findImport(im_posix_memalign); | ||
| _orig_aligned_alloc = (aligned_alloc_t)*lib->findImport(im_aligned_alloc); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Each function name is repeated 3 times, which makes it harder to read and to modify.
This is one the cases where macros are really good (althogh they are generally discouraged).
I'd write something like:
SAVE_ORIG(malloc);
SAVE_ORIG(free);
...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
handled here a4a36cd
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.