git-svn-id: svn://db.shs.com.ru/pip@469 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-25 12:38:43 +00:00
parent 7f2fa410cf
commit 826db9e87d
7 changed files with 266 additions and 68 deletions

View File

@@ -37,6 +37,27 @@
* */
PIDiagnostics::State::State() {
immediate_freq = integral_freq = 0.f;
received_packets_per_sec = 0ull;
received_packets = 0ull;
received_packets_wrong = 0ull;
received_bytes_per_sec = 0ull;
received_bytes = 0ull;
received_bytes_wrong = 0ull;
sended_packets_per_sec = 0ull;
sended_packets = 0ull;
sended_bytes_per_sec = 0ull;
sended_bytes = 0ull;
receive_speed = send_speed = PIString::readableSize(0) + "/s";
quality = PIDiagnostics::Unknown;
}
PIDiagnostics::PIDiagnostics(bool start_): PITimer(PITimer::Pool) {
disconn_ = 0.;
setInterval(100);
@@ -47,13 +68,33 @@ PIDiagnostics::PIDiagnostics(bool start_): PITimer(PITimer::Pool) {
}
PIDiagnostics::State PIDiagnostics::state() const {
constLock();
State ret = cur_state;
constUnlock();
return ret;
}
PIString PIDiagnostics::receiveSpeed() const {
constLock();
PIString ret = cur_state.receive_speed;
constUnlock();
return ret;
}
PIString PIDiagnostics::sendSpeed() const {
constLock();
PIString ret = cur_state.send_speed;
constUnlock();
return ret;
}
void PIDiagnostics::reset() {
lock();
qual = PIDiagnostics::Unknown;
speedRecv = speedSend = PIString::readableSize(0) + "/s";
immediate_freq = integral_freq = 0.f;
count_wrong = count_recv = count_send = bytes_wrong = bytes_recv = bytes_send = 0;
packets_recv_sec = packets_send_sec = bytes_recv_sec = bytes_send_sec = 0;
cur_state = State();
if (disconn_ != 0.) {
int hist_size = history_rec.size();
history_rec.clear();
@@ -71,13 +112,13 @@ void PIDiagnostics::received(int size, bool correct) {
if (correct) {
e.cnt_ok++;
e.bytes_ok += size;
count_recv++;
bytes_recv += size;
cur_state.received_packets++;
cur_state.received_bytes += size;
} else {
e.cnt_fail++;
e.bytes_fail += size;
count_wrong++;
bytes_wrong += size;
cur_state.received_packets_wrong++;
cur_state.received_bytes_wrong += size;
}
e.empty = false;
unlock();
@@ -89,8 +130,8 @@ void PIDiagnostics::sended(int size) {
Entry & e(history_send.front());
e.cnt_ok++;
e.bytes_ok += size;
count_send++;
bytes_send += size;
cur_state.sended_packets++;
cur_state.sended_bytes += size;
e.empty = false;
unlock();
}
@@ -106,25 +147,25 @@ void PIDiagnostics::tick(void * , int ) {
float its = disconn_ * (float(tcnt_send) / history_send.size());
float hz = interval() / 1000.f;
if (tcnt_recv == 0) {
integral_freq = immediate_freq = 0;
packets_recv_sec = bytes_recv_sec = 0;
cur_state.integral_freq = cur_state.immediate_freq = 0;
cur_state.received_packets_per_sec = cur_state.received_bytes_per_sec = 0;
} else {
integral_freq = recv.cnt_ok / itr;
packets_recv_sec = ullong(float(recv.cnt_ok) / itr);
bytes_recv_sec = ullong(double(recv.bytes_ok) / itr);
immediate_freq = double(history_rec.front().cnt_ok) / hz;
cur_state.integral_freq = recv.cnt_ok / itr;
cur_state.received_packets_per_sec = ullong(float(recv.cnt_ok) / itr);
cur_state.received_bytes_per_sec = ullong(double(recv.bytes_ok) / itr);
cur_state.immediate_freq = double(history_rec.front().cnt_ok) / hz;
}
if (tcnt_send == 0) {
packets_send_sec = bytes_send_sec = 0;
cur_state.sended_packets_per_sec = cur_state.sended_bytes_per_sec = 0;
} else {
packets_send_sec = ullong(float(send.cnt_ok) / its);
bytes_send_sec = ullong(double(send.bytes_ok) / its);
cur_state.sended_packets_per_sec = ullong(float(send.cnt_ok) / its);
cur_state.sended_bytes_per_sec = ullong(double(send.bytes_ok) / its);
}
// piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
// speedRecv = PIString::readableSize(ullong(double(history_rec.front().bytes_ok) / hz)) + "/s";
// speedSend = PIString::readableSize(ullong(double(history_send.front().bytes_ok) / hz)) + "/s";
speedRecv = PIString::readableSize(bytes_recv_sec) + "/s";
speedSend = PIString::readableSize(bytes_send_sec) + "/s";
cur_state.receive_speed = PIString::readableSize(cur_state.received_bytes_per_sec) + "/s";
cur_state.send_speed = PIString::readableSize(cur_state.sended_bytes_per_sec) + "/s";
int arc = recv.cnt_ok + recv.cnt_fail;
float good_percents = 0.f;
if (arc > 0) good_percents = (float)recv.cnt_ok / arc * 100.f;
@@ -147,9 +188,9 @@ void PIDiagnostics::tick(void * , int ) {
history_rec.enqueue(e);
history_send.enqueue(e);
}
if (diag != qual) {
qualityChanged(diag, qual);
qual = diag;
if (diag != cur_state.quality) {
qualityChanged(diag, cur_state.quality);
cur_state.quality = diag;
}
unlock();
}
@@ -193,3 +234,12 @@ void PIDiagnostics::changeDisconnectTimeout(float disct) {
unlock();
}
void PIDiagnostics::constLock() const {
const_cast<PIDiagnostics*>(this)->lock();
}
void PIDiagnostics::constUnlock() const {
const_cast<PIDiagnostics*>(this)->unlock();
}