15#include <qplatformdefs.h>
18#if QT_CONFIG(cxx17_filesystem)
32#include "metadata_template.h"
43 static_assert(std::is_arithmetic_v<T>);
44 arr.append(
reinterpret_cast<char *
>(&
val),
sizeof(
val));
74 m_sessionChanged =
true;
81 m_serverClosed =
true;
88void QCtfLibImpl::buildMetadata()
102 writeMetadata(metadata,
true);
109 qCInfo(lcDebugTrace) <<
"QTRACE_LOCATION not set";
124#if !QT_CONFIG(cxx17_filesystem)
125 qCWarning(lcDebugTrace) <<
"Unable to use filesystem";
130 qCWarning(lcDebugTrace) <<
"Unable to write to location";
136 qCWarning(lcDebugTrace) <<
"unable to open session file: "
143 if (QT_FSTAT(QT_FILENO(
file), &stat) != 0) {
147 qsizetype filesize =
qMin(stat.st_size, std::numeric_limits<qsizetype>::max());
151 if (
size != filesize)
156 if (!
obj.isEmpty()) {
158 if (
it.value().isArray()) {
159 m_session.name =
it.key();
160 for (
auto var :
it.value().toArray())
166 qCWarning(lcDebugTrace) <<
"Session file is not valid";
171#if QT_CONFIG(cxx17_filesystem)
178 m_session.all = m_session.tracepoints.contains(
allLiteral());
186void QCtfLibImpl::clearLocation()
188#if QT_CONFIG(cxx17_filesystem)
190 for (
auto const& dirEntry :
std::filesystem::directory_iterator{
location})
192 const auto path = dirEntry.path();
193#if __cplusplus > 201703L
194 if (dirEntry.is_regular_file()
195 &&
path.filename().wstring().starts_with(std::wstring_view(L
"channel_"))
196 && !
path.has_extension()) {
198 const auto strview = std::wstring_view(L
"channel_");
199 const auto sub =
path.filename().wstring().substr(0, strview.length());
200 if (dirEntry.is_regular_file() &&
sub.compare(strview) == 0
201 && !
path.has_extension()) {
203 if (!std::filesystem::remove(
path)) {
204 qCInfo(lcDebugTrace) <<
"Unable to clear output location.";
212void QCtfLibImpl::writeMetadata(
const QString &metadata,
bool overwrite)
215 auto mt = metadata.
toUtf8();
219 FILE *
file =
nullptr;
234void QCtfLibImpl::writeCtfPacket(QCtfLibImpl::Channel &
ch)
236 FILE *
file =
nullptr;
239 if (
file || m_streaming) {
242 packet << s_CtfHeaderMagic;
246 packet <<
ch.minTimestamp;
247 packet <<
ch.maxTimestamp;
250 packet <<
ch.seqnumber++;
252 packet <<
ch.threadIndex;
253 if (
ch.threadName.size())
266 fwrite(
ch.data.data(),
ch.data.size(), 1,
file);
272QCtfLibImpl::Channel::~Channel()
274 impl->writeCtfPacket(*
this);
275 impl->removeChannel(
this);
285void QCtfLibImpl::removeChannel(
Channel *
ch)
293 if (m_sessionChanged) {
298 m_session.all = m_session.tracepoints.contains(
allLiteral());
299 m_sessionChanged =
false;
300 for (
const auto &meta : m_additionalMetadata)
301 writeMetadata(meta->metadata);
302 for (
auto *
priv : m_eventPrivs)
303 writeMetadata(
priv->metadata);
305 for (
auto *
ch : m_channels) {
308 ch->minTimestamp =
ch->maxTimestamp = timestamp;
313 return m_session.all || m_session.tracepoints.contains(point.
provider.
provider);
332 + u
" stream_id = 0;\n loglevel = 13;\n fields := struct {\n "
333 + metadata + u
"\n };\n};\n";
358 if (m_streaming && m_serverClosed)
362 if (!
priv->metadataWritten) {
363 priv->metadataWritten =
true;
365 while (providerMetadata) {
367 providerMetadata = providerMetadata->next;
369 if (m_newAdditionalMetadata.
size()) {
370 for (
const QString &
name : m_newAdditionalMetadata)
371 writeMetadata(m_additionalMetadata[
name]->metadata);
372 m_newAdditionalMetadata.
clear();
374 writeMetadata(
priv->metadata);
378 if (arr.size() != point.
size) {
379 if (arr.size() < point.
size)
391 if (
ch.channelName[0] == 0) {
395 sprintf(
ch.channelName,
"%s/channel_%d",
qPrintable(m_location), m_threadIndices[
thread]);
396 ch.minTimestamp =
ch.maxTimestamp = timestamp;
398 ch.threadIndex = m_threadIndices[
thread];
400 if (
ch.threadName.isEmpty()) {
404 ch.threadNameLength =
ch.threadName.size() + 1;
412 event <<
priv->id << timestamp;
419 ch.minTimestamp =
ch.maxTimestamp = timestamp;
425 ch.maxTimestamp = timestamp;
430 return !m_session.name.
isEmpty();
443 m_additionalMetadata.
insert(metadata.
name, &metadata);
444 m_newAdditionalMetadata.
insert(metadata.
name);
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void handleStatusChange(QCtfServer::ServerStatus status) override
static QCtfLib * instance()
bool sessionEnabled() override
void registerMetadata(const QCtfTraceMetadata &metadata)
bool tracepointEnabled(const QCtfTracePointEvent &point) override
QCtfTracePointPrivate * initializeTracepoint(const QCtfTracePointEvent &point) override
void handleSessionChange() override
void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) override
void setHost(const QString &address)
QString sessionTracepoints() const
bool bufferOnIdle() const
void setCallback(ServerCallback *cb)
void bufferData(const QString &stream, const QByteArray &data, quint32 flags)
ServerStatus status() const
QString sessionName() const
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
qint64 toMSecsSinceEpoch() const
void start() noexcept
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
qint64 nsecsElapsed() const noexcept
qsizetype size() const noexcept
Returns the number of items in the hash.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
\inmodule QtCore\reentrant
QJsonObject object() const
Returns the QJsonObject contained in the document.
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
\inmodule QtCore\reentrant
bool removeOne(const AT &t)
void append(parameter_type t)
QString objectName
the name of this object
QThread * thread() const
Returns the thread in which the object lives.
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
static QString machineHostName()
T & localData()
Returns a reference to the data that was set by the calling thread.
static QThread * currentThread()
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
int port(int defaultPort=-1) const
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
static const char traceMetadataTemplate[]
static QString toMetadata(const QString &provider, const QString &name, const QString &metadata, quint32 eventId)
static const size_t packetSize
static FILE * openFile(const QString &filename, const QString &mode)
static const size_t traceMetadataSize
static QString defaultLiteral()
static QString allLiteral()
static const size_t packetHeaderSize
static QByteArray & operator<<(QByteArray &arr, T val)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter * sub
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
constexpr const T & qMin(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
#define Q_PROCESSOR_WORDSIZE
#define qPrintable(string)
#define qUtf16Printable(string)
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
unsigned long long quint64
QUrl url("example.com")
[constructor-url-reference]
const QCtfTracePointProvider & provider
QCtfTracePointPrivate * d
QCtfTraceMetadata * metadata
\inmodule QtCore \reentrant