diff mbox series

[1/5] kernel-shark-qt: Avoid spurious searches

Message ID 20181212165826.8218-2-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series More modifications toward KS 1.0 | expand

Commit Message

Yordan Karadzhov Dec. 12, 2018, 4:58 p.m. UTC
Do not search if the text field of search panel is empty.
Most probably this is an accidental key press or mouse click.

The text field gets locked only during the actual searching.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/KsTraceViewer.cpp | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Steven Rostedt Dec. 14, 2018, 3:47 a.m. UTC | #1
On Wed, 12 Dec 2018 16:58:44 +0000
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> Do not search if the text field of search panel is empty.
> Most probably this is an accidental key press or mouse click.
> 
> The text field gets locked only during the actual searching.
> 
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  kernel-shark-qt/src/KsTraceViewer.cpp | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
> index a308ea0..599b687 100644
> --- a/kernel-shark-qt/src/KsTraceViewer.cpp
> +++ b/kernel-shark-qt/src/KsTraceViewer.cpp
> @@ -308,8 +308,6 @@ static bool matchCond(const QString &searchText, const QString &itemText)
>  
>  void KsTraceViewer::_search()
>  {
> -	/* Disable the user input until the search is done. */
> -	_searchLineEdit.setReadOnly(true);

Hmm, can any races happen by setting the search line read only after
the empty checks?

Also, I found a bug. Try this on a large data file. It doesn't matter
what data file it is.

With the Search: at its start up defaults (with Column = "#"), type
"aaa" in the search window and then hit enter. While the search is
going on, hit the "Next" button. See what happens.

-- Steve


>  	if (!_searchDone) {
>  		int xColumn, xSelect;
>  		QString xText;
> @@ -319,7 +317,19 @@ void KsTraceViewer::_search()
>  		 * have been modified since the last time we searched.
>  		 */
>  		_matchList.clear();
> +
>  		xText = _searchLineEdit.text();
> +		if (xText.isEmpty()) {
> +			/*
> +			 * No text is provided by the user. Most probably this
> +			 * is an accidental key press.
> +			 */
> +			return;
> +		}
> +
> +		/* Disable the user input until the search is done. */
> +		_searchLineEdit.setReadOnly(true);
> +
>  		xColumn = _columnComboBox.currentIndex();
>  		xSelect = _selectComboBox.currentIndex();
>  
> @@ -346,6 +356,9 @@ void KsTraceViewer::_search()
>  			if (_graphFollows)
>  				emit select(*_it); // Send a signal to the Graph widget.
>  		}
> +
> +		/* Enable the user input. */
> +		_searchLineEdit.setReadOnly(false);
>  	} else {
>  		/*
>  		 * If the search is done, pressing "Enter" is equivalent
> @@ -353,9 +366,6 @@ void KsTraceViewer::_search()
>  		 */
>  		this->_next();
>  	}
> -
> -	/* Enable the user input. */
> -	_searchLineEdit.setReadOnly(false);
>  }
>  
>  void KsTraceViewer::_next()
Yordan Karadzhov Dec. 14, 2018, 12:02 p.m. UTC | #2
On 14.12.18 г. 5:47 ч., Steven Rostedt wrote:
> On Wed, 12 Dec 2018 16:58:44 +0000
> Yordan Karadzhov <ykaradzhov@vmware.com> wrote:
> 
>> Do not search if the text field of search panel is empty.
>> Most probably this is an accidental key press or mouse click.
>>
>> The text field gets locked only during the actual searching.
>>
>> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
>> ---
>>   kernel-shark-qt/src/KsTraceViewer.cpp | 20 +++++++++++++++-----
>>   1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
>> index a308ea0..599b687 100644
>> --- a/kernel-shark-qt/src/KsTraceViewer.cpp
>> +++ b/kernel-shark-qt/src/KsTraceViewer.cpp
>> @@ -308,8 +308,6 @@ static bool matchCond(const QString &searchText, const QString &itemText)
>>   
>>   void KsTraceViewer::_search()
>>   {
>> -	/* Disable the user input until the search is done. */
>> -	_searchLineEdit.setReadOnly(true);
> 
> Hmm, can any races happen by setting the search line read only after
> the empty checks?
> 
> Also, I found a bug. Try this on a large data file. It doesn't matter
> what data file it is.
> 
> With the Search: at its start up defaults (with Column = "#"), type
> "aaa" in the search window and then hit enter. While the search is
> going on, hit the "Next" button. See what happens.
Deadlock :)

Well spotted, thanks a lot!
I will resend the whole series.

Yordan
diff mbox series

Patch

diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
index a308ea0..599b687 100644
--- a/kernel-shark-qt/src/KsTraceViewer.cpp
+++ b/kernel-shark-qt/src/KsTraceViewer.cpp
@@ -308,8 +308,6 @@  static bool matchCond(const QString &searchText, const QString &itemText)
 
 void KsTraceViewer::_search()
 {
-	/* Disable the user input until the search is done. */
-	_searchLineEdit.setReadOnly(true);
 	if (!_searchDone) {
 		int xColumn, xSelect;
 		QString xText;
@@ -319,7 +317,19 @@  void KsTraceViewer::_search()
 		 * have been modified since the last time we searched.
 		 */
 		_matchList.clear();
+
 		xText = _searchLineEdit.text();
+		if (xText.isEmpty()) {
+			/*
+			 * No text is provided by the user. Most probably this
+			 * is an accidental key press.
+			 */
+			return;
+		}
+
+		/* Disable the user input until the search is done. */
+		_searchLineEdit.setReadOnly(true);
+
 		xColumn = _columnComboBox.currentIndex();
 		xSelect = _selectComboBox.currentIndex();
 
@@ -346,6 +356,9 @@  void KsTraceViewer::_search()
 			if (_graphFollows)
 				emit select(*_it); // Send a signal to the Graph widget.
 		}
+
+		/* Enable the user input. */
+		_searchLineEdit.setReadOnly(false);
 	} else {
 		/*
 		 * If the search is done, pressing "Enter" is equivalent
@@ -353,9 +366,6 @@  void KsTraceViewer::_search()
 		 */
 		this->_next();
 	}
-
-	/* Enable the user input. */
-	_searchLineEdit.setReadOnly(false);
 }
 
 void KsTraceViewer::_next()