From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" <linux-trace-devel@vger.kernel.org>
Subject: [PATCH 04/11] kernel-shark-qt: Optimize the search in the text data
Date: Wed, 21 Nov 2018 15:14:22 +0000 [thread overview]
Message-ID: <20181121151356.16901-6-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181121151356.16901-1-ykaradzhov@vmware.com>
This patch aims to optimize the search by doing two small
modifications:
It changes the type of the matching function used when searching.
This will eliminate the call of the QString copy constructor.
It also adds an intermediate step in the conversion of the tracing
data into the format expected by the QTableView widget (QVariant).
By having this intermediate step we avoid the unnecessary conversion
QString -> QVariant -> QString when searching.
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
kernel-shark-qt/src/KsModels.cpp | 28 ++++++++++++++++-----------
kernel-shark-qt/src/KsModels.hpp | 4 +++-
kernel-shark-qt/src/KsTraceViewer.cpp | 6 +++---
kernel-shark-qt/src/KsTraceViewer.hpp | 3 ---
4 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/kernel-shark-qt/src/KsModels.cpp b/kernel-shark-qt/src/KsModels.cpp
index 5eb1646..d67ee62 100644
--- a/kernel-shark-qt/src/KsModels.cpp
+++ b/kernel-shark-qt/src/KsModels.cpp
@@ -59,8 +59,7 @@ void KsFilterProxyModel::_search(int column,
{
int row, nRows(last - first + 1);
int pbCount(1);
- QVariant item;
- QString text;
+ QString item;
_searchProgress = 0;
@@ -76,10 +75,9 @@ void KsFilterProxyModel::_search(int column,
* of the row number in the base model.
*/
row = mapRowFromSource(r);
- item = _source->getValue(column, row);
- if (cond(searchText, item.toString())) {
+ item = _source->getValueStr(column, row);
+ if (cond(searchText, item))
matchList->append(row);
- }
if (_searchStop) {
_searchStop = false;
@@ -156,7 +154,6 @@ QList<int> KsFilterProxyModel::searchMap(int column,
bool notify)
{
QList<int> matchList;
- qInfo() << "searchMap" << first << last;
_search(column, searchText, cond, &matchList, first, last,
nullptr, nullptr, notify);
@@ -203,15 +200,17 @@ QVariant KsViewModel::data(const QModelIndex &index, int role) const
return {};
}
-/** Get the data stored in a given cell of the table. */
-QVariant KsViewModel::getValue(int column, int row) const
+/** Get the string data stored in a given cell of the table. */
+QString KsViewModel::getValueStr(int column, int row) const
{
+ int pid;
+
switch (column) {
case TRACE_VIEW_COL_INDEX :
- return row;
+ return QString("%1").arg(row);
case TRACE_VIEW_COL_CPU:
- return _data[row]->cpu;
+ return QString("%1").arg(_data[row]->cpu);
case TRACE_VIEW_COL_TS:
return KsUtils::Ts2String(_data[row]->ts, 6);
@@ -220,7 +219,8 @@ QVariant KsViewModel::getValue(int column, int row) const
return kshark_get_task_easy(_data[row]);
case TRACE_VIEW_COL_PID:
- return kshark_get_pid_easy(_data[row]);
+ pid = kshark_get_pid_easy(_data[row]);
+ return QString("%1").arg(pid);
case TRACE_VIEW_COL_LAT:
return kshark_get_latency_easy(_data[row]);
@@ -236,6 +236,12 @@ QVariant KsViewModel::getValue(int column, int row) const
}
}
+/** Get the data stored in a given cell of the table. */
+QVariant KsViewModel::getValue(int column, int row) const
+{
+ return getValueStr(column, row);
+}
+
/**
* Get the header of a column. This is an implementation of the pure virtual
* method of the abstract model class.
diff --git a/kernel-shark-qt/src/KsModels.hpp b/kernel-shark-qt/src/KsModels.hpp
index 00b20b2..b66c259 100644
--- a/kernel-shark-qt/src/KsModels.hpp
+++ b/kernel-shark-qt/src/KsModels.hpp
@@ -28,7 +28,7 @@
#include "libkshark-model.h"
/** Matching condition function type. To be user for searching. */
-typedef bool (*condition_func)(QString, QString);
+typedef bool (*condition_func)(const QString &, const QString &);
enum class DualMarkerState;
@@ -81,6 +81,8 @@ public:
/** Get the list of column's headers. */
QStringList header() const {return _header;}
+ QString getValueStr(int column, int row) const;
+
QVariant getValue(int column, int row) const;
size_t search(int column,
diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
index 7f12365..e92dd83 100644
--- a/kernel-shark-qt/src/KsTraceViewer.cpp
+++ b/kernel-shark-qt/src/KsTraceViewer.cpp
@@ -275,17 +275,17 @@ void KsTraceViewer::_graphFollowsChanged(int state)
emit select(*_it); // Send a signal to the Graph widget.
}
-static bool notHaveCond(QString searchText, QString itemText)
+static bool notHaveCond(const QString &searchText, const QString &itemText)
{
return !itemText.contains(searchText, Qt::CaseInsensitive);
}
-static bool containsCond(QString searchText, QString itemText)
+static bool containsCond(const QString &searchText, const QString &itemText)
{
return itemText.contains(searchText, Qt::CaseInsensitive);
}
-static bool matchCond(QString searchText, QString itemText)
+static bool matchCond(const QString &searchText, const QString &itemText)
{
return (itemText.compare(searchText, Qt::CaseInsensitive) == 0);
}
diff --git a/kernel-shark-qt/src/KsTraceViewer.hpp b/kernel-shark-qt/src/KsTraceViewer.hpp
index 2a85e4f..de8af97 100644
--- a/kernel-shark-qt/src/KsTraceViewer.hpp
+++ b/kernel-shark-qt/src/KsTraceViewer.hpp
@@ -20,9 +20,6 @@
#include "KsModels.hpp"
#include "KsDualMarker.hpp"
-/** Matching condition function type. To be user for searchong. */
-typedef bool (*condition_func)(QString, QString);
-
/**
* The KsTraceViewer class provides a widget for browsing in the trace data
* shown in a text form.
--
2.17.1
next prev parent reply other threads:[~2018-11-22 1:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-21 15:14 [PATCH 00/11] Small modifications and bug fixes toward KS 1.0 Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 01/11] kernel-shark-qt: protect all calls of tep_read_number_field() Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 01/11] kernel-shark-qt: Protect " Yordan Karadzhov
2018-11-27 20:34 ` Steven Rostedt
2018-11-21 15:14 ` [PATCH 02/11] kernel-shark-qt: Fix the returned error value of kshark_get_event_id_easy() Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 03/11] kernel-shark-qt: Avoid race condition in kshark_get_event_name_easy() Yordan Karadzhov
2018-11-27 20:37 ` Steven Rostedt
2018-11-21 15:14 ` Yordan Karadzhov [this message]
2018-11-21 15:14 ` [PATCH 05/11] kernel-shark-qt: Add iterator index to the search panel Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 06/11] kernel-shark-qt: Update search iterator when marker is changed Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 07/11] kernel-shark-qt: Optimize the search in a case of a small data-set Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 08/11] kernel-shark qt: No error when Record authentication dialog is closed Yordan Karadzhov
2018-11-27 20:45 ` Steven Rostedt
2018-11-21 15:14 ` [PATCH 09/11] kernel-shark-qt: Remove all system=ftrace events from Record dialog Yordan Karadzhov
2018-11-27 23:02 ` [PATCH 00/11] Small modifications and bug fixes toward KS 1.0 Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181121151356.16901-6-ykaradzhov@vmware.com \
--to=ykaradzhov@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).