Changeset View
Changeset View
Standalone View
Standalone View
plugins/process/network/helper/Accumulator.cpp
Show All 32 Lines | 31 | { | |||
---|---|---|---|---|---|
33 | m_mapping = mapping; | 33 | m_mapping = mapping; | ||
34 | 34 | | |||
35 | m_running = true; | 35 | m_running = true; | ||
36 | m_thread = std::thread { &Accumulator::loop, this }; | 36 | m_thread = std::thread { &Accumulator::loop, this }; | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | Accumulator::PidDataCounterHash Accumulator::data() | 39 | Accumulator::PidDataCounterHash Accumulator::data() | ||
40 | { | 40 | { | ||
41 | std::lock_guard<std::mutex> lock{m_mutex}; | ||||
42 | | ||||
41 | auto tmp = m_data; | 43 | auto tmp = m_data; | ||
42 | 44 | | |||
43 | auto toErase = std::vector<int>{}; | 45 | auto toErase = std::vector<int>{}; | ||
44 | for (auto &entry : m_data) { | 46 | for (auto &entry : m_data) { | ||
45 | if (entry.second.first == 0 && entry.second.second == 0) { | 47 | if (entry.second.first == 0 && entry.second.second == 0) { | ||
46 | toErase.push_back(entry.first); | 48 | toErase.push_back(entry.first); | ||
47 | } else { | 49 | } else { | ||
48 | entry.second.first = 0; | 50 | entry.second.first = 0; | ||
Show All 24 Lines | 74 | if (result.pid == 0) | |||
73 | continue; | 75 | continue; | ||
74 | 76 | | |||
75 | addData(result.direction, packet, result.pid); | 77 | addData(result.direction, packet, result.pid); | ||
76 | } | 78 | } | ||
77 | } | 79 | } | ||
78 | 80 | | |||
79 | void Accumulator::addData(Packet::Direction direction, const Packet &packet, int pid) | 81 | void Accumulator::addData(Packet::Direction direction, const Packet &packet, int pid) | ||
80 | { | 82 | { | ||
83 | std::lock_guard<std::mutex> lock{m_mutex}; | ||||
84 | | ||||
81 | auto itr = m_data.find(pid); | 85 | auto itr = m_data.find(pid); | ||
82 | if (itr == m_data.end()) { | 86 | if (itr == m_data.end()) { | ||
83 | m_data.emplace(pid, InboundOutboundData{0, 0}); | 87 | m_data.emplace(pid, InboundOutboundData{0, 0}); | ||
84 | } | 88 | } | ||
85 | 89 | | |||
86 | if (direction == Packet::Direction::Inbound) { | 90 | if (direction == Packet::Direction::Inbound) { | ||
87 | m_data[pid].first += packet.size(); | 91 | m_data[pid].first += packet.size(); | ||
88 | } else { | 92 | } else { | ||
89 | m_data[pid].second += packet.size(); | 93 | m_data[pid].second += packet.size(); | ||
90 | }; | 94 | }; | ||
91 | } | 95 | } |