15#include <qplatformdefs.h>
29#include "metadata_template.h"
36 static_assert(std::is_arithmetic_v<T>);
60 qCInfo(lcDebugTrace) <<
"QTRACE_LOCATION not set";
66 qCWarning(lcDebugTrace) <<
"Unable to write to location";
73 qCWarning(lcDebugTrace) <<
"unable to open session file: "
80 if (QT_FSTAT(QT_FILENO(
file), &stat) != 0) {
84 qsizetype filesize =
qMin(stat.st_size, std::numeric_limits<qsizetype>::max());
96 if (
it.value().isArray()) {
97 m_session.name =
it.key();
98 for (
auto var :
it.value().toArray())
104 qCWarning(lcDebugTrace) <<
"Session file is not valid";
111 m_session.all = m_session.tracepoints.contains(
QStringLiteral(
"all"));
125#if Q_BYTE_ORDER == Q_BIG_ENDIAN
130 writeMetadata(metadata,
true);
134void QCtfLibImpl::writeMetadata(
const QString &metadata,
bool overwrite)
136 FILE *
file =
nullptr;
137 file = fopen(
qPrintable(m_location +
"/metadata"_L1), overwrite ?
"w+b":
"ab");
150void QCtfLibImpl::writeCtfPacket(QCtfLibImpl::Channel &
ch)
152 FILE *
file =
nullptr;
153 file = fopen(
ch.channelName,
"ab");
157 packet << s_CtfHeaderMagic;
161 packet <<
ch.minTimestamp;
162 packet <<
ch.maxTimestamp;
165 packet <<
ch.seqnumber++;
167 packet <<
ch.threadIndex;
168 if (
ch.threadName.size())
176 fwrite(
ch.data.data(),
ch.data.size(), 1,
file);
188 return m_session.all || m_session.tracepoints.contains(point.
provider.
provider);
191QCtfLibImpl::Channel::~Channel()
194 QCtfLibImpl::writeCtfPacket(*
this);
214 ret +=
QStringLiteral(
" stream_id = 0;\n loglevel = 13;\n fields := struct {\n ");
243 if (!
priv->metadataWritten) {
244 priv->metadataWritten =
true;
246 while (providerMetadata) {
248 providerMetadata = providerMetadata->next;
250 if (m_newAdditionalMetadata.
size()) {
251 for (
const QString &
name : m_newAdditionalMetadata)
252 writeMetadata(m_additionalMetadata[
name]->metadata);
253 m_newAdditionalMetadata.
clear();
255 writeMetadata(
priv->metadata);
272 if (
ch.channelName[0] == 0) {
274 sprintf(
ch.channelName,
"%s/channel_%d",
qPrintable(m_location), m_threadIndices[
thread]);
276 f = fopen(
ch.channelName,
"wb");
279 ch.minTimestamp =
ch.maxTimestamp = timestamp;
281 ch.threadIndex = m_threadIndices[
thread];
283 if (
ch.threadName.isEmpty()) {
287 ch.threadNameLength =
ch.threadName.size() + 1;
295 event <<
priv->id << timestamp;
302 ch.minTimestamp =
ch.maxTimestamp = timestamp;
308 ch.maxTimestamp = timestamp;
313 return !m_session.name.isEmpty();
326 m_additionalMetadata.
insert(metadata.
name, &metadata);
327 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.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QCtfLib * instance()
bool sessionEnabled() override
void registerMetadata(const QCtfTraceMetadata &metadata)
bool tracepointEnabled(const QCtfTracePointEvent &point) override
QCtfTracePointPrivate * initializeTracepoint(const QCtfTracePointEvent &point) override
void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) override
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
QDateTime toUTC() const
Returns a copy of this datetime converted to UTC.
void start() noexcept
Starts this timer.
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
QString objectName
the name of this object
QThread * thread() const
Returns the thread in which the object lives.
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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 toString(StringFormat mode=WithBraces) const
Id128Bytes toBytes(QSysInfo::Endian order=QSysInfo::BigEndian) const noexcept
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 const size_t traceMetadataSize
static const size_t packetHeaderSize
static QByteArray & operator<<(QByteArray &arr, T val)
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
#define Q_PROCESSOR_WORDSIZE
#define qPrintable(string)
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
unsigned long long quint64
const QCtfTracePointProvider & provider
QCtfTracePointPrivate * d
QCtfTraceMetadata * metadata
\inmodule QtCore \reentrant