Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove query stuff from record page #454

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ set_package_properties(

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package(
KF${QT_MAJOR_VERSION}
KF${QT_MAJOR_VERSION} 5.42.0
COMPONENTS ThreadWeaver
ConfigWidgets
CoreAddons
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set(HOTSPOT_SRCS
initiallystoppedprocess.cpp
perfcontrolfifowrapper.cpp
errnoutil.cpp
recordhost.cpp
# ui files:
mainwindow.ui
aboutdialog.ui
Expand All @@ -73,6 +74,7 @@ set(HOTSPOT_SRCS
callgraphsettingspage.ui
frequencypage.ui
sourcepathsettings.ui
perfsettingspage.ui
# resources:
resources.qrc
)
Expand Down
63 changes: 63 additions & 0 deletions src/jobtracker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
SPDX-FileCopyrightText: Milian Wolff <milian.wolff@kdab.com>
SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com

SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include <ThreadWeaver/ThreadWeaver>
#include <QObject>
#include <QPointer>

class JobTracker
{
public:
explicit JobTracker(QObject* context)
: m_context(context)
{
}

bool isJobRunning() const
{
return m_context && m_isRunning;
}

template<typename Job, typename SetData>
void startJob(Job&& job, SetData&& setData)
{
using namespace ThreadWeaver;
const auto jobId = ++m_currentJobId;
auto jobCancelled = [context = m_context, jobId, currentJobId = &m_currentJobId]() {
return !context || jobId != (*currentJobId);
};
auto maybeSetData = [jobCancelled, setData = std::forward<SetData>(setData),
isRunning = &m_isRunning](auto&& results) {
if (!jobCancelled()) {
setData(std::forward<decltype(results)>(results));
*isRunning = false;
}
};

m_isRunning = true;
stream() << make_job([context = m_context, job = std::forward<Job>(job), maybeSetData = std::move(maybeSetData),
jobCancelled = std::move(jobCancelled)]() mutable {
auto results = job(jobCancelled);
if (jobCancelled())
return;

QMetaObject::invokeMethod(
context.data(),
[results = std::move(results), maybeSetData = std::move(maybeSetData)]() mutable {
maybeSetData(std::move(results));
},
Qt::QueuedConnection);
});
}

private:
QPointer<QObject> m_context;
std::atomic<uint> m_currentJobId;
bool m_isRunning = false;
};
8 changes: 8 additions & 0 deletions src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ struct Summary
QStringList errors;
};

struct ThreadNames
{
QHash<qint32, QHash<qint32, QString>> names;
};

struct EventResults
{
QVector<ThreadEvents> threads;
Expand Down Expand Up @@ -951,6 +956,9 @@ Q_DECLARE_TYPEINFO(Data::Summary, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(Data::CostSummary)
Q_DECLARE_TYPEINFO(Data::CostSummary, Q_MOVABLE_TYPE);

Q_DECLARE_METATYPE(Data::ThreadNames)
Q_DECLARE_TYPEINFO(Data::ThreadNames, Q_MOVABLE_TYPE);

Q_DECLARE_METATYPE(Data::EventResults)
Q_DECLARE_TYPEINFO(Data::EventResults, Q_MOVABLE_TYPE);

Expand Down
3 changes: 3 additions & 0 deletions src/multiconfigwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void MultiConfigWidget::setConfig(const KConfigGroup& group)
m_comboBox->clear();
m_config = group;

if (!m_config.isValid())
return;

const auto groups = m_config.groupList();
for (const auto& config : groups) {
if (m_config.hasGroup(config)) {
Expand Down
31 changes: 17 additions & 14 deletions src/parsers/perf/perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,20 +555,20 @@ void addCallerCalleeEvent(const Data::Symbol& symbol, const Data::Location& loca

template<typename FrameCallback>
void addBottomUpResult(Data::BottomUpResults* bottomUpResult, Settings::CostAggregation costAggregation,
const QHash<qint32, QHash<qint32, QString>>& commands, int type, quint64 cost, qint32 pid,
qint32 tid, quint32 cpu, const QVector<qint32>& frames, const FrameCallback& frameCallback)
const Data::ThreadNames& commands, int type, quint64 cost, qint32 pid, qint32 tid, quint32 cpu,
const QVector<qint32>& frames, const FrameCallback& frameCallback)
{
switch (costAggregation) {
case Settings::CostAggregation::BySymbol:
bottomUpResult->addEvent(type, cost, frames, frameCallback);
break;
case Settings::CostAggregation::ByThread: {
auto thread = commands.value(pid).value(tid);
auto thread = commands.names.value(pid).value(tid);
bottomUpResult->addEvent(thread.isEmpty() ? QString::number(tid) : thread, type, cost, frames, frameCallback);
break;
}
case Settings::CostAggregation::ByProcess: {
auto process = commands.value(pid).value(pid);
auto process = commands.names.value(pid).value(pid);
bottomUpResult->addEvent(process.isEmpty() ? QString::number(pid) : process, type, cost, frames, frameCallback);
break;
}
Expand Down Expand Up @@ -747,8 +747,8 @@ class PerfParserPrivate : public QObject
auto thread = addThread(threadStart);
thread->time.start = threadStart.time;
if (threadStart.ppid != threadStart.pid) {
const auto parentComm = commands.value(threadStart.ppid).value(threadStart.ppid);
commands[threadStart.pid][threadStart.pid] = parentComm;
const auto parentComm = commands.names.value(threadStart.ppid).value(threadStart.ppid);
commands.names[threadStart.pid][threadStart.pid] = parentComm;
thread->name = parentComm;
}
break;
Expand Down Expand Up @@ -960,9 +960,9 @@ class PerfParserPrivate : public QObject
// we started the application, otherwise we override the start time when
// we encounter a ThreadStart event
thread.time.start = applicationTime.start;
thread.name = commands.value(thread.pid).value(thread.tid);
thread.name = commands.names.value(thread.pid).value(thread.tid);
if (thread.name.isEmpty() && thread.pid != thread.tid)
thread.name = commands.value(thread.pid).value(thread.pid);
thread.name = commands.names.value(thread.pid).value(thread.pid);
eventResult.threads.push_back(thread);
return &eventResult.threads.last();
}
Expand All @@ -984,7 +984,7 @@ class PerfParserPrivate : public QObject
thread->name = comm;
}
// and remember the command, maybe a future ThreadStart event references it
commands[command.pid][command.tid] = comm;
commands.names[command.pid][command.tid] = comm;
}

void addLocation(const LocationDefinition& location)
Expand Down Expand Up @@ -1124,7 +1124,7 @@ class PerfParserPrivate : public QObject
void addSampleToBottomUp(const Sample& sample, SampleCost sampleCost)
{
if (perfScriptOutput) {
*perfScriptOutput << commands.value(sample.pid).value(sample.pid) << '\t' << sample.pid << '\t'
*perfScriptOutput << commands.names.value(sample.pid).value(sample.pid) << '\t' << sample.pid << '\t'
<< sample.time / 1000000000 << '.' << qSetFieldWidth(9) << qSetPadChar(QLatin1Char('0'))
<< sample.time % 1000000000 << qSetFieldWidth(0) << ":\t" << sampleCost.cost << ' '
<< strings.value(attributes.value(sampleCost.attributeId).name.id) << '\n';
Expand Down Expand Up @@ -1376,7 +1376,7 @@ class PerfParserPrivate : public QObject
Data::EventResults eventResult;
Data::TracepointResults tracepointResult;
Data::FrequencyResults frequencyResult;
QHash<qint32, QHash<qint32, QString>> commands;
Data::ThreadNames commands;
std::unique_ptr<QTextStream> perfScriptOutput;
QHash<qint32, SymbolCount> numSymbolsByModule;
QSet<QString> encounteredErrors;
Expand Down Expand Up @@ -1420,6 +1420,7 @@ PerfParser::PerfParser(QObject* parent)
qRegisterMetaType<Data::PerLibraryResults>();
qRegisterMetaType<Data::TracepointResults>();
qRegisterMetaType<Data::FrequencyResults>();
qRegisterMetaType<Data::ThreadNames>();

// set data via signal/slot connection to ensure we don't introduce a data race
connect(this, &PerfParser::bottomUpDataAvailable, this, [this](const Data::BottomUpResults& data) {
Expand Down Expand Up @@ -1447,6 +1448,8 @@ PerfParser::PerfParser(QObject* parent)
m_tracepointResults = data;
}
});
connect(this, &PerfParser::threadNamesAvailable, this,
[this](const Data::ThreadNames& threadNames) { m_threadNames = threadNames; });
connect(this, &PerfParser::parsingStarted, this, [this]() {
m_isParsing = true;
m_stopRequested = false;
Expand Down Expand Up @@ -1560,14 +1563,14 @@ void PerfParser::startParseFile(const QString& path)
emit tracepointDataAvailable(d.tracepointResult);
emit eventsAvailable(d.eventResult);
emit frequencyDataAvailable(d.frequencyResult);
emit parsingFinished();

m_threadNames = d.commands;
emit threadNamesAvailable(d.commands);

if (d.m_numSamplesWithMoreThanOneFrame == 0) {
emit parserWarning(tr("Samples contained no call stack frames. Consider passing <code>--call-graph "
"dwarf</code> to <code>perf record</code>."));
}

emit parsingFinished();
};

if (path.endsWith(QLatin1String(".perfparser"))) {
Expand Down
3 changes: 2 additions & 1 deletion src/parsers/perf/perfparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class PerfParser : public QObject
void tracepointDataAvailable(const Data::TracepointResults& data);
void frequencyDataAvailable(const Data::FrequencyResults& data);
void eventsAvailable(const Data::EventResults& events);
void threadNamesAvailable(const Data::ThreadNames& threadNames);
void parsingFinished();
void parsingFailed(const QString& errorMessage);
void exportFailed(const QString& errorMessage);
Expand Down Expand Up @@ -86,5 +87,5 @@ class PerfParser : public QObject
std::atomic<bool> m_stopRequested;
std::atomic<bool> m_costAggregationChanged;
std::unique_ptr<QTemporaryFile> m_decompressed;
QHash<qint32, QHash<qint32, QString>> m_threadNames;
Data::ThreadNames m_threadNames;
};
Loading