Skip to contentSkip to conversation

Add drawing instrumentation to be used by the Qt-based KernelShark

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 9 messages Aug 24, 2018 – Aug 25, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add drawing instrumentation to be used by the Qt-based KernelShark

The KernelShark plotting library is introduced in this series of patches. The library will be used by the GUI to draw CPU and Task Graphs. This is also the first time KernelShark enters the world of C++.

This is the second version of this series of patches. The major change from v1 is the modified inheritance tree of the classes in KsPlotTools.

Yordan Karadzhov (VMware) (4):
kernel-shark-qt: Add OpenGL/GLUT as a third party dependency.
kernel-shark-qt: Add basic instruments for OpenGL plotting.
kernel-shark-qt: Add C++ API for drawing of Graphs
kernel-shark-qt: Add an example showing how to draw shapes and Graphs.

 kernel-shark-qt/CMakeLists.txt          |    3 +
 kernel-shark-qt/README                  |    2 +
 kernel-shark-qt/examples/CMakeLists.txt |    4 +
 kernel-shark-qt/examples/dataplot.cpp   |  217 +++++
 kernel-shark-qt/src/CMakeLists.txt      |   14 +
 kernel-shark-qt/src/KsPlotTools.cpp     | 1127 +++++++++++++++++++++++
 kernel-shark-qt/src/KsPlotTools.hpp     |  465 ++++++++++
 kernel-shark-qt/src/libkshark-plot.c    |  212 +++++
 kernel-shark-qt/src/libkshark-plot.h    |   69 ++
 9 files changed, 2113 insertions(+)
 create mode 100644 kernel-shark-qt/examples/dataplot.cpp
 create mode 100644 kernel-shark-qt/src/KsPlotTools.cpp
 create mode 100644 kernel-shark-qt/src/KsPlotTools.hpp
 create mode 100644 kernel-shark-qt/src/libkshark-plot.c
 create mode 100644 kernel-shark-qt/src/libkshark-plot.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/4 kernel-shark-qt: Add OpenGL/GLUT as a third party dependency.

This patch prepares the Cmake build infrastructure for the introduction of a KernelShark Ploting library, baset on OpenGl. The Ploting library will be added in the following patch.

---
 kernel-shark-qt/CMakeLists.txt | 3 +++
 kernel-shark-qt/README         | 2 ++
 2 files changed, 5 insertions(+)
kernel-shark-qt/CMakeLists.txt +3 -0
index 3516caa..0187eb4 100644
@@ -17,6 +17,9 @@ include(${KS_DIR}/build/FindJSONC.cmake)
 
 find_package(Doxygen)
 
+find_package(OpenGL)
+find_package(GLUT)
+
 set(LIBRARY_OUTPUT_PATH    "${KS_DIR}/lib")
 set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
 
kernel-shark-qt/README +2 -0
index e6818fc..f03288c 100644
@@ -7,6 +7,7 @@ Third Party Software:
 The external dependencies:
 1. In order to install the packages on Ubuntu do the following:
     sudo apt-get install build-essential git cmake libjson-c-dev -y
+    sudo apt-get install freeglut3-dev libxmu-dev libxi-dev -y
 
 1.1 I you want to be able to generate Doxygen documentation:
     sudo apt-get install graphviz doxygen-gui -y
@@ -14,6 +15,7 @@ The external dependencies:
 
 2. In order to install the packages on Fedora, as root do the following:
     dnf install gcc gcc-c++ git cmake json-c-devel -y
+    dnf install freeglut-devel redhat-rpm-config -y
 
 2.1 I you want to be able to generate Doxygen documentation:
     dnf install graphviz doxygen -y
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/4 kernel-shark-qt: Add basic instruments for OpenGL plotting.

In reply to Yordan Karadzhov (VMware)

This patch introduces tools for initializing OpenGL and for drawing the three basic geometrical primitives (point, line and polygon) used when plotting KernelShark's graphs.

---
 kernel-shark-qt/src/CMakeLists.txt   |  13 ++
 kernel-shark-qt/src/libkshark-plot.c | 212 +++++++++++++++++++++++++++
 kernel-shark-qt/src/libkshark-plot.h |  69 +++++++++
 3 files changed, 294 insertions(+)
 create mode 100644 kernel-shark-qt/src/libkshark-plot.c
 create mode 100644 kernel-shark-qt/src/libkshark-plot.h
