Skyward boardcore
Loading...
Searching...
No Matches
StackLogger.h
Go to the documentation of this file.
1/* Copyright (c) 2019 Skyward Experimental Rocketry
2 * Author: Luca Erbetta
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <ActiveObject.h>
26#include <Singleton.h>
27#include <logger/Logger.h>
28#include <utils/KernelTime.h>
29
30#include <map>
31
32#include "StackData.h"
33
34using miosix::FastMutex;
35using miosix::Lock;
36
37namespace Boardcore
38{
39
45class StackLogger : public Singleton<StackLogger>
46{
47 friend class Singleton<StackLogger>;
48
49public:
55 void updateStack(uint8_t threadId)
56 {
57 StackData d;
59 d.threadId = threadId;
60 d.minimumStack = miosix::MemoryProfiling::getAbsoluteFreeStack();
61
62 {
63 Lock<FastMutex> l(mutex);
64 stacks[threadId] = d;
65 }
66 }
67
72 void log()
73 {
74 {
75 Lock<FastMutex> l(mutex);
76 for (auto it = stacks.begin(); it != stacks.end(); it++)
77 Logger::getInstance().log(it->second);
78 }
79 }
80
81private:
82 StackLogger() {}
83 ~StackLogger() {}
84
85 FastMutex mutex;
86 std::map<uint8_t, StackData> stacks;
87};
88
89} // namespace Boardcore
static Logger & getInstance()
Definition Singleton.h:52
void updateStack(uint8_t threadId)
Definition StackLogger.h:55
long long getOldTick()
Get the current time in milliseconds.
Definition KernelTime.h:43
This file includes all the types the logdecoder script will decode.
long long timestamp
Definition StackData.h:53
unsigned int minimumStack
Definition StackData.h:55