MCPcopy Create free account
hub / github.com/dmlc/dmlc-core / getFor

Method getFor

include/dmlc/concurrentqueue.h:3120–3194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3118
3119 private:
3120 static MemStats getFor(ConcurrentQueue* q)
3121 {
3122 MemStats stats = { 0 };
3123
3124 stats.elementsEnqueued = q->size_approx();
3125
3126 auto block = q->freeList.head_unsafe();
3127 while (block != nullptr) {
3128 ++stats.allocatedBlocks;
3129 ++stats.freeBlocks;
3130 block = block->freeListNext.load(std::memory_order_relaxed);
3131 }
3132
3133 for (auto ptr = q->producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
3134 bool implicit = dynamic_cast<ImplicitProducer*>(ptr) != nullptr;
3135 stats.implicitProducers += implicit ? 1 : 0;
3136 stats.explicitProducers += implicit ? 0 : 1;
3137
3138 if (implicit) {
3139 auto prod = static_cast<ImplicitProducer*>(ptr);
3140 stats.queueClassBytes += sizeof(ImplicitProducer);
3141 auto head = prod->headIndex.load(std::memory_order_relaxed);
3142 auto tail = prod->tailIndex.load(std::memory_order_relaxed);
3143 auto hash = prod->blockIndex.load(std::memory_order_relaxed);
3144 if (hash != nullptr) {
3145 for (size_t i = 0; i != hash->capacity; ++i) {
3146 if (hash->index[i]->key.load(std::memory_order_relaxed) != ImplicitProducer::INVALID_BLOCK_BASE && hash->index[i]->value.load(std::memory_order_relaxed) != nullptr) {
3147 ++stats.allocatedBlocks;
3148 ++stats.ownedBlocksImplicit;
3149 }
3150 }
3151 stats.implicitBlockIndexBytes += hash->capacity * sizeof(typename ImplicitProducer::BlockIndexEntry);
3152 for (; hash != nullptr; hash = hash->prev) {
3153 stats.implicitBlockIndexBytes += sizeof(typename ImplicitProducer::BlockIndexHeader) + hash->capacity * sizeof(typename ImplicitProducer::BlockIndexEntry*);
3154 }
3155 }
3156 for (; details::circular_less_than<index_t>(head, tail); head += BLOCK_SIZE) {
3157 //auto block = prod->get_block_index_entry_for_index(head);
3158 ++stats.usedBlocks;
3159 }
3160 }
3161 else {
3162 auto prod = static_cast<ExplicitProducer*>(ptr);
3163 stats.queueClassBytes += sizeof(ExplicitProducer);
3164 auto tailBlock = prod->tailBlock;
3165 bool wasNonEmpty = false;
3166 if (tailBlock != nullptr) {
3167 auto block = tailBlock;
3168 do {
3169 ++stats.allocatedBlocks;
3170 if (!block->template is_empty<explicit_context>() || wasNonEmpty) {
3171 ++stats.usedBlocks;
3172 wasNonEmpty = wasNonEmpty || block != tailBlock;
3173 }
3174 ++stats.ownedBlocksExplicit;
3175 block = block->next;
3176 } while (block != tailBlock);
3177 }

Callers

nothing calls this directly

Calls 3

head_unsafeMethod · 0.80
next_prodMethod · 0.80
size_approxMethod · 0.45

Tested by

no test coverage detected