~aleteoryx/muditaos

muditaos/module-sys/SystemManager/CpuLogPrinter.cpp -rw-r--r-- 1.7 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "SystemManager/CpuPrinter.hpp"
#include "SystemManager/SysCpuUpdateResult.hpp"
#include <SystemManager/SystemManagerCommon.hpp>
#include <log/log.hpp>

#include <cinttypes>

extern "C"
{
    uint32_t CLOCK_GetFreq(int);
}

namespace sys::cpu::stats
{

    void LogPrinter::printSysUsage(struct task_prof_data *data, size_t size)
    {
        vTaskSuspendAll();
        {
            for (size_t i = 0; i < size; ++i) {
                if (data[i].exec_time == 0 && data[i].switches == 0) {
                    continue;
                }

                LOG_PRINTF("%s,%" PRIu32 ",%" PRIu32 ",%" PRIu32 "\n",
                           SystemManagerCommon::ServiceProcessor(i).c_str(),
                           data[i].task_TCB_id,
                           data[i].exec_time,
                           data[i].switches);
                /// NOTE: version below is much lighter and doesn't need system suspend, it requires GDB to show what
                /// were the
                // task names LOG_PRINTF("%d,%" PRIu32 "\n", data[i].task_TCB_id, data[i].exec_time);
            }
        }
        xTaskResumeAll();
    }

    void LogPrinter::printCPUChange(const cpu::UpdateResult &ret)
    {
        LOG_PRINTF("CPU freq changed to: %d by: %s reason: %s for freq: %d curent: %" PRIu32 "\n",
                   int(ret.frequencySet),
                   ret.data.name.c_str(),
                   ret.data.reason.c_str(),
                   int(ret.data.minFrequency),
                   CLOCK_GetFreq(0));
    }

    void LogPrinter::printPowerConsumption()
    {}
} // namespace sys::cpu::stats