X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RIC-E2-TERMINATION%2FstatCollector.h;h=706426db7ad488fd2771070193a3621d237982a4;hb=233facdf921c63a800c75724d153998b91b12a36;hp=bb4ce5d382b0ec1b1ead344b030e7f3d937af6d9;hpb=a0f0db639a7b01079db4ea4969c3b79b9ec58340;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/statCollector.h b/RIC-E2-TERMINATION/statCollector.h index bb4ce5d..706426d 100644 --- a/RIC-E2-TERMINATION/statCollector.h +++ b/RIC-E2-TERMINATION/statCollector.h @@ -33,6 +33,9 @@ #include #include #include +#include + +using namespace tbb; typedef struct statResult { std::string ranName; @@ -72,10 +75,10 @@ public: for (auto const &e : recvMessages) { statResult_t result {}; result.ranName = e.first; - result.receivedMessages = e.second.load(std::memory_order_acquire); + result.receivedMessages = e.second; auto found = sentMessages.find(result.ranName); if (found != sentMessages.end()) { - result.sentMessages = found->second.load(std::memory_order_acquire); + result.sentMessages = found->second; } else { result.sentMessages = 0; } @@ -89,29 +92,68 @@ public: StatCollector& operator=(const StatCollector&)= delete; private: - std::unordered_map> sentMessages; - std::unordered_map> recvMessages; + tbb::concurrent_unordered_map sentMessages; + //std::unordered_map sentMessages; + //std::unordered_map recvMessages; + tbb::concurrent_unordered_map recvMessages; std::vector results; - StatCollector() = default; +// StatCollector() = default; + StatCollector() { + sentMessages.clear(); + recvMessages.clear(); + } ~StatCollector() = default; - void inline static increment(std::unordered_map> &map, const std::string &key) { - auto found = map.find(key); - if (found != map.end()) { //inc - map[key].fetch_add(1, std::memory_order_release); - } else { //add - //sentMessages.emplace(std::make_pair(std::string(key), std::atomic(0))); - map.emplace(std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(0)); + void increment(tbb::concurrent_unordered_map &map, const std::string &key); + +}; + +void StatCollector::increment(tbb::concurrent_unordered_map &map, const std::string &key) { + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + if (map.empty()) { + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + map.emplace(std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(1)); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + return; + } + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + auto found = map.find(key); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + if (found != map.end()) { //inc + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } + map[key]++; + } else { //add + //sentMessages.emplace(std::make_pair(std::string(key), std::atomic(0))); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); } + map.emplace(std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(1)); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_INFO, "in file %s at finction %s in line %d", __FILE__, __func__, __LINE__); + } } -}; +} // must define this to allow StatCollector private variables to be known to compiler linker