From patchwork Wed Nov 21 15:14:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10759849 Return-Path: Received: from mail-eopbgr790053.outbound.protection.outlook.com ([40.107.79.53]:64832 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730820AbeKVBvK (ORCPT ); Wed, 21 Nov 2018 20:51:10 -0500 From: Yordan Karadzhov To: "rostedt@goodmis.org" CC: "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 Message-ID: <20181121151356.16901-6-ykaradzhov@vmware.com> References: <20181121151356.16901-1-ykaradzhov@vmware.com> In-Reply-To: <20181121151356.16901-1-ykaradzhov@vmware.com> Content-Language: en-US MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org List-ID: Content-Length: 5479 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 --- 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 KsFilterProxyModel::searchMap(int column, bool notify) { QList 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.