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

This commit is contained in:
2016-04-13 16:35:34 +00:00
parent b93205f175
commit 0a8a753df7
3 changed files with 62 additions and 41 deletions

View File

@@ -14,8 +14,9 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
timeout_ = 10.; timeout_ = 10.;
diag.setDisconnectTimeout(timeout_); diag.setDisconnectTimeout(timeout_);
//CONNECTU(&diag, qualityChanged, this, diagChanged); //CONNECTU(&diag, qualityChanged, this, diagChanged);
diag.setName("PIBaseTransfer");
diag.start(50); diag.start(50);
packets_count = 100; packets_count = 32;
setPacketSize(4096); setPacketSize(4096);
randomize(); randomize();
} }
@@ -268,7 +269,7 @@ bool PIBaseTransfer::send_process() {
} }
stm.reset(); stm.reset();
ba = build_packet(i); ba = build_packet(i);
diag.sended(ba.size()); diag.sended(ba.size_s());
sendRequest(ba); sendRequest(ba);
mutex_send.lock(); mutex_send.lock();
send_queue++; send_queue++;
@@ -313,7 +314,7 @@ bool PIBaseTransfer::send_process() {
continue; continue;
} }
ba = build_packet(chk - 1); ba = build_packet(chk - 1);
diag.sended(ba.size()); diag.sended(ba.size_s());
sendRequest(ba); sendRequest(ba);
mutex_send.lock(); mutex_send.lock();
send_queue++; send_queue++;
@@ -419,7 +420,7 @@ void PIBaseTransfer::sendReply(PacketType reply) {
header.type = reply; header.type = reply;
PIByteArray ba; PIByteArray ba;
ba << header; ba << header;
if (is_sending || is_receiving) diag.sended(ba.size()); if (is_sending || is_receiving) diag.sended(ba.size_s());
sendRequest(ba); sendRequest(ba);
} }
@@ -438,7 +439,7 @@ bool PIBaseTransfer::getStartRequest() {
ba << st; ba << st;
state_string = "send request"; state_string = "send request";
while (tm.elapsed_s() < timeout_) { while (tm.elapsed_s() < timeout_) {
diag.sended(ba.size()); diag.sended(ba.size_s());
sendRequest(ba); sendRequest(ba);
if (break_) return false; if (break_) return false;
// piCoutObj << replies[0]; // piCoutObj << replies[0];

View File

@@ -38,7 +38,10 @@
PIDiagnostics::PIDiagnostics(bool start_): PITimer(PITimer::Pool) { PIDiagnostics::PIDiagnostics(bool start_): PITimer(PITimer::Pool) {
disconn_ = 0.;
reset(); reset();
setDisconnectTimeout(3.);
changeDisconnectTimeout(3.);
if (start_) start(100); if (start_) start(100);
} }
@@ -50,18 +53,20 @@ void PIDiagnostics::reset() {
immediate_freq = integral_freq = 0.f; immediate_freq = integral_freq = 0.f;
count_wrong = count_recv = count_send = bytes_wrong = bytes_recv = bytes_send = 0; 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; packets_recv_sec = packets_send_sec = bytes_recv_sec = bytes_send_sec = 0;
history_rec.clear(); if (disconn_ != 0.) {
history_send.clear(); int hist_size = history_rec.size();
history_rec << Entry(); history_rec.clear();
history_send << Entry(); history_send.clear();
history_rec.resize(hist_size);
history_send.resize(hist_size);
}
unlock(); unlock();
setDisconnectTimeout(3.);
} }
void PIDiagnostics::received(int size, bool correct) { void PIDiagnostics::received(int size, bool correct) {
lock(); lock();
Entry &e(history_send.back()); Entry & e(history_send.front());
if (correct) { if (correct) {
e.cnt_ok++; e.cnt_ok++;
e.bytes_ok += size; e.bytes_ok += size;
@@ -80,7 +85,7 @@ void PIDiagnostics::received(int size, bool correct) {
void PIDiagnostics::sended(int size) { void PIDiagnostics::sended(int size) {
lock(); lock();
Entry &e(history_send.back()); Entry & e(history_send.front());
e.cnt_ok++; e.cnt_ok++;
e.bytes_ok += size; e.bytes_ok += size;
count_send++; count_send++;
@@ -92,55 +97,66 @@ void PIDiagnostics::sended(int size) {
void PIDiagnostics::tick(void * data, int delimiter) { void PIDiagnostics::tick(void * data, int delimiter) {
lock(); lock();
int tcnt = 0; int tcnt_recv = 0;
Entry send = calcHistory(history_send, &tcnt); int tcnt_send = 0;
Entry recv = calcHistory(history_rec, &tcnt); Entry send = calcHistory(history_send, tcnt_send);
float it = disconn_ * (float(tcnt) / history_rec.size()); 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; float hz = interval() / 1000.f;
integral_freq = recv.cnt_ok / it; integral_freq = recv.cnt_ok / itr;
packets_recv_sec = ullong(float(recv.cnt_ok) / it); packets_recv_sec = ullong(float(recv.cnt_ok) / itr);
packets_send_sec = ullong(float(send.cnt_ok) / it); packets_send_sec = ullong(float(send.cnt_ok) / its);
bytes_recv_sec = ullong(double(recv.bytes_ok) / it); bytes_recv_sec = ullong(double(recv.bytes_ok) / itr);
bytes_send_sec = ullong(double(send.bytes_ok) / it); bytes_send_sec = ullong(double(send.bytes_ok) / its);
immediate_freq = double(history_rec.back().cnt_ok) / hz; immediate_freq = double(history_rec.back().cnt_ok) / hz;
speedRecv = PIString::readableSize(ullong(double(history_rec.back().bytes_ok) / hz)) + "/s"; // piCoutObj << disconn_ << interval() << history_send.size() << tcnt_send << count_send << send.cnt_ok;
speedSend = PIString::readableSize(ullong(double(history_send.back().bytes_ok) / hz)) + "/s"; // speedRecv = PIString::readableSize(ullong(double(history_rec.back().bytes_ok) / hz)) + "/s";
// speedSend = PIString::readableSize(ullong(double(history_send.back().bytes_ok) / hz)) + "/s";
speedRecv = PIString::readableSize(bytes_recv_sec) + "/s";
speedSend = PIString::readableSize(bytes_send_sec) + "/s";
int arc = recv.cnt_ok + recv.cnt_fail; int arc = recv.cnt_ok + recv.cnt_fail;
float good_percents = 0.f; float good_percents = 0.f;
if (arc > 0) good_percents = (float)recv.cnt_ok / arc * 100.f; if (arc > 0) good_percents = (float)recv.cnt_ok / arc * 100.f;
PIDiagnostics::Quality diag; PIDiagnostics::Quality diag;
if (tcnt == 0) { if (tcnt_recv == 0) {
diag = PIDiagnostics::Unknown; diag = PIDiagnostics::Unknown;
} else { } else {
if (good_percents == 0.f) diag = PIDiagnostics::Failure; if (good_percents == 0.f) diag = PIDiagnostics::Failure;
else if (good_percents <= 20.f) diag = PIDiagnostics::Bad; else if (good_percents <= 20.f) diag = PIDiagnostics::Bad;
else if (good_percents > 20.f && good_percents <= 80.f) diag = PIDiagnostics::Average; else if (good_percents > 20.f && good_percents <= 80.f) diag = PIDiagnostics::Average;
else diag = PIDiagnostics::Good; else diag = PIDiagnostics::Good;
}
if ((tcnt_send + tcnt_recv) != 0) {
// piCoutObj << tcnt_recv << tcnt_send;
history_rec.dequeue();
history_send.dequeue();
Entry e;
e.empty = false;
history_rec.enqueue(e);
history_send.enqueue(e);
} }
if (diag != qual) { if (diag != qual) {
qualityChanged(diag, qual); qualityChanged(diag, qual);
qual = diag; qual = diag;
} }
history_rec.dequeue();
history_send.dequeue();
Entry e;
if (diag != PIDiagnostics::Unknown) e.empty = false;
history_rec.enqueue(e);
history_send.enqueue(e);
unlock(); unlock();
} }
PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> &hist, int * cnt) { PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> & hist, int & cnt) {
Entry e; Entry e;
*cnt = 0; cnt = 0;
for (int i = 0; i < hist.size_s(); ++i) { for (int i = 0; i < hist.size_s(); ++i) {
e.bytes_ok += hist[i].bytes_ok; e.bytes_ok += hist[i].bytes_ok;
e.bytes_fail += hist[i].bytes_fail; e.bytes_fail += hist[i].bytes_fail;
e.cnt_ok += hist[i].cnt_ok; e.cnt_ok += hist[i].cnt_ok;
e.cnt_fail += hist[i].cnt_fail; e.cnt_fail += hist[i].cnt_fail;
if (!e.empty) *cnt++; if (!hist[i].empty) cnt++;
} }
e.empty = false;
//piCoutObj << hist.size() << cnt;
return e; return e;
} }
@@ -153,9 +169,14 @@ void PIDiagnostics::propertyChanged(const PIString &) {
void PIDiagnostics::changeDisconnectTimeout(float disct) { void PIDiagnostics::changeDisconnectTimeout(float disct) {
lock(); lock();
disconn_ = piMaxf(disct, interval()); // if (disct != disconn_) {
int hist_size = piMaxi(int(disconn_ * 1000 / interval()), 1); disconn_ = piMaxf(disct, interval() / 1000.f);
history_rec.resize(hist_size); int hist_size = piMaxi(int(disconn_ * 1000. / interval()), 1);
history_send.resize(hist_size); //piCoutObj << hist_size << interval();
history_rec.resize(hist_size);
history_send.resize(hist_size);
// }
// piCoutObj << hist_size << disconn_ << interval();
unlock(); unlock();
} }

View File

@@ -51,8 +51,7 @@ public:
float disconnectTimeout() const {return disconn_;} float disconnectTimeout() const {return disconn_;}
//! Returns period of full disconnect in seconds and period of averaging frequency //! Returns period of full disconnect in seconds and period of averaging frequency
void setDisconnectTimeout(float s) {setProperty("disconnectTimeout", s); changeDisconnectTimeout(s);} void setDisconnectTimeout(float s) {setProperty("disconnectTimeout", s);}
//! Returns immediate receive frequency, packets/s //! Returns immediate receive frequency, packets/s
float immediateFrequency() const {return immediate_freq;} float immediateFrequency() const {return immediate_freq;}
@@ -191,8 +190,8 @@ private:
}; };
void tick(void * data, int delimiter); void tick(void * data, int delimiter);
Entry calcHistory(PIQueue<Entry> & hist, int * cnt); Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
void propertyChanged(const PIString & ); void propertyChanged(const PIString &);
void changeDisconnectTimeout(float disct); void changeDisconnectTimeout(float disct);
PIDiagnostics::Quality qual; PIDiagnostics::Quality qual;