MCPcopy Create free account
hub / github.com/SmingHub/Sming / update

Method update

Sming/Arch/Esp32/Services/Profiling/TaskStat.cpp:39–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37TaskStat::~TaskStat() = default;
38
39bool TaskStat::update()
40{
41 if(!out) {
42 return false;
43 }
44#if CONFIG_FREERTOS_USE_TRACE_FACILITY && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
45
46 // Get current task states
47 auto& info = taskInfo[endIndex];
48 info.count = uxTaskGetSystemState(info.status, maxTasks, &info.runTime);
49 if(info.count == 0) {
50 out->println(_F("[TaskStat] uxTaskGetSystemState returned 0"));
51 return false;
52 }
53
54 std::qsort(info.status, info.count, sizeof(TaskStatus_t), [](const void* a, const void* b) -> int {
55 auto s1 = static_cast<const TaskStatus_t*>(a);
56 auto s2 = static_cast<const TaskStatus_t*>(b);
57 int res = 0;
58#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
59 res = s1->xCoreID - s2->xCoreID;
60#endif
61 if(res == 0) {
62 res = s2->uxCurrentPriority - s1->uxCurrentPriority;
63 }
64 if(res == 0) {
65 res = s1->xTaskNumber - s2->xTaskNumber;
66 }
67 return res;
68 });
69
70 if(startIndex == endIndex) {
71 endIndex = 1;
72 return true;
73 }
74
75 auto& startInfo = taskInfo[startIndex];
76 auto& endInfo = taskInfo[endIndex];
77
78 // Set indices for next update
79 endIndex = startIndex;
80 startIndex = 1 - endIndex;
81
82 // Calculate totalElapsedTime in units of run time stats clock period.
83 uint32_t totalElapsedTime = endInfo.runTime - startInfo.runTime;
84 if(totalElapsedTime == 0) {
85 out->println(_F("[TaskStat] Run time was 0: Have you set CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS?"));
86 return false;
87 }
88
89 std::bitset<maxTasks> startMatched, endMatched;
90
91 PSTR_ARRAY(hdrfmt, "# | Core | Prio | Handle | Run Time | % Time | Name");
92 PSTR_ARRAY(datfmt, "%-3u | %c | %4u | %08x | %8u | %3u%% | %s\r\n");
93 out->println();
94 out->println(hdrfmt);
95 // Match each task in startInfo.status to those in the endInfo.status
96 for(unsigned i = 0; i < startInfo.count; i++) {

Callers

nothing calls this directly

Calls 2

printlnMethod · 0.80
printfMethod · 0.80

Tested by

no test coverage detected