Skip to contentSkip to conversation

kernel-shark :Fix all build warnings for gcc 10.2.1

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 7 messages Sep 16, 2020 – Sep 30, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 kernel-shark :Fix all build warnings for gcc 10.2.1

Tested on Fedora 32:
gcc (GCC) 10.2.1 20200723 (Red Hat 10.2.1-1)

---
 kernel-shark/src/KsAdvFilteringDialog.cpp |  6 +++---
 kernel-shark/src/KsCaptureDialog.cpp      |  2 +-
 kernel-shark/src/KsTraceGraph.cpp         | 23 ++++++++---------------
 kernel-shark/src/KsTraceGraph.hpp         |  4 ++++
 kernel-shark/src/KsUtils.cpp              |  4 ++--
 kernel-shark/src/KsUtils.hpp              |  6 +++---
 kernel-shark/src/KsWidgetsLib.cpp         |  6 +++---
 7 files changed, 24 insertions(+), 27 deletions(-)
kernel-shark/src/KsAdvFilteringDialog.cpp +3 -3
index 6af1aea..8dc53bb 100644
@@ -170,7 +170,7 @@ void KsAdvFilteringDialog::_setSystemCombo(struct kshark_context *kshark_ctx)
 		}
 	}
 
-	qSort(sysList);
+	std::sort(sysList.begin(), sysList.end());
 	_systemComboBox.addItems(sysList);
 
 	i = _systemComboBox.findText("ftrace");
@@ -291,7 +291,7 @@ void KsAdvFilteringDialog::_systemChanged(const QString &sysName)
 			evtsList << events[i]->name;
 	}
 
-	qSort(evtsList);
+	std::sort(evtsList.begin(), evtsList.end());
 	_eventComboBox.addItems(evtsList);
 
 	i = _eventComboBox.findText("function");
@@ -310,7 +310,7 @@ KsAdvFilteringDialog::_getEventFormatFields(struct tep_event *event)
 
 	free(fields);
 
-	qSort(fieldList);
+	std::sort(fieldList.begin(), fieldList.end());
 	return fieldList;
 }
 
kernel-shark/src/KsCaptureDialog.cpp +1 -1
index d6f8014..63fd5d6 100644
@@ -219,7 +219,7 @@ QStringList KsCaptureControl::_getPlugins()
 	}
 
 	free (all_plugins);
-	qSort(pluginList);
+	std::sort(pluginList.begin(), pluginList.end());
 
 	return pluginList;
 }
kernel-shark/src/KsTraceGraph.cpp +8 -15
index 90f83f3..f21fcfc 100644
@@ -282,11 +282,9 @@ void KsTraceGraph::_stopUpdating()
 void KsTraceGraph::_resetPointer(uint64_t ts, int cpu, int pid)
 {
 	uint64_t sec, usec;
-	QString pointer;
 
 	kshark_convert_nano(ts, &sec, &usec);
-	pointer.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelP2.setText(pointer);
+	_labelP2.setText(_t2str(sec, usec));
 
 	if (pid > 0 && cpu >= 0) {
 		struct kshark_context *kshark_ctx(NULL);
@@ -316,13 +314,12 @@ void KsTraceGraph::_setPointerInfo(size_t i)
 	QString lat(kshark_get_latency_easy(e));
 	QString info(kshark_get_info_easy(e));
 	QString comm(kshark_get_task_easy(e));
-	QString pointer, elidedText;
 	int labelWidth, width;
+	QString elidedText;
 	uint64_t sec, usec;
 
 	kshark_convert_nano(e->ts, &sec, &usec);
-	pointer.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelP2.setText(pointer);
+	_labelP2.setText(_t2str(sec, usec));
 
 	comm.append("-");
 	comm.append(QString("%1").arg(kshark_get_pid_easy(e)));
@@ -445,7 +442,7 @@ void KsTraceGraph::addCPUPlot(int cpu)
 		return;
 
 	_glWindow._cpuList.append(cpu);
-	qSort(_glWindow._cpuList);
+	std::sort(_glWindow._cpuList.begin(), _glWindow._cpuList.end());
 	_selfUpdate();
 }
 
@@ -456,7 +453,7 @@ void KsTraceGraph::addTaskPlot(int pid)
 		return;
 
 	_glWindow._taskList.append(pid);
-	qSort(_glWindow._taskList);
+	std::sort(_glWindow._taskList.begin(), _glWindow._taskList.end());
 	_selfUpdate();
 }
 
