git-svn-id: svn://db.shs.com.ru/pip@188 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -14,8 +14,9 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
timeout_ = 10.;
|
||||
diag.setDisconnectTimeout(timeout_);
|
||||
//CONNECTU(&diag, qualityChanged, this, diagChanged);
|
||||
diag.setName("PIBaseTransfer");
|
||||
diag.start(50);
|
||||
packets_count = 100;
|
||||
packets_count = 32;
|
||||
setPacketSize(4096);
|
||||
randomize();
|
||||
}
|
||||
@@ -268,7 +269,7 @@ bool PIBaseTransfer::send_process() {
|
||||
}
|
||||
stm.reset();
|
||||
ba = build_packet(i);
|
||||
diag.sended(ba.size());
|
||||
diag.sended(ba.size_s());
|
||||
sendRequest(ba);
|
||||
mutex_send.lock();
|
||||
send_queue++;
|
||||
@@ -313,7 +314,7 @@ bool PIBaseTransfer::send_process() {
|
||||
continue;
|
||||
}
|
||||
ba = build_packet(chk - 1);
|
||||
diag.sended(ba.size());
|
||||
diag.sended(ba.size_s());
|
||||
sendRequest(ba);
|
||||
mutex_send.lock();
|
||||
send_queue++;
|
||||
@@ -419,7 +420,7 @@ void PIBaseTransfer::sendReply(PacketType reply) {
|
||||
header.type = reply;
|
||||
PIByteArray ba;
|
||||
ba << header;
|
||||
if (is_sending || is_receiving) diag.sended(ba.size());
|
||||
if (is_sending || is_receiving) diag.sended(ba.size_s());
|
||||
sendRequest(ba);
|
||||
}
|
||||
|
||||
@@ -438,7 +439,7 @@ bool PIBaseTransfer::getStartRequest() {
|
||||
ba << st;
|
||||
state_string = "send request";
|
||||
while (tm.elapsed_s() < timeout_) {
|
||||
diag.sended(ba.size());
|
||||
diag.sended(ba.size_s());
|
||||
sendRequest(ba);
|
||||
if (break_) return false;
|
||||
// piCoutObj << replies[0];
|
||||
|
||||
@@ -38,7 +38,10 @@
|
||||
|
||||
|
||||
PIDiagnostics::PIDiagnostics(bool start_): PITimer(PITimer::Pool) {
|
||||
disconn_ = 0.;
|
||||
reset();
|
||||
setDisconnectTimeout(3.);
|
||||
changeDisconnectTimeout(3.);
|
||||
if (start_) start(100);
|
||||
}
|
||||
|
||||
@@ -50,18 +53,20 @@ void PIDiagnostics::reset() {
|
||||
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;
|
||||
history_rec.clear();
|
||||
history_send.clear();
|
||||
history_rec << Entry();
|
||||
history_send << Entry();
|
||||
if (disconn_ != 0.) {
|
||||
int hist_size = history_rec.size();
|
||||
history_rec.clear();
|
||||
history_send.clear();
|
||||
history_rec.resize(hist_size);
|
||||
history_send.resize(hist_size);
|
||||
}
|
||||
unlock();
|
||||
setDisconnectTimeout(3.);
|
||||
}
|
||||
|
||||
|
||||
void PIDiagnostics::received(int size, bool correct) {
|
||||
lock();
|
||||
Entry &e(history_send.back());
|
||||
Entry & e(history_send.front());
|
||||
if (correct) {
|
||||
e.cnt_ok++;
|
||||
e.bytes_ok += size;
|
||||
@@ -80,7 +85,7 @@ void PIDiagnostics::received(int size, bool correct) {
|
||||
|
||||
void PIDiagnostics::sended(int size) {
|
||||
lock();
|
||||
Entry &e(history_send.back());
|
||||
Entry & e(history_send.front());
|
||||
e.cnt_ok++;
|
||||
e.bytes_ok += size;
|
||||
count_send++;
|
||||
@@ -92,55 +97,66 @@ void PIDiagnostics::sended(int size) {
|
||||
|
||||
void PIDiagnostics::tick(void * data, int delimiter) {
|
||||
lock();
|
||||
int tcnt = 0;
|
||||
Entry send = calcHistory(history_send, &tcnt);
|
||||
Entry recv = calcHistory(history_rec, &tcnt);
|
||||
float it = disconn_ * (float(tcnt) / history_rec.size());
|
||||
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;
|
||||
integral_freq = recv.cnt_ok / it;
|
||||
packets_recv_sec = ullong(float(recv.cnt_ok) / it);
|
||||
packets_send_sec = ullong(float(send.cnt_ok) / it);
|
||||
bytes_recv_sec = ullong(double(recv.bytes_ok) / it);
|
||||
bytes_send_sec = ullong(double(send.bytes_ok) / it);
|
||||
integral_freq = recv.cnt_ok / itr;
|
||||
packets_recv_sec = ullong(float(recv.cnt_ok) / itr);
|
||||
packets_send_sec = ullong(float(send.cnt_ok) / its);
|
||||
bytes_recv_sec = ullong(double(recv.bytes_ok) / itr);
|
||||
bytes_send_sec = ullong(double(send.bytes_ok) / its);
|
||||
immediate_freq = double(history_rec.back().cnt_ok) / hz;
|
||||
speedRecv = PIString::readableSize(ullong(double(history_rec.back().bytes_ok) / hz)) + "/s";
|
||||
speedSend = PIString::readableSize(ullong(double(history_send.back().bytes_ok) / hz)) + "/s";
|
||||
// piCoutObj << disconn_ << interval() << history_send.size() << tcnt_send << count_send << send.cnt_ok;
|
||||
// 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;
|
||||
float good_percents = 0.f;
|
||||
if (arc > 0) good_percents = (float)recv.cnt_ok / arc * 100.f;
|
||||
PIDiagnostics::Quality diag;
|
||||
if (tcnt == 0) {
|
||||
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 ((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) {
|
||||
qualityChanged(diag, qual);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> &hist, int * cnt) {
|
||||
PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> & hist, int & cnt) {
|
||||
Entry e;
|
||||
*cnt = 0;
|
||||
cnt = 0;
|
||||
for (int i = 0; i < hist.size_s(); ++i) {
|
||||
e.bytes_ok += hist[i].bytes_ok;
|
||||
e.bytes_fail += hist[i].bytes_fail;
|
||||
e.cnt_ok += hist[i].cnt_ok;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -153,9 +169,14 @@ void PIDiagnostics::propertyChanged(const PIString &) {
|
||||
|
||||
void PIDiagnostics::changeDisconnectTimeout(float disct) {
|
||||
lock();
|
||||
disconn_ = piMaxf(disct, interval());
|
||||
int hist_size = piMaxi(int(disconn_ * 1000 / interval()), 1);
|
||||
history_rec.resize(hist_size);
|
||||
history_send.resize(hist_size);
|
||||
// if (disct != disconn_) {
|
||||
disconn_ = piMaxf(disct, interval() / 1000.f);
|
||||
int hist_size = piMaxi(int(disconn_ * 1000. / interval()), 1);
|
||||
//piCoutObj << hist_size << interval();
|
||||
history_rec.resize(hist_size);
|
||||
history_send.resize(hist_size);
|
||||
// }
|
||||
// piCoutObj << hist_size << disconn_ << interval();
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,7 @@ public:
|
||||
float disconnectTimeout() const {return disconn_;}
|
||||
|
||||
//! 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
|
||||
float immediateFrequency() const {return immediate_freq;}
|
||||
@@ -191,8 +190,8 @@ private:
|
||||
};
|
||||
|
||||
void tick(void * data, int delimiter);
|
||||
Entry calcHistory(PIQueue<Entry> & hist, int * cnt);
|
||||
void propertyChanged(const PIString & );
|
||||
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
||||
void propertyChanged(const PIString &);
|
||||
void changeDisconnectTimeout(float disct);
|
||||
|
||||
PIDiagnostics::Quality qual;
|
||||
|
||||
Reference in New Issue
Block a user