Loading...
Searching...
No Matches
casacore::MemoryTrace Class Reference
casa package (libcasa_casa) » OS_module

More...

`#include <MemoryTrace.h>`

## Static Public Member Functions

static void | start ()
| Start the tracing.
static void | stop ()
| Stop the tracing.
static void | open ()
| Open the trace file if not open yet.
static void | close ()
| Close the tracing output file.
static Bool | isOn ()
| Is tracing on?
static Bool | isOpen ()
| Is the tracing file opened?
static void | writeBlock (const char *msg, const std::string &name)
| Write a block line in the output file.
static void | writeBlock (const char *msg, const char *name)
static std::ofstream & | writeAlloc (const void *ptr, size_t)
| Write an alloc or free message.
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.
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.

## 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:

- An allocation line like "a <address> <caller> <size>"
- A deallocation line like "f <address> <caller>"
- A line like "begin/end <name>" telling the script the beginning or end of a code block. It makes it possible to see how memory usage develops. Such lines can be inserted using the class MemoryTraceBlock.

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 68 of file MemoryTrace.h.

## Member Function Documentation

## close()

void casacore::MemoryTrace::close | ( |  | ) |

static

Close the tracing output file.

## freeHook()

void casacore::MemoryTrace::freeHook | ( | void * | ,
|  | const void * | caller )

static

## isOn()

Bool casacore::MemoryTrace::isOn | ( |  | ) |

inline static

Is tracing on?

Definition at line 87 of file MemoryTrace.h.

References theirDoTrace.

## isOpen()

Bool casacore::MemoryTrace::isOpen | ( |  | ) |

inline static

Is the tracing file opened?

Definition at line 91 of file MemoryTrace.h.

References theirFile.

## makeString()

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

static

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

## mallocHook()

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

static

The hooks for malloc and free writing the trace messages.

## open()

void casacore::MemoryTrace::open | ( |  | ) |

static

Open the trace file if not open yet.

## start()

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.

## stop()

void casacore::MemoryTrace::stop | ( |  | ) |

static

Stop the tracing.

## writeAlloc()

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

static

Write an alloc or free message.

## writeBlock() [1/2]

void casacore::MemoryTrace::writeBlock | ( | const char * | msg,
|  | const char * | name )

static

References casacore::name().

## writeBlock() [2/2]

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

static

Write a block line in the output file.

References casacore::name().

## writeFree()

std::ofstream & casacore::MemoryTrace::writeFree | ( | const void * | ptr | ) |

static

## Member Data Documentation

## theirDoTrace

Bool casacore::MemoryTrace::theirDoTrace

static private

Definition at line 111 of file MemoryTrace.h.

Referenced by isOn().

## theirFile

std::ofstream casacore::MemoryTrace::theirFile

static private

Definition at line 112 of file MemoryTrace.h.

Referenced by isOpen().

## theirOldFreeHook

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

static private

Definition at line 116 of file MemoryTrace.h.

## theirOldMallocHook

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

static private

Definition at line 115 of file MemoryTrace.h.

## theirTimer

Timer casacore::MemoryTrace::theirTimer

static private

Definition at line 113 of file MemoryTrace.h.

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

- casa/OS/MemoryTrace.h