Skip to content

Commit 187d99c

Browse files
NeroBurnerJF002
authored andcommitted
SystemMonitor: implement FreeRtosMonitor only if trace facility is set
Split SystemMonitor into h and cpp file and move the logging code of the `Process` function into the cpp file. Depending of the `configUSE_TRACE_FACILITY` define from `src/FreeRTOSConfig.h` create either a "FreeRtosMonitor" or a "DummyMonitor". Make the `Process()` function non-const, as the FreeRtosMonitor changes the member variable `lastTick`. In `SystemTask.h` we then only need to use `SystemMonitor`, without knowledge of the `configUSE_TRACE_FACILITY` define.
1 parent 5fe5cee commit 187d99c

4 files changed

Lines changed: 35 additions & 39 deletions

File tree

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ list(APPEND SOURCE_FILES
516516
displayapp/lv_pinetime_theme.c
517517

518518
systemtask/SystemTask.cpp
519+
systemtask/SystemMonitor.cpp
519520
drivers/TwiMaster.cpp
520521

521522
heartratetask/HeartRateTask.cpp
@@ -577,6 +578,7 @@ list(APPEND RECOVERY_SOURCE_FILES
577578
FreeRTOS/port_cmsis.c
578579

579580
systemtask/SystemTask.cpp
581+
systemtask/SystemMonitor.cpp
580582
drivers/TwiMaster.cpp
581583
components/gfx/Gfx.cpp
582584
components/rle/RleDecoder.cpp

src/systemtask/SystemMonitor.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "systemtask/SystemTask.h"
2+
#if configUSE_TRACE_FACILITY == 1
3+
// FreeRtosMonitor
4+
#include <FreeRTOS.h>
5+
#include <task.h>
6+
#include <nrf_log.h>
7+
8+
void Pinetime::System::SystemMonitor::Process() {
9+
if (xTaskGetTickCount() - lastTick > 10000) {
10+
NRF_LOG_INFO("---------------------------------------\nFree heap : %d", xPortGetFreeHeapSize());
11+
TaskStatus_t tasksStatus[10];
12+
auto nb = uxTaskGetSystemState(tasksStatus, 10, nullptr);
13+
for (uint32_t i = 0; i < nb; i++) {
14+
NRF_LOG_INFO("Task [%s] - %d", tasksStatus[i].pcTaskName, tasksStatus[i].usStackHighWaterMark);
15+
if (tasksStatus[i].usStackHighWaterMark < 20)
16+
NRF_LOG_INFO("WARNING!!! Task %s task is nearly full, only %dB available",
17+
tasksStatus[i].pcTaskName,
18+
tasksStatus[i].usStackHighWaterMark * 4);
19+
}
20+
lastTick = xTaskGetTickCount();
21+
}
22+
}
23+
#else
24+
// DummyMonitor
25+
void Pinetime::System::SystemMonitor::Process() {}
26+
#endif

src/systemtask/SystemMonitor.h

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
#pragma once
2-
#include <FreeRTOS.h>
2+
#include <FreeRTOS.h> // declares configUSE_TRACE_FACILITY
33
#include <task.h>
4-
#include <nrf_log.h>
54

65
namespace Pinetime {
76
namespace System {
8-
struct DummyMonitor {};
9-
struct FreeRtosMonitor {};
10-
11-
template <class T> class SystemMonitor {
12-
public:
13-
SystemMonitor() = delete;
14-
};
15-
16-
template <> class SystemMonitor<DummyMonitor> {
7+
class SystemMonitor {
178
public:
18-
void Process() const {
19-
}
20-
};
21-
22-
template <> class SystemMonitor<FreeRtosMonitor> {
23-
public:
24-
void Process() const {
25-
if (xTaskGetTickCount() - lastTick > 10000) {
26-
NRF_LOG_INFO("---------------------------------------\nFree heap : %d", xPortGetFreeHeapSize());
27-
auto nb = uxTaskGetSystemState(tasksStatus, 10, nullptr);
28-
for (uint32_t i = 0; i < nb; i++) {
29-
NRF_LOG_INFO("Task [%s] - %d", tasksStatus[i].pcTaskName, tasksStatus[i].usStackHighWaterMark);
30-
if (tasksStatus[i].usStackHighWaterMark < 20)
31-
NRF_LOG_INFO("WARNING!!! Task %s task is nearly full, only %dB available",
32-
tasksStatus[i].pcTaskName,
33-
tasksStatus[i].usStackHighWaterMark * 4);
34-
}
35-
lastTick = xTaskGetTickCount();
36-
}
37-
}
38-
9+
void Process();
10+
#if configUSE_TRACE_FACILITY == 1
3911
private:
4012
mutable TickType_t lastTick = 0;
41-
mutable TaskStatus_t tasksStatus[10];
13+
#endif
4214
};
4315
}
44-
}
16+
}

src/systemtask/SystemTask.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ namespace Pinetime {
148148
bool stepCounterMustBeReset = false;
149149
static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000);
150150

151-
#if configUSE_TRACE_FACILITY == 1
152-
SystemMonitor<FreeRtosMonitor> monitor;
153-
#else
154-
SystemMonitor<DummyMonitor> monitor;
155-
#endif
151+
SystemMonitor monitor;
156152
};
157153
}
158154
}

0 commit comments

Comments
 (0)