Hello Allen,
Allen Bierbaum wrote:
On Wed, Feb 25, 2009 at 10:15 AM, Carsten Neumann
<[email protected]> wrote:
Allen Bierbaum wrote:
Another question about detecting this, does the MemoryConsumption
helper class track down memory usage across multiple aspects. For
example if multiple copies of an fc are held across contexts, does it
count up all the copies or just one per fc?
It only counts a single aspect copy.
Can you extend this so there is an option for asking it to count usage
across aspects? (ie. is this even possible to do?)
I've attached a patch (lightly tested) that modifies the thing to count
per aspect memory consumption, however it does not take into account if
data is shared between aspects.
If you need that you'd have to use MField<T>::isShared() or even look at
MField<T>::_uiSharedWith to determine what aspect share the data.
We are still running into strange memory consumption issues and I want
to see where all of it is going.
I hope you can find out where the mem is going, with IEEE VR approaching
fast I'm a bit time constrained at the moment...
Cheers,
Carsten
diff --git a/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.h b/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.h
index 1685860..f643c4d 100644
--- a/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.h
+++ b/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.h
@@ -106,6 +106,15 @@ OutPtrT dynamic_fcptr_cast(FieldContainer * const pPtr)
}
#endif
+/*! This provides debug access to protected/private functions of
+ FieldContainer.
+ */
+struct FCDebugAccess
+{
+ static inline AspectStore *getAspectStore(FieldContainer *fc);
+};
+
+
OSG_END_NAMESPACE
#include "OSGContainerPtrFuncs.inl"
diff --git a/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.inl b/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.inl
index e62207a..cc082ce 100644
--- a/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.inl
+++ b/Source/Base/FieldContainer/Base/OSGContainerPtrFuncs.inl
@@ -38,5 +38,10 @@
OSG_BEGIN_NAMESPACE
+inline AspectStore *FCDebugAccess::getAspectStore(FieldContainer *fc)
+{
+ return fc->getAspectStore();
+}
+
OSG_END_NAMESPACE
diff --git a/Source/Base/FieldContainer/Base/OSGFieldContainer.h b/Source/Base/FieldContainer/Base/OSGFieldContainer.h
index 8adba97..db59005 100644
--- a/Source/Base/FieldContainer/Base/OSGFieldContainer.h
+++ b/Source/Base/FieldContainer/Base/OSGFieldContainer.h
@@ -69,6 +69,8 @@ class SFieldConnector;
template <class FieldT>
class MFieldConnector;
+class FCDebugAccess;
+
/*! \ingroup GrpBaseFieldContainerBase
*/
@@ -481,6 +483,7 @@ class FieldContainer : public ReflexiveContainer
template <class FieldT>
friend class MFieldConnector;
+ friend class FCDebugAccess;
/*!\brief prohibit default function (move to 'public' if needed) */
void operator =(const FieldContainer &source);
diff --git a/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.cpp b/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.cpp
index cfa75b2..067b1a5 100644
--- a/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.cpp
+++ b/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.cpp
@@ -39,6 +39,7 @@
#include "OSGFieldContainerUtils.h"
#include "OSGFieldContainerSFields.h"
#include "OSGFieldContainerMFields.h"
+#include "OSGContainerPtrFuncs.h"
#include "OSGAttachment.h"
#include "OSGAttachmentMapSFields.h"
#include "OSGNameAttachment.h"
@@ -305,56 +306,98 @@ void MemoryConsumption::scan(void)
if(pFC == NULL)
continue;
- TypeMemMapIt tmIt = _memMap.find(pFC->getType().getId());
- UInt32 binSize = pFC->getBinSize(TypeTraits<BitVector>::BitsSet);
+ UInt32 typeId = pFC->getType().getId();
+ TypeMemMapIt tmIt = _memMap.find(typeId);
- if(tmIt != _memMap.end())
+ if(tmIt == _memMap.end())
{
- tmIt->second.first += binSize;
- tmIt->second.second += 1;
+ _memMap[typeId] = MemInfo();
+ tmIt = _memMap.find(typeId);
}
- else
+
+ tmIt->second.instanceCount += 1;
+
+ // iterate over all aspects and sum their memory consumption
+ AspectStore *as = FCDebugAccess::getAspectStore(pFC);
+ UInt32 numAs = as->getNumAspects();
+
+ tmIt->second.aspectMem.resize(numAs, 0);
+
+ for(UInt32 a = 0; a < numAs; ++a)
{
- _memMap[pFC->getType().getId()] = MemCountPair(binSize, 1);
+ FieldContainer *pFCAs = as->getPtr(a);
+
+ if(pFCAs == NULL)
+ continue;
+
+ tmIt->second.aspectMem[a] +=
+ pFCAs->getBinSize(TypeTraits<BitVector>::BitsSet);
}
}
}
-
void MemoryConsumption::print(std::ostream &os, bool ignoreProto) const
{
TypeMemMapConstIt tmIt = _memMap.begin();
TypeMemMapConstIt tmEnd = _memMap.end ();
- UInt32 totalMem = 0;
- UInt32 totalCount = 0;
- boost::format formatter("%|1$-25| [%|2$8|] Byte [%|3$8.0f|] kByte [%|4$4|]\n");
+ boost::format beginFormat ("%|1$-25| [%|2$8|] - [%|3$2|] aspects:");
+ boost::format aspectFormat(" [%|1$8|] Byte");
+ boost::format endFormat (" => [%|1$8|] Byte total");
+
+ UInt32 totalMem = 0;
+ UInt32 totalCount = 0;
+ AspectMemStore totalAspectMem;
for(; tmIt != tmEnd; ++tmIt)
{
- FieldContainerType *fcType =
+ UInt32 typeTotal = 0;
+ FieldContainerType *fcType =
FieldContainerFactory::the()->findType(tmIt->first);
if(fcType == NULL)
continue;
- if(ignoreProto && tmIt->second.second == 1)
+ if(ignoreProto && tmIt->second.instanceCount == 1)
continue;
- os << formatter % fcType->getCName()
- % tmIt->second.first
- % (tmIt->second.first / 1024.f)
- % tmIt->second.second;
+ os << beginFormat % fcType->getCName()
+ % tmIt->second.instanceCount
+ % tmIt->second.aspectMem.size();
+
+ totalAspectMem.resize(tmIt->second.aspectMem.size(), 0);
+
+ AspectMemStoreConstIt amsIt = tmIt->second.aspectMem.begin();
+ AspectMemStoreConstIt amsEnd = tmIt->second.aspectMem.end ();
- totalMem += tmIt->second.first;
- totalCount += tmIt->second.second;
+ for(UInt32 a = 0; amsIt != amsEnd; ++amsIt, ++a)
+ {
+ typeTotal += *amsIt;
+ totalAspectMem[a] += *amsIt;
+
+ os << aspectFormat % *amsIt;
+ }
+
+ os << endFormat % typeTotal << "\n";
+
+ totalCount += tmIt->second.instanceCount;
+ totalMem += typeTotal;
}
os << "--------------------------------------------\n";
- os << formatter % "Total"
- % totalMem
- % (totalMem / 1024.f)
- % totalCount;
+ os << beginFormat % "Total"
+ % totalCount
+ % totalAspectMem.size();
+
+ AspectMemStoreConstIt amsIt = totalAspectMem.begin();
+ AspectMemStoreConstIt amsEnd = totalAspectMem.end ();
+
+ for(; amsIt != amsEnd; ++amsIt)
+ {
+ os << aspectFormat % *amsIt;
+ }
+
+ os << endFormat % totalMem << std::endl;
}
MemoryConsumption::TypeMemMapConstIt MemoryConsumption::beginMap(void) const
diff --git a/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.h b/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.h
index 59a3530..e9f25d7 100644
--- a/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.h
+++ b/Source/System/FieldContainer/Misc/OSGFieldContainerUtils.h
@@ -64,11 +64,20 @@ bool compareContainerEqual(const FieldContainer *lhs,
class OSG_SYSTEM_DLLMAPPING MemoryConsumption
{
public:
- typedef std::pair<UInt32, UInt32 > MemCountPair;
- typedef std::map <UInt32, MemCountPair> TypeMemMap;
+ typedef std::vector<UInt32> AspectMemStore;
+ typedef AspectMemStore::iterator AspectMemStoreIt;
+ typedef AspectMemStore::const_iterator AspectMemStoreConstIt;
+
+ struct MemInfo
+ {
+ UInt32 instanceCount;
+ AspectMemStore aspectMem;
+ };
+
+ typedef std::map<UInt32, MemInfo> TypeMemMap;
typedef TypeMemMap::iterator TypeMemMapIt;
typedef TypeMemMap::const_iterator TypeMemMapConstIt;
-
+
void scan (void );
void print(std::ostream &os, bool ignoreProto = true) const;
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users