Skip to content

Commit

Permalink
Merge pull request #28 from bitcraze/improved_stats
Browse files Browse the repository at this point in the history
Bug fixes and features regarding packet statistics
  • Loading branch information
krichardsson authored Mar 13, 2023
2 parents 1d908d1 + 0e45798 commit fc92573
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions include/crazyflieLinkCpp/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ class Connection
}

Statistics(const Statistics& other)
{
*this = other;
}

Statistics& operator=(const Statistics& other)
{
std::atomic_store(&sent_count, std::atomic_load(&other.sent_count));
std::atomic_store(&sent_ping_count, std::atomic_load(&other.sent_ping_count));
std::atomic_store(&receive_count, std::atomic_load(&other.receive_count));
std::atomic_store(&enqueued_count, std::atomic_load(&other.enqueued_count));
std::atomic_store(&ack_count, std::atomic_load(&other.ack_count));
std::atomic_store(&ack_count, std::atomic_load(&other.ack_count));
return *this;
}

void reset()
{
sent_count = 0;
sent_ping_count = 0;
receive_count = 0;
enqueued_count = 0;
ack_count = 0;
Expand All @@ -49,6 +57,7 @@ class Connection
{
out << "Statistics(";
out << "sent_count=" << s.sent_count;
out << "sent_ping_count=" << s.sent_ping_count;
out << ",receive_count=" << s.receive_count;
out << ",enqueued_count=" << s.enqueued_count;
out << ",ack_count=" << s.ack_count;
Expand All @@ -59,6 +68,7 @@ class Connection
}

std::atomic_size_t sent_count;
std::atomic_size_t sent_ping_count;
std::atomic_size_t receive_count;
std::atomic_size_t enqueued_count;
std::atomic_size_t ack_count;
Expand Down Expand Up @@ -96,7 +106,7 @@ class Connection

const std::string& uri() const;

Connection::Statistics statistics();
const Connection::Statistics statistics() const;

friend std::ostream& operator<<(std::ostream& out, const Connection& p);

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const std::string& Connection::uri() const
return impl_->uri_;
}

Connection::Statistics Connection::statistics()
const Connection::Statistics Connection::statistics() const
{
if (!impl_->runtime_error_.empty()) {
throw std::runtime_error(impl_->runtime_error_);
Expand Down
6 changes: 5 additions & 1 deletion src/CrazyradioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void CrazyradioThread::run()

if (con->retry_) {
p = con->retry_;
--con->statistics_.enqueued_count;
} else {
const std::lock_guard<std::mutex> lock(con->queue_send_mutex_);
if (!con->queue_send_.empty())
Expand All @@ -209,6 +210,9 @@ void CrazyradioThread::run()
} else if (!con->useAutoPing_)
{
continue;
} else {
// We are now proceeding with sending the ping
++con->statistics_.sent_ping_count;
}
}

Expand All @@ -221,7 +225,6 @@ void CrazyradioThread::run()
con->safelinkUp_ = !con->safelinkUp_;
if (con->retry_) {
con->retry_ = Packet();
--con->statistics_.enqueued_count;
}
} else {
con->retry_ = p;
Expand Down Expand Up @@ -264,6 +267,7 @@ void CrazyradioThread::run()
{
ack = radio.sendPacket(ping, sizeof(ping));
++con->statistics_.sent_count;
++con->statistics_.sent_ping_count;
}
}

Expand Down

0 comments on commit fc92573

Please sign in to comment.