px4_work_queue: reset statistics after each status print

This commit is contained in:
Daniel Agar
2020-09-01 16:53:37 -04:00
parent 86e10afd76
commit 668c16da83
4 changed files with 12 additions and 7 deletions
@@ -69,7 +69,7 @@ protected:
ScheduledWorkItem(const char *name, const wq_config_t &config) : WorkItem(name, config) {} ScheduledWorkItem(const char *name, const wq_config_t &config) : WorkItem(name, config) {}
virtual ~ScheduledWorkItem() override; virtual ~ScheduledWorkItem() override;
virtual void print_run_status() const override; virtual void print_run_status() override;
private: private:
@@ -70,7 +70,7 @@ public:
} }
} }
virtual void print_run_status() const; virtual void print_run_status();
/** /**
* Switch to a different WorkQueue. * Switch to a different WorkQueue.
@@ -99,10 +99,12 @@ protected:
void RunPreamble() void RunPreamble()
{ {
_run_count++; if (_run_count == 0) {
if (_time_first_run == 0) {
_time_first_run = hrt_absolute_time(); _time_first_run = hrt_absolute_time();
_run_count = 1;
} else {
_run_count++;
} }
} }
@@ -64,7 +64,7 @@ void ScheduledWorkItem::ScheduleClear()
WorkItem::ScheduleClear(); WorkItem::ScheduleClear();
} }
void ScheduledWorkItem::print_run_status() const void ScheduledWorkItem::print_run_status()
{ {
if (_call.period > 0) { if (_call.period > 0) {
PX4_INFO_RAW("%-26s %8.1f Hz %12.0f us (%" PRId64 " us)\n", _item_name, (double)average_rate(), PX4_INFO_RAW("%-26s %8.1f Hz %12.0f us (%" PRId64 " us)\n", _item_name, (double)average_rate(),
+4 -1
View File
@@ -132,9 +132,12 @@ float WorkItem::average_interval() const
return 0.f; return 0.f;
} }
void WorkItem::print_run_status() const void WorkItem::print_run_status()
{ {
PX4_INFO_RAW("%-26s %8.1f Hz %12.0f us\n", _item_name, (double)average_rate(), (double)average_interval()); PX4_INFO_RAW("%-26s %8.1f Hz %12.0f us\n", _item_name, (double)average_rate(), (double)average_interval());
// reset statistics
_run_count = 0;
} }
} // namespace px4 } // namespace px4