kernel-shark-qt/src/CMakeLists.txt +13 -0
index a762da1..9c74bc0 100644
@@ -13,5 +13,18 @@ target_link_libraries(kshark ${CMAKE_DL_LIBS}
 
 set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
 
+if (OPENGL_FOUND AND GLUT_FOUND)
+
+    message(STATUS "libkshark-plot")
+    add_library(kshark-plot  SHARED  libkshark-plot.c)
+
+    target_link_libraries(kshark-plot  kshark
+                                       ${OPENGL_LIBRARIES}
+                                       ${GLUT_LIBRARY})
+
+    set_target_properties(kshark-plot PROPERTIES  SUFFIX ".so.${KS_VERSION_STRING}")
+
+endif (OPENGL_FOUND AND GLUT_FOUND)
+
 configure_file( ${KS_DIR}/build/deff.h.cmake
                 ${KS_DIR}/src/KsDeff.h)
kernel-shark-qt/src/libkshark-plot.c new file +212 -0

212 lines not on this page · raw message

kernel-shark-qt/src/libkshark-plot.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/4 kernel-shark-qt: Add C++ API for drawing of Graphs

In reply to Yordan Karadzhov (VMware)

This patch extends the KernelShark Plotting library, by adding a C++ API for drawing CPU and Task Graphs.

---
 kernel-shark-qt/src/CMakeLists.txt  |    3 +-
 kernel-shark-qt/src/KsPlotTools.cpp | 1127 +++++++++++++++++++++++++++
 kernel-shark-qt/src/KsPlotTools.hpp |  465 +++++++++++
 3 files changed, 1594 insertions(+), 1 deletion(-)
 create mode 100644 kernel-shark-qt/src/KsPlotTools.cpp
 create mode 100644 kernel-shark-qt/src/KsPlotTools.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -1
index 9c74bc0..ac2847a 100644
@@ -16,7 +16,8 @@ set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
 if (OPENGL_FOUND AND GLUT_FOUND)
 
     message(STATUS "libkshark-plot")
-    add_library(kshark-plot  SHARED  libkshark-plot.c)
+    add_library(kshark-plot  SHARED  libkshark-plot.c
+                                     KsPlotTools.cpp)
 
     target_link_libraries(kshark-plot  kshark
                                        ${OPENGL_LIBRARIES}
kernel-shark-qt/src/KsPlotTools.cpp new file +1127 -0

1,127 lines not on this page · raw message

kernel-shark-qt/src/KsPlotTools.hpp new file +465 -0

465 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 3/4] kernel-shark-qt: Add C++ API for drawing of Graphs

kernel-shark-qt/src/KsPlotTools.cpp line 797

Quoted 2 lines · On Fri, 24 Aug 2018 17:21:15 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark-qt/src/KsPlotTools.cpp new file +2 -0
+	/*
+	 * Check the content of the very firs bin and see if the CPU is

I haven't really looked too much at this patch yet, but this spelling stood out. Seems your 't' key is not working well when typing "first bin". There's several places that have that ;-)

-- Steve

Quoted 16 lines
kernel-shark-qt/src/KsPlotTools.cpp new file +16 -0
+	 * active.
+	 */
+	bin = 0;
+	get_pid(bin);
+	if (pidFront >= 0) {
+		/*
+		 * The CPU is active and this is a regular process.
+		 * Set this bin.
+		 */
+		set_bin(bin);
+	} else {
+		/*
+		 * No data from this CPU in the very firs bin. Use the Lower
+		 * Overflow Bin to retrieve the Process Id (if any). First
+		 * get the Pid back, ignoring the filters.
+		 */
#5 lore raw

Re: [PATCH v2 3/4] kernel-shark-qt: Add C++ API for drawing of Graphs

Quoted 6 lines · Steven Rostedt

kernel-shark-qt/src/KsPlotTools.cpp line 797

Quoted 2 lines
kernel-shark-qt/src/KsPlotTools.cpp new file +2 -0
+	/*
+	 * Check the content of the very firs bin and see if the CPU is

I haven't really looked too much at this patch yet, but this spelling stood out. Seems your 't' key is not working well when typing "first bin". There's several places that have that;-)

I am sorry for this annoying typos. This is happening because my editor is trying to auto-complete the words when I am typing. And it does this based on what I already wrote in the file. So if I misspell a word once next time the editor will suggest the same typo.

Thanks!
Yordan

Quoted 2 lines

-- Steve

#6 lore raw

PATCH v2 4/4 kernel-shark-qt: Add an example showing how to draw shapes and Graphs.

In reply to Yordan Karadzhov (VMware)

This patch introduces a basic example, showing how to initialize OpenGL and how to use the C++ API in order to draw simple shapes or to show animated Graphs.

---
 kernel-shark-qt/examples/CMakeLists.txt |   4 +
 kernel-shark-qt/examples/dataplot.cpp   | 217 ++++++++++++++++++++++++
 2 files changed, 221 insertions(+)
 create mode 100644 kernel-shark-qt/examples/dataplot.cpp
kernel-shark-qt/examples/CMakeLists.txt +4 -0
index a3745fa..0c83293 100644
@@ -15,3 +15,7 @@ target_link_libraries(dhisto   kshark)
 message(STATUS "confogio")
 add_executable(confio          configio.c)
 target_link_libraries(confio   kshark)
+
+message(STATUS "dataplot")
+add_executable(dplot          dataplot.cpp)
+target_link_libraries(dplot   kshark-plot)
kernel-shark-qt/examples/dataplot.cpp new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH v2 4/4] kernel-shark-qt: Add an example showing how to draw shapes and Graphs.

Quoted 14 lines · On Fri, 24 Aug 2018 17:21:16 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark-qt/examples/dataplot.cpp new file +14 -0
+int main(int argc, char **argv)
+{
+	struct kshark_context *kshark_ctx(nullptr);
+	struct kshark_entry **data(nullptr);
+	static char *input_file;
+	bool status, shapes(false);
+	size_t r, n_rows;
+	int c, nBins;
+
+	while ((c = getopt(argc, argv, "si")) != -1) {
+		switch(c) {
+		case 'i':
+			input_file = optarg;
+			break;

kernel-shark-qt/examples/dataplot.cpp line 159

Quoted 10 lines
kernel-shark-qt/examples/dataplot.cpp new file +10 -0
+		case 's':
+			shapes = true;
+
+		default:
+			break;
+		}
+	}
+
+	/* Create a new kshark session. */
+	if (!kshark_instance(&kshark_ctx))

Should make some warning message. I ran this from the build directory like:

../bin/dplot ../../trace.dat

and it did nothing. But if I ran it from the trace-cmd.git repo as

kernel-shark-qt/bin/dplot trace.dat

Then it did something. We need to make it work when called from anywhere with a path to any trace.dat file. And give some kind of message if no parameter is passed in.

Hmm, we should also probably make a separate directory for example programs. Perhaps have a "demo" directory for these?

-- Steve

Quoted 13 lines
kernel-shark-qt/examples/dataplot.cpp new file +13 -0
+		return 1;
+
+	/* Open a trace data file produced by trace-cmd. */
+	if (input_file)
+		status = kshark_open(kshark_ctx, input_file);
+	else
+		status = kshark_open(kshark_ctx, default_file);
+
+	if (!status) {
+		kshark_free(kshark_ctx);
+		return 1;
+	}
+
#8 lore raw

Re: [PATCH v2 4/4] kernel-shark-qt: Add an example showing how to draw shapes and Graphs.

Quoted 9 lines · Steven Rostedt

Should make some warning message. I ran this from the build directory like:

../bin/dplot ../../trace.dat

and it did nothing. But if I ran it from the trace-cmd.git repo as

kernel-shark-qt/bin/dplot trace.dat

You are right, this example is a mess. I will fix the bugs and will add a help message.

Quoted 6 lines

Then it did something. We need to make it work when called from anywhere with a path to any trace.dat file. And give some kind of message if no parameter is passed in.

Hmm, we should also probably make a separate directory for example programs. Perhaps have a "demo" directory for these?

Yes, we can do this. Or maybe we can even move the examples to a different repo and call it "kshark_demos"?

Thanks!
Yordan

Quoted 2 lines

-- Steve