Coder Social home page Coder Social logo

fulinux / stackusage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from d99kris/stackusage

0.0 2.0 0.0 370 KB

Measure stack usage in Linux and macOS applications

License: BSD 3-Clause "New" or "Revised" License

CMake 4.31% Shell 26.38% Roff 5.62% C 63.68%

stackusage's Introduction

Stackusage

Linux + Mac
Build status

Stackusage measures stack usage in Linux and macOS applications (main thread and native pthread child threads). The measured stack utilization data can be used to adjust the stack size allocation to provide desired margin for child threads. This is primarily useful for applications and libraries designed to work in resource-constrained environments (such as embedded systems).

Example Usage

$ stackusage ./ex001
stackusage log start ----------------------------------------------------
  pid  id    tid  requested     actual     maxuse  max%    dur  funcP
23930   0  23930    8388608    8384512       4144     0      0  (nil)
23930   1  23931      16384      16384       9336    56      0  0x4009b0
23930   2  23932      20480      20480      13528    66      0  0x4009b0
23930   3  23933      24576      24576      16728    68      0  0x4009b0
23930   4  23934      32768      32768      24920    76      0  0x4009b0
23930   5  23935      49152      49152      41304    84      0  0x4009b0
stackusage log end ------------------------------------------------------

Supported Platforms

Stackusage is primarily developed and tested on Linux, but basic functionality should work in macOS / OS X as well. Current version has been tested on:

  • OS X El Capitan 10.11
  • Ubuntu 16.04 LTS

Limitation: On macOS / OS X this tool relies on code injection using DYLD_INSERT_LIBRARIES, which generally does not work with third-party applications in a standard system. Using it on (your own) applications built from source should work fine though.

Installation

Pre-requisites (Ubuntu):

sudo apt install git cmake build-essential

Download the source code:

git clone https://github.com/d99kris/stackusage && cd stackusage

Generate Makefile and build:

mkdir -p build && cd build && cmake .. && make -s

Optionally install in system:

sudo make install

Usage

General usage syntax:

stackusage <application> [application arguments]

Example checking stack usage of test program 'ex001' with stackusage installed on system:

stackusage ./ex001

Output Format

Example output:

stackusage log start ----------------------------------------------------
  pid  id    tid  requested     actual     maxuse  max%    dur  funcP
23930   0  23930    8388608    8384512       4144     0      0  (nil)
23930   1  23931      16384      16384       9336    56      0  0x4009b0
23930   2  23932      20480      20480      13528    66      0  0x4009b0
23930   3  23933      24576      24576      16728    68      0  0x4009b0
23930   4  23934      32768      32768      24920    76      0  0x4009b0
23930   5  23935      49152      49152      41304    84      0  0x4009b0
stackusage log end ------------------------------------------------------

Description of columns:

pid         process id
id          id (0 = main thread, 1 = first child thread, etc..)
tid         thread id / tid (only supported on Linux, others show '0')
requested   requested stack size in bytes
actual      actual stack size in bytes (excl. any stack guard)
maxuse      maximum stack usage in bytes
max%        maximum use of requested stack size in percentage
dur         thread duration in seconds
funcP       (nil) for main, pointer to start_routine for child threads

The function that funcP points to can be determined for example using addr2line:

$ addr2line -f -e ./ex001 0x4009b0
thread_start
./tests/ex001.c:81

Technical Details

Stackusage intercepts calls to pthread_create and fills the thread stack with a dummy data pattern. It also registers a callback routine to be called upon thread termination. In the callback routine the amount of remaining dummy pattern in the stack is checked, in order to determine the stack usage.

License

Stackusage is distributed under the BSD 3-Clause license. See LICENSE file.

Keywords

linux, macos, os x, pthreads, stack usage, stack utilization, threads.

stackusage's People

Contributors

d99kris avatar

Watchers

James Cloos avatar 陈福林 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.