@@ -606,21 +603,17 @@ void KsTraceGraph::_updateGraphLegends()
 void KsTraceGraph::_updateTimeLegends()
 {
 	uint64_t sec, usec, tsMid;
-	QString tMin, tMid, tMax;
 
 	kshark_convert_nano(_glWindow.model()->histo()->min, &sec, &usec);
-	tMin.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMin.setText(tMin);
+	_labelXMin.setText(_t2str(sec, usec));
 
 	tsMid = (_glWindow.model()->histo()->min +
 		 _glWindow.model()->histo()->max) / 2;
 	kshark_convert_nano(tsMid, &sec, &usec);
-	tMid.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMid.setText(tMid);
+	_labelXMid.setText(_t2str(sec, usec));
 
 	kshark_convert_nano(_glWindow.model()->histo()->max, &sec, &usec);
-	tMax.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMax.setText(tMax);
+	_labelXMax.setText(_t2str(sec, usec));
 }
 
 /**
kernel-shark/src/KsTraceGraph.hpp +4 -0
index c53258c..8abc06b 100644
@@ -108,6 +108,10 @@ private:
 
 	void _markerReDraw();
 
+	QString _t2str(uint64_t sec, uint64_t usec) {
+		return QString::number(sec) + "." + QString::number(usec);
+	};
+
 	enum class GraphActions {
 		ZoomIn,
 		ZoomOut,
kernel-shark/src/KsUtils.cpp +2 -2
index 8c61b3f..24f7178 100644
@@ -48,7 +48,7 @@ QVector<int> getPidList()
 
 	free(tempPids);
 
-	qSort(pids);
+	std::sort(pids.begin(), pids.end());
 
 	return pids;
 }
@@ -90,7 +90,7 @@ QVector<int> getFilterIds(tracecmd_filter_id *filter)
 	for (int i = 0; i < n; ++i)
 		v.append(cpuFilter[i]);
 
-	qSort(v);
+	std::sort(v.begin(), v.end());
 
 	free(cpuFilter);
 	return v;
kernel-shark/src/KsUtils.hpp +3 -3
index 9adacd8..2772b84 100644
@@ -25,10 +25,10 @@
 #include "KsPlotTools.hpp"
 
 /** Macro providing the height of the screen in pixels. */
-#define SCREEN_HEIGHT  QApplication::desktop()->screenGeometry().height()
+#define SCREEN_HEIGHT  QGuiApplication::screens()[0]->geometry().height()
 
 /** Macro providing the width of the screen in pixels. */
-#define SCREEN_WIDTH   QApplication::desktop()->screenGeometry().width()
+#define SCREEN_WIDTH   QGuiApplication::screens()[0]->geometry().width()
 
 //! @cond Doxygen_Suppress
 
@@ -45,7 +45,7 @@ static auto stringWidth = [](QString s)
 	QFont font;
 	QFontMetrics fm(font);
 
-	return fm.width(s);
+	return fm.horizontalAdvance(s);
 };
 
 //! @endcond
kernel-shark/src/KsWidgetsLib.cpp +3 -3
index 330230e..a84aff3 100644
@@ -642,7 +642,7 @@ KsCPUCheckBoxWidget::KsCPUCheckBoxWidget(struct tep_handle *tep,
 		cpuItem->setText(0, "  ");
 		cpuItem->setText(1, QString("CPU %1").arg(i));
 		cpuItem->setCheckState(0, Qt::Checked);
-		cpuItem->setBackgroundColor(0, QColor(colors[i].r(),
+		cpuItem->setBackground(0, QColor(colors[i].r(),
 						      colors[i].g(),
 						      colors[i].b()));
 		_tree.addTopLevelItem(cpuItem);
@@ -799,12 +799,12 @@ KsTasksCheckBoxWidget::KsTasksCheckBoxWidget(struct tep_handle *pevent,
 		comm = tep_data_comm_from_pid(kshark_ctx->pevent, pid);
 		comItem = new QTableWidgetItem(tr(comm));
 
-		pidItem->setBackgroundColor(QColor(colors[pid].r(),
+		pidItem->setBackground(QColor(colors[pid].r(),
 						   colors[pid].g(),
 						   colors[pid].b()));
 
 		if (_id[i] == 0)
-			pidItem->setTextColor(Qt::white);
+			pidItem->setForeground(Qt::white);
 
 		_table.setItem(i, 2, comItem);
 	}
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/4 kernel-shark: Have correct screen geometry on high-resolution screens

A scale factor (also called "Device Pixel Ratio") is often applied in the display settings when running on laptops having high-resolution screens. Take this scale factor into consideration when calculating the screen size.

Note that the size of some widget is set to be a fractions of the total size of the screen.

---
 kernel-shark/src/KsUtils.hpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.hpp +10 -2
index 2772b84..a07af1a 100644
@@ -25,10 +25,18 @@
 #include "KsPlotTools.hpp"
 
 /** Macro providing the height of the screen in pixels. */
-#define SCREEN_HEIGHT  QGuiApplication::screens()[0]->geometry().height()
+#define SCREEN_HEIGHT \
+	( \
+	QGuiApplication::screens()[0]->geometry().height() / \
+	QApplication::desktop()->devicePixelRatio() \
+	)
 
 /** Macro providing the width of the screen in pixels. */
-#define SCREEN_WIDTH   QGuiApplication::screens()[0]->geometry().width()
+#define SCREEN_WIDTH \
+	( \
+	QGuiApplication::screens()[0]->geometry().width() / \
+	QApplication::desktop()->devicePixelRatio() \
+	)
 
 //! @cond Doxygen_Suppress
 
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/4 kernel-shark: Check if Qt has been found when building the examples

In reply to Yordan Karadzhov (VMware)

Some of the examples depend on Qt. Check if Qt exists befor trying to build these examples.

---
 kernel-shark/examples/CMakeLists.txt | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
kernel-shark/examples/CMakeLists.txt +10 -6
index 35e6b1e..032f305 100644
@@ -20,10 +20,14 @@ message(STATUS "dataplot")
 add_executable(dplot          dataplot.cpp)
 target_link_libraries(dplot   kshark-plot)
 
-message(STATUS "widgetdemo")
-add_executable(widgetdemo          widgetdemo.cpp)
-target_link_libraries(widgetdemo   kshark-gui)
+if (Qt5Widgets_FOUND)
 
-message(STATUS "cmd_split")
-add_executable(cmd_split           cmd_split.cpp)
-target_link_libraries(cmd_split    kshark-gui)
+    message(STATUS "widgetdemo")
+    add_executable(widgetdemo          widgetdemo.cpp)
+    target_link_libraries(widgetdemo   kshark-gui)
+
+    message(STATUS "cmd_split")
+    add_executable(cmd_split           cmd_split.cpp)
+    target_link_libraries(cmd_split    kshark-gui)
+
+endif (Qt5Widgets_FOUND)
Signature · 1 line
2.26.2
#3 lore raw

PATCH 4/4 kernel-shark: Fix dependency (symbol resolving) issue

In reply to Yordan Karadzhov (VMware)

When linking KernelShark libraries we must take into account the intrinsic dependency hierarchy of the trace-cmd libraries. "libtraceevent" is the most basic one. "libtracefs" depends on "libtraceevent" and "libtracecmd" depends on both "libtraceevent" and "libtracefs". In order to guarantee a correct symbol resolution during linking, those libraries must be listed in a reverse order (the most basic comes last).

---
 kernel-shark/src/CMakeLists.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel-shark/src/CMakeLists.txt +3 -3
index 9666b18..0627783 100644
@@ -7,10 +7,10 @@ add_library(kshark SHARED libkshark.c
                           libkshark-configio.c
                           libkshark-collection.c)
 
-target_link_libraries(kshark ${TRACEEVENT_LIBRARY}
-                             ${TRACECMD_LIBRARY}
+target_link_libraries(kshark ${TRACECMD_LIBRARY}
                              ${TRACEFS_LIBRARY}
-                             ${JSONC_LIBRARY}
+                             ${TRACEEVENT_LIBRARY}
+			     ${JSONC_LIBRARY}
                              ${CMAKE_DL_LIBS})
 
 set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
Signature · 1 line
2.26.2
#4 lore raw
In reply to Yordan Karadzhov (VMware)
Quoted 30 lines · On Wed, 16 Sep 2020 09:50:04 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark/src/KsTraceGraph.cpp +3 -7
@@ -606,21 +603,17 @@ void KsTraceGraph::_updateGraphLegends()
 void KsTraceGraph::_updateTimeLegends()
 {
 	uint64_t sec, usec, tsMid;
-	QString tMin, tMid, tMax;
 
 	kshark_convert_nano(_glWindow.model()->histo()->min, &sec, &usec);
-	tMin.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMin.setText(tMin);
+	_labelXMin.setText(_t2str(sec, usec));
 
 	tsMid = (_glWindow.model()->histo()->min +
 		 _glWindow.model()->histo()->max) / 2;
 	kshark_convert_nano(tsMid, &sec, &usec);
-	tMid.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMid.setText(tMid);
+	_labelXMid.setText(_t2str(sec, usec));
 
 	kshark_convert_nano(_glWindow.model()->histo()->max, &sec, &usec);
-	tMax.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMax.setText(tMax);
+	_labelXMax.setText(_t2str(sec, usec));
 }
 
 /**
kernel-shark/src/KsTraceGraph.hpp +0 -0
index c53258c..8abc06b 100644

kernel-shark/src/KsTraceGraph.hpp private: · line 112

Quoted 5 lines
kernel-shark/src/KsTraceGraph.hpp +2 -0
@@ -108,6 +108,10 @@ private:
 
 	void _markerReDraw();
 
+	QString _t2str(uint64_t sec, uint64_t usec) {
+		return QString::number(sec) + "." + QString::number(usec);

Hmm, if sec is 5 and usec is 1, would the above work? That is, would it give:

	"5.000001"

Or would it give:

	"5.1"

which would be wrong.

-- Steve

Quoted 5 lines
kernel-shark/src/KsTraceGraph.hpp +2 -0
+	};
+
 	enum class GraphActions {
 		ZoomIn,
 		ZoomOut,
#5 lore raw
Quoted 42 lines · Steven Rostedt
Quoted 30 lines · On Wed, 16 Sep 2020 09:50:04 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark/src/KsTraceGraph.cpp +3 -7
@@ -606,21 +603,17 @@ void KsTraceGraph::_updateGraphLegends()
  void KsTraceGraph::_updateTimeLegends()
  {
  	uint64_t sec, usec, tsMid;
-	QString tMin, tMid, tMax;
 
  	kshark_convert_nano(_glWindow.model()->histo()->min, &sec, &usec);
-	tMin.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMin.setText(tMin);
+	_labelXMin.setText(_t2str(sec, usec));
 
  	tsMid = (_glWindow.model()->histo()->min +
  		 _glWindow.model()->histo()->max) / 2;
  	kshark_convert_nano(tsMid, &sec, &usec);
-	tMid.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMid.setText(tMid);
+	_labelXMid.setText(_t2str(sec, usec));
 
  	kshark_convert_nano(_glWindow.model()->histo()->max, &sec, &usec);
-	tMax.sprintf("%" PRIu64 ".%06" PRIu64 "", sec, usec);
-	_labelXMax.setText(tMax);
+	_labelXMax.setText(_t2str(sec, usec));
  }
 
  /**
kernel-shark/src/KsTraceGraph.hpp +0 -0
index c53258c..8abc06b 100644

kernel-shark/src/KsTraceGraph.hpp private: · line 112

Quoted 5 lines
kernel-shark/src/KsTraceGraph.hpp +2 -0
@@ -108,6 +108,10 @@ private:
 
  	void _markerReDraw();
 
+	QString _t2str(uint64_t sec, uint64_t usec) {
+		return QString::number(sec) + "." + QString::number(usec);

Hmm, if sec is 5 and usec is 1, would the above work? That is, would it give:

Quoted 8 lines
	"5.000001"

Or would it give:

	"5.1"

which would be wrong.

Yes, this is wrong. Thanks a lot Steven!
Do you prefer to re-send the entire patch-set or only this one?

thanks,
Yordan

Quoted 7 lines

-- Steve

Quoted 5 lines
kernel-shark/src/KsTraceGraph.hpp +2 -0
+	};
+
  	enum class GraphActions {
  		ZoomIn,
  		ZoomOut,
#6 lore raw
Quoted 2 lines · On Wed, 30 Sep 2020 16:55:45 +0300 "Yordan Karadzhov (VMware)"…

Yes, this is wrong. Thanks a lot Steven!
Do you prefer to re-send the entire patch-set or only this one?

Resend the entire set. It makes patchwork happier ;-)

-- Steve