2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 // This class is a memory allocation tracker used to optimize
21 // the memory usage and find memory leaks.
27 #include "gnashconfig.h"
30 // If we don't have support for mallinfo(), this code is useless
36 #include "dsodefs.h" // DSOEXPORT
40 class DSOEXPORT Memory
{
43 // Borrowed from malloc.h and trimmed down.
44 struct small_mallinfo
{
45 int line
; // line number of this data sample
46 struct timespec stamp
; // the time stamp of this sample
47 int arena
; // non-mmapped space allocated from system
48 int uordblks
; // total allocated space
49 int fordblks
; // total free space
55 // Start collecting statistics. This can effect performance
58 // Stop collecting statistics
59 void endStats() { addStats();_collecting
= false; };
61 // Erase all collected data and reset collections.
65 void startCheckpoint() { _checkpoint
[0] = mallinfo(); };
68 // Add or retrieve mallinfo data
70 int addStats(int line
);
71 int addStats(struct small_mallinfo
*x
);
72 int addStats(struct small_mallinfo
*x
, int line
);
73 struct small_mallinfo
*getStats() { return _info
; };
74 struct small_mallinfo
*operator[](int x
) { return _info
+ x
; };
75 int totalStats() { return _index
; };
77 // Analyze memory usage
80 // Dump the differences of bytes allocated between two samples
82 int diffStats(int x
, int y
);
84 // Dump the differences in the timestamp between two samples
86 int diffStamp(int x
, int y
);
88 // Dump the vector of stored classes
89 void dump(struct mallinfo
*x
);
90 void dump(struct small_mallinfo
*x
);
95 // For data logging, we want to store as little as possible
96 // so we don't impact the system too hard. Data logging memory
97 // allocations can generate a huge amount of data, so we have
98 // to be careful. We also can't use STL, as that does more
99 // memory allocations, which will confuse our statistics
101 struct small_mallinfo
*_info
;
102 // Since we aren't using STL, we have to store how much
103 // data storage we have ourselves.
106 // For checkpoints, we want the all the data
107 struct mallinfo _checkpoint
[2];
110 } // end of gnash namespace
112 #endif // end of HAVE_MALLINFO
114 // end of __MEMORY_H__
119 // indent-tabs-mode: t