-
Notifications
You must be signed in to change notification settings - Fork 48
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
Improve TCMalloc detection #443
Conversation
So I wasn't sure if all distributions are using the exact same implementation. But if preloading is the only way to make it work, and it is done when Kodi starts, it means our add-on has libtcmalloc preloaded as well. So I was wondering within python if we can detect whether libtcmalloc was loaded, or whether we can detect that from our process memory (i.e. /proc/pid). It would make the implementation somewhat more robust (if my assumptions are correct). |
Maybe this is possible from command line with EDIT: works on Linux x64 but not in LibreELEC |
I think I found a solution based on these commands:
Test packages to use with the nightly builds of LibreELEC and CoreELEC: |
So I think this can be simplified by doing: content = open('/proc/self/maps', 'r').read() You do not have to call a unix command to read a file. And we can use the python child process to find if the library is preloaded. The implementation would something like: libtcmalloc = 'libtcmalloc_minimal.so'
process_maps = open('/proc/self/maps', 'r').read()
is_tcmalloc_preloaded = bool(libtcmalloc in process_maps)
arm_device = None
if not is_tcmalloc_preloaded: We do not so much care about the exact location of libtcmalloc_minimal.so or even if the file exists. |
What would be even better is if we can verify if the calls that Widevine is doing are available. In that case we do not even need to check for the library in the process maps, we could simply ask python if those symbols are available in its process space and conclude they are also available to libwidevinecdm.so. Any of these would probably do:
With ctypes you can easily load a library and then check if any of these symbols are present (and even call them). But I cannot easily find a way to access already loaded (preloaded or linked to python interpreter itself). libraries. It must be possible though. |
But we can make those improvements later as well. It is more important that we have something that works well enough on all supported platforms. Whatever works the broadest is best. |
Thanks, I simplified the check. |
So, if CoreELEC is linking to libtcmalloc.so or libtcmalloc_minimal.so and it is not preloaded, I assumed that we could no longer check python's process memory for tcmalloc symbols, and this would be a dead-end. I also assumed that using /proc/self/maps will effectively no longer work. But that is not true. I expected that the parent pid (ppid) of python would be the Kodi binary (kodi.bin) but that is not the case. On LibreELEC the parent of the python interpreter is in fact kodi.sh (the startup wrapper). So the python interpreter is in fact compiled into kodi.bin (big surprise). In fact that is not a big surprise, because that's how it can cache previous runs of an add-on. And we already established that add-ons were being runs as |
Co-authored-by: Dag Wieers <dag@wieers.com>
Co-authored-by: Dag Wieers <dag@wieers.com>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Do we know who can test this on CoreELEC for us? |
I think @CastagnaIT tested the CoreELEC nightly before. |
i have tested this PR on last coreelec nightly by choosing "Re-install widevine cdm lib" setting menu |
Thanks for confirming. |
Thank you for taking care about the linked in option 👍 We currently see some users reporting rebooting devices and we maybe switch to the LD_PRELOAD method as it looks "more stable" and causes less rebooting devices. Currently we trigger two errors with the new cdm lib: rebooting while watching, like after 20-60min and a crash when a stream is opened/closed multiple times. |
@Portisch you are talking about coreelec or libreelec? |
CoreELEC only 😉 First users reporting already tcmalloc LD_PRELOAD works "better" than direct linking and does not reboot the device anymore. For the other issue when multiple times open/close a stream I will report when I collected some more debug info, thank you! |
Tomorrow i will try to play multiple times with my coreelec to see if happen also to me |
This checks if TCMalloc is preloaded or linked using
/proc/self/maps