d99kris / stackusage

Measure stack usage in Linux and macOS applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to preload libstackusage.dylib on MacOS

lkloh opened this issue · comments

I'm using MacOS Big Sur version 11.3.1. I tried the installation steps suggested:

  1. Prerequisites: sudo apt install git cmake build-essential -- skipped as I have git and cmake installed, brew install build-essential and sudo port install build-essential didn't turn up packages but I was still able to compile.
  2. Download source code: git clone https://github.com/d99kris/stackusage && cd stackusage
  3. Generate Makefile and build: mkdir -p build && cd build && cmake .. && make -s

Now this generated several files in the build directory:

CMakeCache.txt      Makefile            ex002               stackusage          test004
CMakeFiles          cmake_install.cmake ex004               test001
CTestTestfile.cmake ex001               libstackusage.dylib test002

When I ran:

./stackusage ls

it keeps giving me this error: error: unable to preload libstackusage.dylib.

Running sudo make install to install in system and then trying

./stackusage ls

persistently gave the same error: error: unable to preload libstackusage.dylib.

Is there something obvious I'm missing, or do you think this could be a bug?

Hi @lkloh - thanks for the very well-written issue description! 👍

I believe the issue you are seeing is due to a known limitation of stackusage on macOS. Basically it can only provide analysis on your own programs / locally built. You could try run stackusage on one of the example programs in the build directory, and it should work. Example:

cd build
./stackusage ./ex001

This limitation is due to macOS not allowing the type of code injection stackusage relies on, for - I think - system binaries and signed programs. It's briefly mentioned in the README.md https://github.com/d99kris/stackusage#supported-platforms but I should probably consider adding a note in the warning-message of stackusage itself (on macOS).

Hi @lkloh - thanks for the very well-written issue description! 👍

I believe the issue you are seeing is due to a known limitation of stackusage on macOS. Basically it can only provide analysis on your own programs / locally built. You could try run stackusage on one of the example programs in the build directory, and it should work. Example:

cd build
./stackusage ./ex001

This limitation is due to macOS not allowing the type of code injection stackusage relies on, for - I think - system binaries and signed programs. It's briefly mentioned in the README.md https://github.com/d99kris/stackusage#supported-platforms but I should probably consider adding a note in the warning-message of stackusage itself (on macOS).

Thanks for the response! I was able to analyze the ex00X programs 👍

~/stackusage/build(master*) » ./stackusage ./ex001                                   laykuanloh@Lays-MacBook-Pro
Starting thread size=8192 usage=0
Starting thread size=12288 usage=4096
Starting thread size=16384 usage=8192
Starting thread size=24576 usage=16384
Starting thread size=40960 usage=32768
stackusage log at 2021-08-12 08:50:39 ----------------------------------------
  pid  id    tid  requested     actual     maxuse  max%    dur               funcP name
52449   0      0   67104768   67104768      12448     0      0                 0x0
52449   1      0       8192       8192       2336    28      0         0x1084c4e00
52449   2      0      12288      12288       6560    53      0         0x1084c4e00
52449   3      0      16384      16384       8464    51      0         0x1084c4e00
52449   4      0      24576      24576      16656    67      0         0x1084c4e00
52449   5      0      40960      40960      33040    80      0         0x1084c4e00

Yes, adding a warning message to stackusage on MacOS so people don't get confused would be great.

Another thing that could be helpful is to change the --help message's proposed test program to ./stackusage ./ex001 instead of ./stackusage ls. I was using the --help message to understand how to use the tool when I ran into the error.

Screen Shot 2021-08-12 at 8 58 22 AM

Hi again, good suggestion. Now the --help message has been aligned with the README.md, and a warning message has been added when running stackusage and it fails to preload/inject its code.

Hi again, good suggestion. Now the --help message has been aligned with the README.md, and a warning message has been added when running stackusage and it fails to preload/inject its code.

thanks!