~aleteoryx/muditaos

ref: 202dd9306402a91c309aaf30806559330ee06fba muditaos/board/rt1051/crashdump/crashdumpwriter_vfs.hpp -rw-r--r-- 1.1 KiB
202dd930 — Artur Śleszyński [CP-261] Print crash occurences to log 4 years 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "crashdumpwriter.hpp"

#include <array>
#include <ctime>
#include <memory>

namespace purefs::fs
{
    class filesystem;
}

namespace crashdump
{
    constexpr inline auto CrashDumpFileNameFormat = "/sys/user/crashdump-%FT%TZ.hex";

    class CrashDumpWriterVFS : public CrashDumpWriter
    {
      public:
        void openDump() override;
        void saveDump() override;

        void writeBytes(const std::uint8_t *buff, std::size_t size) override;
        void writeHalfWords(const std::uint16_t *buff, std::size_t size) override;
        void writeWords(const std::uint32_t *buff, std::size_t size) override;

      private:
        template <std::size_t N> void formatCrashDumpFileName(std::array<char, N> &name)
        {
            std::time_t now;
            std::time(&now);
            std::strftime(name.data(), name.size(), CrashDumpFileNameFormat, std::localtime(&now));
        }

        int dumpFd{-1};

        std::shared_ptr<purefs::fs::filesystem> vfs;
    };

} // namespace crashdump