reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
HeapInstanceCounter.cxx
Go to the documentation of this file.
2#include "rutil/Mutex.hxx"
3#include "rutil/Logger.hxx"
4#include "rutil/Data.hxx"
5
6#include "rutil/ResipAssert.h"
7#include <map>
8
9using namespace std;
10using namespace resip;
11
12#define RESIPROCATE_SUBSYSTEM resip::Subsystem::STATS
13
14typedef map<void *, unsigned long> AllocationSizeMap;
15
16//namespace // unnamed namespace
17//{
31
32// .dlb. should be using comparitor on typeinfo
33typedef map<Data, InstanceCounts> AllocationMap;
36//}
37
38#ifdef RESIP_HEAP_COUNT
39void
41{
43 if (allocationMap.empty())
44 {
45 WarningLog(<< "No allocations.");
46 }
47 else
48 {
49 AllocationMap::const_iterator i(allocationMap.begin());
50 AllocationMap::const_iterator iEnd(allocationMap.end());
51 for (; i != iEnd; ++i)
52 {
53 if (i->second.total)
54 {
55 //abi::__cxa_demangle(typeid(obj).name(), 0, 0, &status);
56 WarningLog(<< i->first << " " << i->second.total << " > " << i->second.outstanding << ", " <<
57 i->second.totalBytesOutstanding);
58 }
59 }
60 }
61}
62
63void*
64HeapInstanceCounter::allocate(size_t bytes,
65 const type_info& ti)
66{
67 void* addr = ::operator new(bytes);
68
69 { //lock scope
70 // WarningLog(<< "allocated " << ti.name());
72
73 const Data name(Data::Share, ti.name(), strlen(ti.name()));
74 InstanceCounts &counts = allocationMap[name];
75
76 counts.total += 1;
77 counts.outstanding += 1;
78 counts.totalBytesOutstanding += bytes;
79 counts.allocationSizes[addr] = bytes;
80 }
81 return addr;
82}
83
84void
85HeapInstanceCounter::deallocate(void* addr,
86 const type_info& ti)
87{
88 {//lock scope
89 // WarningLog(<< "deallocated " << ti.name());
91 const Data name(Data::Share, ti.name(), strlen(ti.name()));
92 if (allocationMap.find(name) != allocationMap.end())
93 {
94 InstanceCounts &counts = allocationMap[name];
95
96 if (counts.allocationSizes.find(addr) != counts.allocationSizes.end())
97 {
98 counts.outstanding -= 1;
99 counts.totalBytesOutstanding -= counts.allocationSizes[addr];
100 counts.allocationSizes.erase(addr);
101 }
102 }
103 }
104 ::operator delete(addr);
105}
106
107#else // RESIP_HEAP_COUNT
108void
111
112#endif // RESIP_HEAP_COUNT
113
114/* ====================================================================
115 * The Vovida Software License, Version 1.0
116 *
117 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 *
123 * 1. Redistributions of source code must retain the above copyright
124 * notice, this list of conditions and the following disclaimer.
125 *
126 * 2. Redistributions in binary form must reproduce the above copyright
127 * notice, this list of conditions and the following disclaimer in
128 * the documentation and/or other materials provided with the
129 * distribution.
130 *
131 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
132 * and "Vovida Open Communication Application Library (VOCAL)" must
133 * not be used to endorse or promote products derived from this
134 * software without prior written permission. For written
135 * permission, please contact vocal@vovida.org.
136 *
137 * 4. Products derived from this software may not be called "VOCAL", nor
138 * may "VOCAL" appear in their name, without prior written
139 * permission of Vovida Networks, Inc.
140 *
141 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
142 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
143 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
144 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
145 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
146 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
147 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
148 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
149 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
150 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
151 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
152 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
153 * DAMAGE.
154 *
155 * ====================================================================
156 *
157 * This software consists of voluntary contributions made by Vovida
158 * Networks, Inc. and many individuals on behalf of Vovida Networks,
159 * Inc. For more information on Vovida Networks, Inc., please see
160 * <http://www.vovida.org/>.
161 *
162 */
AllocationMap allocationMap
map< void *, unsigned long > AllocationSizeMap
map< Data, InstanceCounts > AllocationMap
Mutex allocationMutex
#define WarningLog(args_)
Definition Logger.hxx:134
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
@ Share
The Data instance will use the buffer in a read-only mode.
Definition Data.hxx:266
dcm! – add UnusedChecking(_enum) below;
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28
AllocationSizeMap allocationSizes