code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Speed and quality in/out diagnostics
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Speed and quality in/out diagnostics
Andrey Bychkov work.a.b@yandex.ru, Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pidiagnostics.h"
@@ -39,38 +39,36 @@
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;
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;
quality = PIDiagnostics::Unknown;
}
PIDiagnostics::PIDiagnostics(bool start_): PITimer(/*PITimer::Pool*/) {
disconn_ = 0.;
//piCout << "PIDiagnostics construct";
// piCout << "PIDiagnostics construct";
setInterval(100);
reset();
setDisconnectTimeout(3.);
changeDisconnectTimeout(3.);
if (start_) PITimer::start(100);
//piCout << "PIDiagnostics construct done";
// piCout << "PIDiagnostics construct done";
}
PIDiagnostics::~PIDiagnostics() {
PITimer::stop();
//piCout << "~PIDiagnostics start...";
//piCout << "~PIDiagnostics done!";
// piCout << "~PIDiagnostics start...";
// piCout << "~PIDiagnostics done!";
}
@@ -151,49 +149,52 @@ void PIDiagnostics::sended(int size) {
}
void PIDiagnostics::tick(void * , int ) {
void PIDiagnostics::tick(void *, int) {
mutex_state.lock();
//piCoutObj << "lock";
// piCoutObj << "lock";
int tcnt_recv = 0;
int tcnt_send = 0;
Entry send = calcHistory(history_send, tcnt_send);
Entry recv = calcHistory(history_rec, tcnt_recv);
float itr = disconn_ * (float(tcnt_recv) / history_rec.size());
float its = disconn_ * (float(tcnt_send) / history_send.size());
float hz = interval() / 1000.f;
Entry send = calcHistory(history_send, tcnt_send);
Entry recv = calcHistory(history_rec, tcnt_recv);
float itr = disconn_ * (float(tcnt_recv) / history_rec.size());
float its = disconn_ * (float(tcnt_send) / history_send.size());
float hz = interval() / 1000.f;
if (tcnt_recv == 0) {
cur_state.integral_freq = cur_state.immediate_freq = 0;
cur_state.received_packets_per_sec = cur_state.received_bytes_per_sec = 0;
} else {
cur_state.integral_freq = recv.cnt_ok / itr;
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;
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) {
cur_state.sended_packets_per_sec = cur_state.sended_bytes_per_sec = 0;
} else {
cur_state.sended_packets_per_sec = ullong(float(send.cnt_ok) / its);
cur_state.sended_bytes_per_sec = ullong(double(send.bytes_ok) / its);
cur_state.sended_bytes_per_sec = ullong(double(send.bytes_ok) / its);
}
//piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
// piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
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;
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;
PIDiagnostics::Quality diag;
if (tcnt_recv == 0) {
diag = PIDiagnostics::Unknown;
} else {
if (good_percents == 0.f) diag = PIDiagnostics::Failure;
else if (good_percents <= 20.f) diag = PIDiagnostics::Bad;
else if (good_percents > 20.f && good_percents <= 80.f) diag = PIDiagnostics::Average;
else diag = PIDiagnostics::Good;
if (good_percents == 0.f)
diag = PIDiagnostics::Failure;
else if (good_percents <= 20.f)
diag = PIDiagnostics::Bad;
else if (good_percents > 20.f && good_percents <= 80.f)
diag = PIDiagnostics::Average;
else
diag = PIDiagnostics::Good;
}
if ((tcnt_send + tcnt_recv) != 0) {
// piCoutObj << tcnt_recv << tcnt_send;
// piCoutObj << tcnt_recv << tcnt_send;
history_rec.dequeue();
history_send.dequeue();
Entry e;
@@ -206,7 +207,7 @@ void PIDiagnostics::tick(void * , int ) {
cur_state.quality = diag;
}
mutex_state.unlock();
//piCoutObj << "unlock";
// piCoutObj << "unlock";
}
@@ -221,7 +222,7 @@ PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> & hist, int & cnt
if (!hist[i].empty) cnt++;
}
e.empty = false;
// piCoutObj << hist.size() << cnt;
// piCoutObj << hist.size() << cnt;
return e;
}
@@ -237,14 +238,13 @@ void PIDiagnostics::changeDisconnectTimeout(float disct) {
disconn_ = piMaxf(disct, interval() / 1000.f);
if (interval() > 0) {
int hist_size = piClampi(int(disconn_ * 1000.f / float(interval())), 1, 65536);
//piCoutObj << hist_size << interval();
// piCoutObj << hist_size << interval();
history_rec.resize(hist_size);
history_send.resize(hist_size);
} else {
history_rec.resize(1);
history_send.resize(1);
}
//piCoutObj << hist_size << disconn_ << interval();
// piCoutObj << hist_size << disconn_ << interval();
mutex_state.unlock();
}