Coder Social home page Coder Social logo

memory_monitor's Introduction

Memory Monitor for ndnSim

This is a memory analyze tool for ndnSim. It can also be used out of ndnSim. It monitors memory allocation and deallocation by overriding operator new / delete, and records all memory blocks allocated but not freed. It can start and stop at any time, controlled by code. And outputs the call stack when the memory was allocated into a text file.

Usage

Instructions below is for who compile ns-3 and ndnSim from source code with your scenario. Memory operations happened in NFD, ndnSim and scenario will be recorded.

  1. Put memory_monitor.hpp and memory_monitor.cpp into ns3/src/ndnSIM/NFD/core
  2. Include #include "NFD/core/memory_monitor.hpp" in your scenario.
  3. Use monitor::Monitor::getInstance() to get the instance of monitor.
    • Call start() to start recording. A record will be inserted into a list whenever a memory block is allocated. When it gets freed, the record will be deleted.
    • Call stop() to stop recording allocation. It will continue recording free.
    • Call stopAll() to stop recording allocation and free. The record list will not change any more.
    • Call getRecords() to get a copy of record list at any time.
    • Call writeLogFile(<file>) to create a log file.
  4. Use convert.py to translate the log file from address + function name into file name + line number.

If you write a seperate scenario, just put two files into extensions to get them linked with your scenario.

Log file format

For every block:

>>TIME: time stamp
>>SIZE: size of the block
>>DEPT: depth of call stack
>>ADDR: address of call stack
.....
<<

Examples

There is an example of using monitor to check memory leaks of ConsumerCbr. You can just copy all in examples folder into ndnSIM/examples and run it. It just a copy of ndn-simple and ndn-consumer-cbr with little modification. Read the code for more.

Problems with MacOS

The code can not work well with clang's c++ library sometimes, so please compile it with gcc like:

./waf configure --enable-examples ----check-c-compiler=gcc --check-cxx-compiler=g++

You may need to recompile boost library with gcc before that. convert.py can not be used in MacOS for different format of backtrace_symbols_fd.

Remark

It's not well tested now. Please let me know if any bug found.

memory_monitor's People

Contributors

zjkmxy avatar

Watchers

James Cloos avatar  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.