#include <iostream>
-MemBlobStats MemBlob::Stats;
InstanceIdDefinitions(MemBlob, "blob");
/* MemBlobStats */
-MemBlobStats::MemBlobStats(): alloc(0), live(0), append(0), liveBytes(0)
-{}
-
MemBlobStats&
MemBlobStats::operator += (const MemBlobStats& s)
{
return os;
}
+static auto &
+WriteableStats()
+{
+ static const auto stats = new MemBlobStats();
+ return *stats;
+}
+
+const MemBlobStats &
+MemBlob::GetStats()
+{
+ return WriteableStats();
+}
+
/* MemBlob */
MemBlob::MemBlob(const MemBlob::size_type reserveSize) :
{
if (mem || capacity)
memFreeBuf(capacity, mem);
- Stats.liveBytes -= capacity;
- --Stats.live;
+ auto &stats = WriteableStats();
+ stats.liveBytes -= capacity;
+ --stats.live;
SBufStats::RecordMemBlobSizeAtDestruct(capacity);
debugs(MEMBLOB_DEBUGSECTION,9, "destructed, this="
debugs(MEMBLOB_DEBUGSECTION, 8,
id << " memAlloc: requested=" << minSize <<
", received=" << capacity);
- ++Stats.live;
- ++Stats.alloc;
- Stats.liveBytes += capacity;
+ auto &stats = WriteableStats();
+ ++stats.live;
+ ++stats.alloc;
+ stats.liveBytes += capacity;
}
void
{
Must(willFit(n));
size += n;
- ++Stats.append;
+ ++WriteableStats().append;
}
void
memmove(mem + size, source, n);
size += n;
}
- ++Stats.append;
+ ++WriteableStats().append;
}
void
}
}
-const MemBlobStats&
-MemBlob::GetStats()
-{
- return Stats;
-}
-
std::ostream&
MemBlob::dump(std::ostream &os) const
{
class MemBlobStats
{
public:
- MemBlobStats();
-
/// dumps class-wide statistics
std::ostream& dump(std::ostream& os) const;
MemBlobStats& operator += (const MemBlobStats&);
public:
- uint64_t alloc; ///< number of MemBlob instances created so far
- uint64_t live; ///< number of MemBlob instances currently alive
- uint64_t append; ///< number of MemBlob::append() calls
- uint64_t liveBytes; ///< the total size of currently allocated storage
+ uint64_t alloc = 0; ///< number of MemBlob instances created so far
+ uint64_t live = 0; ///< number of MemBlob instances currently alive
+ uint64_t append = 0; ///< number of MemBlob::append() calls
+ uint64_t liveBytes = 0; ///< the total size of currently allocated storage
};
/** Refcountable, fixed-size, content-agnostic memory buffer.
const InstanceId<MemBlob> id; ///< blob identifier
private:
- static MemBlobStats Stats; ///< class-wide statistics
-
void memAlloc(const size_type memSize);
/// whether the offset points to the end of the used area