kernel-shark: Hide CPUs with no data in them
PATCH 1/2 kernel-shark: Hide CPUs with no data in them
A hash table, storring all idle CPUs is added to the session context. If a CPU does not contain any data (is idle), its plot is not shown by default when KernelShark starts. Note that, if the option '--cpu' is used, it has priority and if idle CPUs are selected, the corresponding empty CPU plots will be displayed.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215677
--- src/KsGLWidget.cpp | 11 ++++++++--- src/libkshark-tepdata.c | 5 ++++- src/libkshark.c | 6 ++++++ src/libkshark.h | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-)
src/KsGLWidget.cpp +8 -3
@@ -419,6 +419,7 @@ void KsGLWidget::keyReleaseEvent(QKeyEvent *event) void KsGLWidget::_defaultPlots(kshark_context *kshark_ctx) { + struct kshark_data_stream *stream; QVector<int> streamIds, plotVec; uint64_t tMin, tMax; int nCPUs, nBins;
@@ -432,15 +433,19 @@ void KsGLWidget::_defaultPlots(kshark_context *kshark_ctx) */ streamIds = KsUtils::getStreamIdList(kshark_ctx); for (auto const &sd: streamIds) { - nCPUs = kshark_ctx->stream[sd]->n_cpus; + stream = kshark_ctx->stream[sd]; + nCPUs = stream->n_cpus; plotVec.clear(); /* If the number of CPUs is too big show only the first 16. */ if (nCPUs > KS_MAX_START_PLOTS / kshark_ctx->n_streams) nCPUs = KS_MAX_START_PLOTS / kshark_ctx->n_streams; - for (int i = 0; i < nCPUs; ++i) - plotVec.append(i); + for (int cpu{0}; cpu < stream->n_cpus && plotVec.count() < nCPUs; ++cpu) { + /* Do not add plots for idle CPUs. */ + if (!kshark_hash_id_find(stream->idle_cpus, cpu)) + plotVec.append(cpu); + } _streamPlots[sd]._cpuList = plotVec; _streamPlots[sd]._taskList = {};
src/libkshark-tepdata.c +4 -1
@@ -391,7 +391,10 @@ static ssize_t get_records(struct kshark_context *kshark_ctx, rec =tracecmd_read_data (kshark_get_tep_input (stream), cpu); } - total += count; +if (!count) +kshark_hash_id_add (stream->idle_cpus, cpu); +else + total += count; } *rec_list = cpu_list;
src/libkshark.c +6 -0
@@ -121,6 +121,8 @@ static void kshark_stream_free(struct kshark_data_stream *stream)if (!stream)return ; +kshark_hash_id_free (stream->idle_cpus); +kshark_hash_id_free (stream->show_task_filter);kshark_hash_id_free (stream->hide_task_filter);
@@ -147,6 +149,8 @@ static struct kshark_data_stream *kshark_stream_alloc()if (!stream) goto fail; + stream->idle_cpus =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + stream->show_task_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); stream->hide_task_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS );
@@ -433,6 +437,8 @@ static int kshark_stream_close(struct kshark_data_stream *stream)kshark_hash_id_clear (stream->show_cpu_filter);kshark_hash_id_clear (stream->hide_cpu_filter); +kshark_hash_id_clear (stream->idle_cpus); +if (kshark_is_tep (stream))return kshark_tep_close_interface (stream);
src/libkshark.h +3 -0
@@ -286,6 +286,9 @@ struct kshark_data_stream {/** The number of CPUs presented in this data stream. */ int n_cpus; +/** Hash table of Idle CPUs. */ +struct kshark_hash_id *idle_cpus; +/** * The number of distinct event types presented in this data stream. */
Signature · 1 line
2.32.0
PATCH 2/2 kernel-shark: CPU plots dialog ease spotting empty CPUs
The CPU plots dialog will show only the ones with content. A "hide empty" checkbox is added, that by default is checked. If it is unchecked, then all the CPUs would show up.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215677
--- src/KsWidgetsLib.cpp | 26 +++++++++++++++++++++++++- src/KsWidgetsLib.hpp | 7 +++++-- 2 files changed, 30 insertions(+), 3 deletions(-)
src/KsWidgetsLib.cpp +25 -1
@@ -906,12 +906,35 @@ void KsCheckBoxTreeWidget::_verify() * @param parent: The parent of this widget. */ KsCPUCheckBoxWidget::KsCPUCheckBoxWidget(kshark_data_stream *stream, QWidget *parent) -: KsCheckBoxTreeWidget(stream->stream_id, "CPUs", parent) +: KsCheckBoxTreeWidget(stream->stream_id, "CPUs", parent), + _hideEmpty("hide empty") { int height(FONT_HEIGHT * 1.5); KsPlot::ColorTable colors; QString style; + _hideEmpty.setCheckState(Qt::Checked); + _tb.addSeparator(); + _tb.addWidget(&_hideEmpty); + + auto lamHideEmpty = [this, stream] (bool hide) { + QTreeWidgetItem *item; + bool isIdle; + + for(int cpu = 0; cpu < stream->n_cpus; ++cpu) { + item = _tree.topLevelItem(cpu); + if (hide) { + isIdle = kshark_hash_id_find(stream->idle_cpus, cpu); + item->setHidden(isIdle); + } else { + item->setHidden(false); + } + } + }; + + connect(&_hideEmpty, &QCheckBox::clicked, + lamHideEmpty); + style = QString("QTreeView::item { height: %1 ;}").arg(height); _tree.setStyleSheet(style);
@@ -934,6 +957,7 @@ KsCPUCheckBoxWidget::KsCPUCheckBoxWidget(kshark_data_stream *stream, QWidget *pa _cb[i] = cpuItem; } + lamHideEmpty(true); _adjustSize(); }
src/KsWidgetsLib.hpp +5 -2
@@ -275,10 +275,9 @@ public: /** The user provided an input. The widget has been modified. */ bool _userInput; -private: +protected: QToolBar _tb; -protected: /** Identifier of the Data stream for which the selection applies. */ int _sd;
@@ -544,6 +543,10 @@ struct KsCPUCheckBoxWidget : public KsCheckBoxTreeWidget KsCPUCheckBoxWidget(kshark_data_stream *stream, QWidget *parent = nullptr); + +private: + /** The "hide empty" checkbox. */ + QCheckBox _hideEmpty; }; /**
Signature · 1 line
2.32.0
Re: [PATCH 2/2] kernel-shark: CPU plots dialog ease spotting empty CPUs
Quoted 8 lines · On Wed, 16 Mar 2022 16:37:17 +0200 "Yordan Karadzhov (VMware)"…
The CPU plots dialog will show only the ones with content. A "hide empty" checkbox is added, that by default is checked. If it is unchecked, then all the CPUs would show up.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215677
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>---
This is awesome Yordan!
It's exactly what I was looking for.
Although, I found that if I select more that 16 CPU plots at a time it hangs. I can add that to the BZ. (I noticed this before these patches).
-- Steve
Re: [PATCH 2/2] kernel-shark: CPU plots dialog ease spotting empty CPUs
Quoted 2 lines · On Wed, 16 Mar 2022 11:03:56 -0400 Steven Rostedt <[email protected]> wrote:
Although, I found that if I select more that 16 CPU plots at a time it hangs. I can add that to the BZ. (I noticed this before these patches).
Strange, it hung just before posting this, but trying it again, I can't reproduce the lockup :-/
I'll play some more with it.
-- Steve