casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Static Public Member Functions | Static Private Attributes | List of all members
casacore::MemoryTrace Class Reference

memory usage tracing mechanism More...

#include <MemoryTrace.h>

Static Public Member Functions

static void start ()
 Start the tracing. More...
 
static void stop ()
 Stop the tracing. More...
 
static void open ()
 Open the trace file if not open yet. More...
 
static void close ()
 Close the tracing output file. More...
 
static Bool isOn ()
 Is tracing on? More...
 
static Bool isOpen ()
 Is the tracing file opened? More...
 
static void writeBlock (const char *msg, const std::string &name)
 Write a block line in the output file. More...
 
static void writeBlock (const char *msg, const char *name)
 
static std::ofstream & writeAlloc (const void *ptr, size_t)
 Write an alloc or free message. More...
 
static std::ofstream & writeFree (const void *ptr)
 
static void * mallocHook (size_t, const void *caller)
 The hooks for malloc and free writing the trace messages. More...
 
static void freeHook (void *, const void *caller)
 
static std::string makeString (const char *)
 Make a string from a char* without tracing a possible malloc in the string constructor. More...
 

Static Private Attributes

static Bool theirDoTrace
 
static std::ofstream theirFile
 
static Timer theirTimer
 
static void *(* theirOldMallocHook )(size_t, const void *)
 
static void(* theirOldFreeHook )(void *, const void *)
 

Detailed Description

memory usage tracing mechanism

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Synopsis

The MemoryTrace class provides some means to trace the memory usage of a program. It logs malloc and free messages in a file which can be examined by the python script memorytrace.py.
The tracing is done using hooks for malloc and free as explained in 'man malloc_hook'.

The tracing can be started and stopped at any time. On the first start the trace file is created. The file can be closed at any time, usually at the end of a program. Another start will recreate the file.

The trace file consists of 3 types of lines:

All lines start with the number of milliseconds since the start of the program.

The script memorytrace.py can be used to interpret the log file and to show the memory usage.

Definition at line 70 of file MemoryTrace.h.

Member Function Documentation

static void casacore::MemoryTrace::close ( )
static

Close the tracing output file.

static void casacore::MemoryTrace::freeHook ( void *  ,
const void *  caller 
)
static
static Bool casacore::MemoryTrace::isOn ( )
inlinestatic

Is tracing on?

Definition at line 89 of file MemoryTrace.h.

References theirDoTrace.

static Bool casacore::MemoryTrace::isOpen ( )
inlinestatic

Is the tracing file opened?

Definition at line 93 of file MemoryTrace.h.

References theirFile.

static std::string casacore::MemoryTrace::makeString ( const char *  )
static

Make a string from a char* without tracing a possible malloc in the string constructor.

static void* casacore::MemoryTrace::mallocHook ( size_t  ,
const void *  caller 
)
static

The hooks for malloc and free writing the trace messages.

static void casacore::MemoryTrace::open ( )
static

Open the trace file if not open yet.

static void casacore::MemoryTrace::start ( )
static

Start the tracing.

Nothing is done if already started. On the first time, it opens the trace file. The name of the trace file can be given in the env.var. CASACORE_MEMORYTRACE. If undefined, the name casacore_memorytrace.log will be used.

static void casacore::MemoryTrace::stop ( )
static

Stop the tracing.

static std::ofstream& casacore::MemoryTrace::writeAlloc ( const void *  ptr,
size_t   
)
static

Write an alloc or free message.

static void casacore::MemoryTrace::writeBlock ( const char *  msg,
const std::string &  name 
)
static

Write a block line in the output file.

static void casacore::MemoryTrace::writeBlock ( const char *  msg,
const char *  name 
)
static
static std::ofstream& casacore::MemoryTrace::writeFree ( const void *  ptr)
static

Member Data Documentation

Bool casacore::MemoryTrace::theirDoTrace
staticprivate

Definition at line 113 of file MemoryTrace.h.

Referenced by isOn().

std::ofstream casacore::MemoryTrace::theirFile
staticprivate

Definition at line 114 of file MemoryTrace.h.

Referenced by isOpen().

void(* casacore::MemoryTrace::theirOldFreeHook)(void *, const void *)
staticprivate

Definition at line 118 of file MemoryTrace.h.

void*(* casacore::MemoryTrace::theirOldMallocHook)(size_t, const void *)
staticprivate

Definition at line 117 of file MemoryTrace.h.

Timer casacore::MemoryTrace::theirTimer
staticprivate

Definition at line 115 of file MemoryTrace.h.


The documentation for this class was generated from the following file: