Skip to contentSkip to conversation

Fixes for KS 1.0

PATCH In review Yordan Karadzhov (VMware) 2 participants 10 messages Jul 17, 2019 – Jul 18, 2019

lore
Share & tools
lore
#0 lore raw

cover Fixes for KS 1.0

It turns that there are number of ways to crash the GUI if you click buttons or play with the mouse before any data is loaded. This patch-set tries to get this fixed.

Yordan Karadzhov (VMware) (2):
kernel-shark: Initialize the data-related fields of the model
kernel-shark: Always check if data is loaded before changing the
graphs

 kernel-shark/src/KsGLWidget.cpp    | 22 ++++++++++++++++++++--
 kernel-shark/src/KsGLWidget.hpp    |  2 ++
 kernel-shark/src/KsTraceGraph.cpp  |  9 +++++++++
 kernel-shark/src/libkshark-model.c |  3 +++
 4 files changed, 34 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 kernel-shark: Initialize the data-related fields of the model

It is particularly important to initialize to zero the "data_size" field because its value is used when doing operations like scroll or zoom to check if data has been loaded or not. Not having "data_size" set to zero can cause segfault (as reported by Steven).

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
 kernel-shark/src/libkshark-model.c | 3 +++
 1 file changed, 3 insertions(+)
kernel-shark/src/libkshark-model.c +3 -0
index 18f9c69..fd4d876 100644
@@ -36,6 +36,9 @@ void ksmodel_init(struct kshark_trace_histo *histo)
 	 * Initialize an empty histo. The histo will have no bins and will
 	 * contain no data.
 	 */
+	histo->data_size = 0;
+	histo->data = NULL;
+
 	histo->bin_size = 0;
 	histo->min = 0;
 	histo->max = 0;
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 17 lines · On Wed, 17 Jul 2019 11:53:05 +0300 "Yordan Karadzhov (VMware)"…

It is particularly important to initialize to zero the "data_size" field because its value is used when doing operations like scroll or zoom to check if data has been loaded or not. Not having "data_size" set to zero can cause segfault (as reported by Steven).

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
 kernel-shark/src/libkshark-model.c | 3 +++
 1 file changed, 3 insertions(+)
kernel-shark/src/libkshark-model.c +0 -0
index 18f9c69..fd4d876 100644

kernel-shark/src/libkshark-model.c void ksmodel_init(struct kshark_trace_histo *histo) · line 44

Quoted 9 lines
kernel-shark/src/libkshark-model.c +3 -0
@@ -36,6 +36,9 @@ void ksmodel_init(struct kshark_trace_histo *histo)
 	 * Initialize an empty histo. The histo will have no bins and will
 	 * contain no data.
 	 */
+	histo->data_size = 0;
+	histo->data = NULL;
+
 	histo->bin_size = 0;
 	histo->min = 0;
 	histo->max = 0;

Are we just trying to set all fields of histo to NULL or zero? If so, why not just do:

	memset(histo, 0, sizeof(*histo));

?

This will make sure ksmodel_init() zeros all of histo when/if we add new fields.

-- Steve

#3 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 33 lines · Steven Rostedt
Quoted 17 lines · On Wed, 17 Jul 2019 11:53:05 +0300 "Yordan Karadzhov (VMware)"…

It is particularly important to initialize to zero the "data_size" field because its value is used when doing operations like scroll or zoom to check if data has been loaded or not. Not having "data_size" set to zero can cause segfault (as reported by Steven).

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
  kernel-shark/src/libkshark-model.c | 3 +++
  1 file changed, 3 insertions(+)
kernel-shark/src/libkshark-model.c +0 -0
index 18f9c69..fd4d876 100644

kernel-shark/src/libkshark-model.c void ksmodel_init(struct kshark_trace_histo *histo) · line 44

Quoted 9 lines
kernel-shark/src/libkshark-model.c +3 -0
@@ -36,6 +36,9 @@ void ksmodel_init(struct kshark_trace_histo *histo)
  	 * Initialize an empty histo. The histo will have no bins and will
  	 * contain no data.
  	 */
+	histo->data_size = 0;
+	histo->data = NULL;
+
  	histo->bin_size = 0;
  	histo->min = 0;
  	histo->max = 0;

Are we just trying to set all fields of histo to NULL or zero? If so, why not just do:

Quoted 7 lines
	memset(histo, 0, sizeof(*histo));

?

This will make sure ksmodel_init() zeros all of histo when/if we add new fields.

Yes, this will do a better job.

Thanks!
Yordan

Quoted 2 lines

-- Steve

#4 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 5 lines · On Wed, 17 Jul 2019 15:42:31 +0300 "Yordan Karadzhov (VMware)"…
Quoted 5 lines

Are we just trying to set all fields of histo to NULL or zero? If so, why not just do:

	memset(histo, 0, sizeof(*histo));
Quoted 7 lines
Quoted 5 lines

?

This will make sure ksmodel_init() zeros all of histo when/if we add new fields.

Yes, this will do a better job.

Care to send a v2 patch?

Thanks Yordan!

-- Steve

#5 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 10 lines · Steven Rostedt
Quoted 7 lines · On Wed, 17 Jul 2019 15:42:31 +0300 "Yordan Karadzhov (VMware)"…
Quoted 7 lines

Are we just trying to set all fields of histo to NULL or zero? If so, why not just do:

	memset(histo, 0, sizeof(*histo));

?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

This will make sure ksmodel_init() zeros all of histo when/if we add new fields.

Yes, this will do a better job.

Care to send a v2 patch?

Just make the change and apply, if this is OK with you.

Thanks a lot!
Yordan

Quoted 5 lines

Thanks Yordan!

-- Steve

#6 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 5 lines · On Wed, 17 Jul 2019 16:38:47 +0300 "Yordan Karadzhov (VMware)"…
Quoted 2 lines

Care to send a v2 patch?

Just make the change and apply, if this is OK with you.

Here's the new patch:

From: "Steven Rostedt (VMware)" <[email protected]>
Subject: [PATCH] kernel-shark: Initialize all fields of struct kshark_trace_histo

The function ksmodel_init() is to initialize the kshark_trace_histo structure to zero. Currently it does it via each field. It is safer to use memset() that will guarantee that the entire structure is set to zeros or NULLs if new fields are added. This is required because there's places in the code that check if a field is NULL or zero to determine if it should be set or not.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
 kernel-shark/src/libkshark-model.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
(quoted diff) +0 -0

b/kernel-shark/src/libkshark-model.c index 18f9c691..6c54e1e1 100644

kernel-shark/src/libkshark-model.c +0 -0
@@ -36,13 +36,7 @@ void ksmodel_init(struct kshark_trace_histo *histo)
 	 * Initialize an empty histo. The histo will have no bins and

will
* contain no data.
*/
- histo->bin_size = 0;
- histo->min = 0;
- histo->max = 0;
- histo->n_bins = 0;
-
- histo->bin_count = NULL;
- histo->map = NULL;
+ memset(histo, 0, sizeof(*histo));
}

/**

Signature · 1 line
2.20.1
#7 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

And here's the version that claws-mail didn't line wrap :-p

-- Steve

From: "Steven Rostedt (VMware)" <[email protected]>
Subject: [PATCH] kernel-shark: Initialize all fields of struct kshark_trace_histo

The function ksmodel_init() is to initialize the kshark_trace_histo structure to zero. Currently it does it via each field. It is safer to use memset() that will guarantee that the entire structure is set to zeros or NULLs if new fields are added. This is required because there's places in the code that check if a field is NULL or zero to determine if it should be set or not.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
 kernel-shark/src/libkshark-model.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
kernel-shark/src/libkshark-model.c +1 -7
index 18f9c691..6c54e1e1 100644
@@ -36,13 +36,7 @@ void ksmodel_init(struct kshark_trace_histo *histo)
 	 * Initialize an empty histo. The histo will have no bins and will
 	 * contain no data.
 	 */
-	histo->bin_size = 0;
-	histo->min = 0;
-	histo->max = 0;
-	histo->n_bins = 0;
-
-	histo->bin_count = NULL;
-	histo->map = NULL;
+	memset(histo, 0, sizeof(*histo));
 }
 
 /**
Signature · 1 line
2.20.1
author Reviewed-by
#8 lore raw

Re: [PATCH 1/2] kernel-shark: Initialize the data-related fields of the model

Quoted 33 lines · Steven Rostedt

And here's the version that claws-mail didn't line wrap :-p

-- Steve

From: "Steven Rostedt (VMware)" <[email protected]>
Subject: [PATCH] kernel-shark: Initialize all fields of struct kshark_trace_histo

The function ksmodel_init() is to initialize the kshark_trace_histo structure to zero. Currently it does it via each field. It is safer to use memset() that will guarantee that the entire structure is set to zeros or NULLs if new fields are added. This is required because there's places in the code that check if a field is NULL or zero to determine if it should be set or not.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204195

---
  kernel-shark/src/libkshark-model.c | 8 +-------
  1 file changed, 1 insertion(+), 7 deletions(-)
kernel-shark/src/libkshark-model.c +0 -1
index 18f9c691..6c54e1e1 100644
@@ -36,13 +36,7 @@ void ksmodel_init(struct kshark_trace_histo *histo)
  	 * Initialize an empty histo. The histo will have no bins and will
  	 * contain no data.
  	 */
