24 #include <boost/format.hpp> 28 #ifndef SENF_DISABLE_CONSOLE 41 #ifndef SENF_PACKET_NO_HEAP_INTERPRETERS 46 #ifndef SENF_DISABLE_CONSOLE 50 struct ConsoleDirRegistration
52 ConsoleDirRegistration()
58 fty::Command(&ConsoleDirRegistration::memoryStatus));
60 .
add(
"dumpAnnotationRegistry",
63 .
add(
"pktHandleCount",
64 fty::Command(&ConsoleDirRegistration::pktCount));
67 static void memoryStatus(std::ostream & os)
69 os <<
"SENF_PACKET_PREALLOC_INTERPRETERS = " << SENF_PACKET_PREALLOC_INTERPRETERS <<
"\n" 70 #ifdef SENF_PACKET_NO_HEAP_INTERPRETERS 71 <<
"SENF_PACKET_NO_HEAP_INTERPRETERS\n" 73 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC 74 <<
"SENF_PACKET_ALTERNATIVE_PREALLOC\n" 78 #ifndef SENF_PACKET_NO_HEAP_INTERPRETERS 86 static void pktCount(std::ostream & os)
91 static ConsoleDirRegistration instance_;
94 ConsoleDirRegistration ConsoleDirRegistration::instance_;
100 #ifndef SENF_PACKET_NO_HEAP_INTERPRETERS 102 prefix_ void senf::detail::PacketImpl::destroySelf()
110 PacketInterpreterBase * p (&(*i));
111 interpreters_.erase(i);
113 if (preallocHeapcount_ == 0)
122 SENF_ASSERT(refcount_ >= 1,
"Internal failure: Releasing dead PacketImpl ??");
127 if (refcount_ == 1) {
140 os <<
"PacketImpl @" <<
this <<
"-" <<
static_cast<void*
>(
static_cast<byte*
>(
static_cast<void*
>(
this+1))-1)
141 <<
" refcount=" << refcount()
142 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC 143 <<
" preallocHigh=" << preallocHigh_
145 #ifndef SENF_PACKET_NO_HEAP_INTERPRETERS 146 <<
" preallocHeapcount=" << preallocHeapcount_
149 std::set<void*> used;
153 std::set<void*> free;
155 PreallocSlot * p (preallocFree_);
156 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC 159 while (p != prealloc_ + SENF_PACKET_PREALLOC_INTERPRETERS)
163 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC 166 p += p->nextOffset_ + 1;
170 for (
unsigned i (0); i <
171 #ifdef SENF_PACKET_ALTERNATIVE_PREALLOC 174 SENF_PACKET_PREALLOC_INTERPRETERS
177 void * p (&(prealloc_[i]));
179 os <<
" free @" << p << std::endl;
180 else if (! used.count(p))
181 os <<
" unlinked @" << p
182 <<
" refcount=" << static_cast<PacketInterpreterBase*>(p)->refcount() << std::endl;
188 interpreters_.push_back(*p);
194 interpreters_.push_front(*p);
202 interpreters_.insert(i, *p);
212 truncateInterpreters(n);
213 iterator first (boost::next(begin(),self->begin_));
214 data_.erase(first, boost::next(begin(),self->end_));
215 updateIterators(
self,self->begin_,-self->size());
226 interpreters_.erase(i);
261 for (; i != i_end; ++i) {
273 i != AnnotationRegistry::instance().end(); ++i) {
274 void * antn (annotation(*i));
276 AnnotationRegistry::instance().dump(*i, os, antn);
282 ::memset(simpleAnnotations_, 0,
sizeof(simpleAnnotations_));
283 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS 284 complexAnnotations_.clear();
290 std::copy(&other.simpleAnnotations_[0], &other.simpleAnnotations_[0] +
291 sizeof(simpleAnnotations_)/
sizeof(simpleAnnotations_[0]), simpleAnnotations_);
292 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS 293 complexAnnotations_.assign(
294 other.complexAnnotations_.begin(), other.complexAnnotations_.end());
298 #ifndef SENF_PACKET_NO_COMPLEX_ANNOTATIONS 300 prefix_ void * senf::detail::PacketImpl::complexAnnotation(AnnotationRegistry::key_type key)
302 SENF_ASSERT( key < 0,
"complexAnnotation called with invalid key");
304 || complexAnnotations_.is_null(-key-1))
305 ? 0 : complexAnnotations_[-key-1].
get();
313 prefix_ void senf::detail::AnnotationRegistry::dump(key_type key, std::ostream & os,
318 if (i != registry_.end()) {
320 i->second->v_dump(os, annotation);
325 prefix_ void senf::detail::AnnotationRegistry::dumpRegistrations(std::ostream & os)
328 boost::format fmt (
"%-56.56s %-4.4s %-7.7s %5d\n");
329 os <<
"SENF_PACKET_ANNOTATION_SLOTS = " << SENF_PACKET_ANNOTATION_SLOTS <<
"\n" 330 <<
"SENF_PACKET_ANNOTATION_SLOTSIZE = " << SENF_PACKET_ANNOTATION_SLOTSIZE <<
"\n";
331 #ifdef SENF_PACKET_NO_COMPLEX_ANNOTATIONS 332 os <<
"SENF_PACKET_NO_COMPLEX_ANNOTATIONS defined\n";
334 os << fmt %
"TYPE" %
"FAST" %
"COMPLEX" %
"SIZE";
337 key_type key (i->second);
338 std::string nm (i->first);
339 if (nm.size() > 56) nm.erase(nm.begin(), nm.begin()+nm.size()-32);
342 % (key >= 0 ?
"yes" :
"no")
343 % (isComplex(key) ?
"yes" :
"no")
350 senf::detail::AnnotationRegistry::instance().dumpRegistrations(os);
void memDebug(std::ostream &os)
void copy(ListParser< ListPolicy > const &listParser, OutputIterator result)
senf::detail::packet::byte byte
senf::detail::packet::difference_type difference_type
static std::int32_t const & pktCount()
void dumpAnnotations(std::ostream &os)
std::string fieldName(std::string const &s)
void prependInterpreter(PacketInterpreterBase *p)
Internal: Base packet interpreter class.
senf::detail::packet::iterator iterator
console::ScopedDirectory & packetConsoleDir()
raw_container::const_iterator const_iterator
Packet data STL-sequence view.
raw_container::size_type size_type
Internal: Packet data storage.
raw_container::iterator iterator
static size_type maxPreallocHigh()
senf::detail::packet::size_type size_type
#define SENF_ASSERT(x, comment)
raw_container::difference_type difference_type
void assignAnnotations(PacketImpl const &other)
static size_type maxPreallocHeapcount()
void dumpPacketAnnotationRegistry(std::ostream &os)
Dump annotation registry debug information.
void appendInterpreter(PacketInterpreterBase *p)
void clear(PacketData *self)
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)