QElectroTech
0.200.1-dev
Loading...
Searching...
No Matches
logring.h
Go to the documentation of this file.
1
/*
2
Copyright 2006-2026 The QElectroTech Team
3
This file is part of QElectroTech.
4
5
QElectroTech is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 2 of the License, or
8
(at your option) any later version.
9
10
QElectroTech is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
#ifndef LOGRING_H
19
#define LOGRING_H
20
21
#include <QByteArray>
22
#include <QVector>
23
#include <atomic>
24
#include <vector>
25
50
class
LogRing
51
{
52
public
:
53
static
constexpr
int
kCapacityEntries
= 4096;
54
static
constexpr
int
kEntryBytes
= 512;
// 4096 * 512 = 2 MiB total
55
56
LogRing
();
57
62
void
append
(
const
QByteArray &line)
noexcept
;
63
66
QVector<QByteArray>
snapshot
()
const
;
67
71
void
dumpToFd
(
int
fd)
const
noexcept
;
72
73
void
clear
();
74
75
private
:
76
struct
Entry
{
77
char
data
[
kEntryBytes
];
78
std::atomic<int>
length
{0};
// 0 = not yet written this lap
79
};
80
81
std::vector<Entry>
m_entries
;
// preallocated once, capacity fixed
82
std::atomic<quint64>
m_write_cursor
{0};
// monotonically increasing
83
};
84
85
#endif
// LOGRING_H
LogRing::m_entries
std::vector< Entry > m_entries
Definition
logring.h:81
LogRing::snapshot
QVector< QByteArray > snapshot() const
Definition
logring.cpp:109
LogRing::dumpToFd
void dumpToFd(int fd) const noexcept
Definition
logring.cpp:130
LogRing::LogRing
LogRing()
Definition
logring.cpp:73
LogRing::m_write_cursor
std::atomic< quint64 > m_write_cursor
Definition
logring.h:82
LogRing::kCapacityEntries
static constexpr int kCapacityEntries
Definition
logring.h:53
LogRing::append
void append(const QByteArray &line) noexcept
Definition
logring.cpp:82
LogRing::clear
void clear()
Definition
logring.cpp:146
LogRing::kEntryBytes
static constexpr int kEntryBytes
Definition
logring.h:54
LogRing::Entry
Definition
logring.h:76
LogRing::Entry::data
char data[kEntryBytes]
Definition
logring.h:77
LogRing::Entry::length
std::atomic< int > length
Definition
logring.h:78
sources
logging
logring.h
Generated by
1.15.0