Skip to content

Commit 5ab6f12

Browse files
authored
feat(monitor): update monitor to support longer task name printing (#233)
* Update task monitor to support dynamically configuring table column width based on configured freertos max name length * Update task monitor to not show core id column if core id is not configured to be tracked as part of the task.
1 parent b66b7fa commit 5ab6f12

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

components/monitor/include/task_monitor.hpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,28 @@ class TaskMonitor : public BaseComponent {
202202
if (task_info.empty()) {
203203
return output;
204204
}
205-
output = "| Task Name | CPU % | High Water Mark | Priority | Core ID |\n"
206-
"| ---------------- | ----- | --------------- | -------- | ------- |\n";
205+
static constexpr int task_name_header_min_width = 9; // length of "Task Name"
206+
static constexpr int task_name_max_width = CONFIG_FREERTOS_MAX_TASK_NAME_LEN;
207+
static constexpr int task_name_width =
208+
std::max(task_name_header_min_width, task_name_max_width);
209+
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
210+
output = fmt::format("| {1: ^{0}.{0}s} | CPU % | High Water Mark | Priority | Core ID |\n"
211+
"| {2:->{0}} | ----- | --------------- | -------- | ------- |\n",
212+
task_name_width, "Task Name", "");
213+
for (const auto &t : task_info) {
214+
output += fmt::format("| {1: >{0}.{0}s} | {2: >3} % | {3: >13} B | {4: >8} | {5: >7} |\n",
215+
task_name_width, t.name, t.cpu_percent, t.high_water_mark, t.priority,
216+
t.core_id);
217+
}
218+
#else
219+
output = fmt::format("| {1: ^{0}.{0}s} | CPU % | High Water Mark | Priority |\n"
220+
"| {2:->{0}} | ----- | --------------- | -------- |\n",
221+
task_name_width, "Task Name", "");
207222
for (const auto &t : task_info) {
208-
output += fmt::format("| {: >16.16s} | {: >3} % | {: >13} B | {: >8} | {: >7} |\n", t.name,
209-
t.cpu_percent, t.high_water_mark, t.priority, t.core_id);
223+
output += fmt::format("| {1: >{0}.{0}s} | {2: >3} % | {3: >13} B | {4: >8} |\n",
224+
task_name_width, t.name, t.cpu_percent, t.high_water_mark, t.priority);
210225
}
226+
#endif
211227
return output;
212228
}
213229

@@ -236,7 +252,12 @@ template <> struct fmt::formatter<espp::TaskMonitor::TaskInfo> {
236252
template <typename FormatContext>
237253
auto format(const espp::TaskMonitor::TaskInfo &t, FormatContext &ctx) {
238254
return fmt::format_to(
255+
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
239256
ctx.out(), "TaskInfo(name={}, cpu_percent={}, high_water_mark={}, priority={}, core_id={})",
240257
t.name, t.cpu_percent, t.high_water_mark, t.priority, t.core_id);
258+
#else
259+
ctx.out(), "TaskInfo(name={}, cpu_percent={}, high_water_mark={}, priority={})", t.name,
260+
t.cpu_percent, t.high_water_mark, t.priority);
261+
#endif
241262
}
242263
};

0 commit comments

Comments
 (0)