RAVE
pyrave_debug.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2009 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
25#ifndef PYRAVE_DEBUG_H
26#define PYRAVE_DEBUG_H
27#include <stdio.h>
28#include "rave_debug.h"
29
33typedef struct {
34 long created;
35 long destroyed;
36 const char* name;
38
47#define PYRAVE_DEBUG_MODULE(oname) \
48 static PyRaveObjectDebugging _pyravedebug = { \
49 0, 0, oname }; \
50 \
51 static void _pyravedebug_statistics(void) { \
52 if ((_pyravedebug.created - _pyravedebug.destroyed) != 0) { \
53 fprintf(stderr, "\n------------------------------------------\n"); \
54 fprintf(stderr, "CRITICAL ( Python module: %s ) \n", _pyravedebug.name); \
55 fprintf(stderr, "Created objects: %ld\n", _pyravedebug.created); \
56 fprintf(stderr, "Destroyed objects: %ld\n", _pyravedebug.destroyed); \
57 fprintf(stderr, "Objects lost: %ld\n", (_pyravedebug.created - _pyravedebug.destroyed)); \
58 fprintf(stderr, "\n"); \
59 } \
60 }
61
65#define PYRAVE_DEBUG_OBJECT_CREATED \
66 _pyravedebug.created++
67
71#define PYRAVE_DEBUG_OBJECT_DESTROYED \
72 _pyravedebug.destroyed++
73
77#define PYRAVE_DEBUG_INITIALIZE \
78 if (atexit(_pyravedebug_statistics) != 0) { \
79 fprintf(stderr, "Failed to setup debug statistics for module %s\n", _pyravedebug.name); \
80 }
81
82#endif /* PYRAVE_DEBUG_H */
Defines the functions for debugging rave.
Debugger struct to be used in rave python modules.
Definition pyrave_debug.h:33
long destroyed
counts how many times an object has been destroyed
Definition pyrave_debug.h:35
long created
counts how many times an object has been created
Definition pyrave_debug.h:34
const char * name
the name for this object
Definition pyrave_debug.h:36