-	histo->bin_size = 0;

kernel-shark/src/libkshark-model.c void ksmodel_init(struct kshark_trace_histo *histo) · line 42

Quoted 10 lines
kernel-shark/src/libkshark-model.c +1 -6
-	histo->min = 0;
-	histo->max = 0;
-	histo->n_bins = 0;
-
-	histo->bin_count = NULL;
-	histo->map = NULL;
+	memset(histo, 0, sizeof(*histo));
  }
 
  /**

Thanks!
Yordan

#9 lore raw

PATCH 2/2 kernel-shark: Always check if data is loaded before changing the graphs

In reply to Yordan Karadzhov (VMware)

We want all operations over the graphs (like Zoom or Scroll) to be protected for the case when no data is loaded or no graphs are plotted.

---
 kernel-shark/src/KsGLWidget.cpp   | 22 ++++++++++++++++++++--
 kernel-shark/src/KsGLWidget.hpp   |  2 ++
 kernel-shark/src/KsTraceGraph.cpp |  9 +++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)
kernel-shark/src/KsGLWidget.cpp +20 -2
index ce68052..e930006 100644
@@ -88,9 +88,11 @@ void KsGLWidget::paintGL()
 
 	glClear(GL_COLOR_BUFFER_BIT);
 
+	if (isEmpty())
+		return;
+
 	/* Draw the time axis. */
-	if(_data)
-		_drawAxisX(size);
+	_drawAxisX(size);
 
 	/* Process and draw all graphs by using the built-in logic. */
 	_makeGraphs(_cpuList, _taskList);
@@ -127,6 +129,13 @@ void KsGLWidget::reset()
 	_model.reset();
 }
 
+/** Check if the widget is empty (not showing anything). */
+bool KsGLWidget::isEmpty() const {
+	return !_data ||
+	       !_data->size() ||
+	       (!_cpuList.size() && !_taskList.size());
+}
+
 /** Reimplemented event handler used to receive mouse press events. */
 void KsGLWidget::mousePressEvent(QMouseEvent *event)
 {
@@ -198,6 +207,9 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event)
 	size_t row;
 	bool ret;
 
+	if (isEmpty())
+		return;
+
 	if (_rubberBand.isVisible())
 		_rangeBoundStretched(_posInRange(event->pos().x()));
 
@@ -224,6 +236,9 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event)
 /** Reimplemented event handler used to receive mouse release events. */
 void KsGLWidget::mouseReleaseEvent(QMouseEvent *event)
 {
+	if (isEmpty())
+		return;
+
 	if (event->button() == Qt::LeftButton) {
 		size_t posMouseRel = _posInRange(event->pos().x());
 		int min, max;
@@ -251,6 +266,9 @@ void KsGLWidget::wheelEvent(QWheelEvent * event)
 {
 	int zoomFocus;
 
+	if (isEmpty())
+		return;
+
 	if (_mState->activeMarker()._isSet &&
 	    _mState->activeMarker().isVisible()) {
 		/*
kernel-shark/src/KsGLWidget.hpp +2 -0
index e141b0a..3d428b1 100644
@@ -41,6 +41,8 @@ public:
 
 	void reset();
 
+	bool isEmpty() const;
+
 	/** Reprocess all graphs. */
 	void update() {resizeGL(width(), height());}
 
kernel-shark/src/KsTraceGraph.cpp +9 -0
index 324f36e..2e48372 100644
@@ -234,6 +234,9 @@ void KsTraceGraph::_zoomOut()
 
 void KsTraceGraph::_quickZoomIn()
 {
+	if (_glWindow.isEmpty())
+		return;
+
 	/* Bin size will be 100 ns. */
 	_glWindow.model()->quickZoomIn(100);
 	if (_mState->activeMarker()._isSet &&
@@ -249,6 +252,9 @@ void KsTraceGraph::_quickZoomIn()
 
 void KsTraceGraph::_quickZoomOut()
 {
+	if (_glWindow.isEmpty())
+		return;
+
 	_glWindow.model()->quickZoomOut();
 }
 
@@ -646,6 +652,9 @@ void KsTraceGraph::_updateGraphs(GraphActions action)
 	double k;
 	int bin;
 
+	if (_glWindow.isEmpty())
+		return;
+
 	/*
 	 * Set the "Key Pressed" flag. The flag will stay set as long as the user
 	 * keeps the corresponding action button pressed.
Signature · 1 line
2.20.1