summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <[email protected]>2023-06-20 13:26:52 +0300
committerAntti Määttä <[email protected]>2023-08-03 08:23:30 +0300
commitc6ab516f71efeeaaf2a10dbc0368fb437f8b3a6c (patch)
tree370cdf112de607d82b5f75e485b3357eb8b3cf5b
parent7fe1198f6edb40de2299272c7523d85d7486598b (diff)
CTF: Clear output location at startup
Remove old files from the output location before saving new ones. Pick-to: 6.6 6.5 Change-Id: I75181126c6c920e13951e9a46a6be1c666d457fe Reviewed-by: Antti Määttä <[email protected]> Reviewed-by: Janne Koskinen <[email protected]>
-rw-r--r--src/plugins/tracing/qctflib.cpp30
-rw-r--r--src/plugins/tracing/qctflib_p.h1
2 files changed, 26 insertions, 5 deletions
diff --git a/src/plugins/tracing/qctflib.cpp b/src/plugins/tracing/qctflib.cpp
index 783be079f71..f57f1cf71f2 100644
--- a/src/plugins/tracing/qctflib.cpp
+++ b/src/plugins/tracing/qctflib.cpp
@@ -116,6 +116,7 @@ QCtfLibImpl::QCtfLibImpl()
}
m_location = location + QStringLiteral("/ust");
std::filesystem::create_directory(qPrintable(m_location), qPrintable(location));
+ clearLocation();
}
m_session.all = m_session.tracepoints.contains(QStringLiteral("all"));
@@ -136,6 +137,30 @@ QCtfLibImpl::QCtfLibImpl()
m_timer.start();
}
+void QCtfLibImpl::clearLocation()
+{
+ const std::filesystem::path location{qUtf16Printable(m_location)};
+ for (auto const& dirEntry : std::filesystem::directory_iterator{location})
+ {
+ const auto path = dirEntry.path();
+#if __cplusplus > 201703L
+ if (dirEntry.is_regular_file()
+ && path.filename().wstring().starts_with(std::wstring_view(L"channel_"))
+ && !path.has_extension()) {
+#else
+ const auto strview = std::wstring_view(L"channel_");
+ const auto sub = path.filename().wstring().substr(0, strview.length());
+ if (dirEntry.is_regular_file() && sub.compare(strview) == 0
+ && !path.has_extension()) {
+#endif
+ if (!std::filesystem::remove(path)) {
+ qCInfo(lcDebugTrace) << "Unable to clear output location.";
+ break;
+ }
+ }
+ }
+}
+
void QCtfLibImpl::writeMetadata(const QString &metadata, bool overwrite)
{
FILE *file = nullptr;
@@ -276,11 +301,6 @@ void QCtfLibImpl::doTracepoint(const QCtfTracePointEvent &point, const QByteArra
if (ch.channelName[0] == 0) {
m_threadIndices.insert(thread, m_threadIndices.size());
- sprintf(ch.channelName, "%s/channel_%d", qPrintable(m_location), m_threadIndices[thread]);
- FILE *f = nullptr;
- f = openFile(ch.channelName, "wb"_L1);
- if (f)
- fclose(f);
ch.minTimestamp = ch.maxTimestamp = timestamp;
ch.thread = thread;
ch.threadIndex = m_threadIndices[thread];
diff --git a/src/plugins/tracing/qctflib_p.h b/src/plugins/tracing/qctflib_p.h
index 98f34699bd0..8d88183b84f 100644
--- a/src/plugins/tracing/qctflib_p.h
+++ b/src/plugins/tracing/qctflib_p.h
@@ -89,6 +89,7 @@ private:
QHash<QString, QCtfTracePointPrivate *> m_eventPrivs;
void updateMetadata(const QCtfTracePointEvent &point);
void writeMetadata(const QString &metadata, bool overwrite = false);
+ void clearLocation();
static void writeCtfPacket(Channel &ch);
static constexpr QUuid s_TraceUuid = QUuid(0x3e589c95, 0xed11, 0xc159, 0x42, 0x02, 0x6a, 0x9b, 0x02, 0x00, 0x12, 0xac);