Skip to contentSkip to conversation

kernel-shark: Improve the build system

PATCH In review Yordan Karadzhov (VMware) 2 participants 8 messages Jan 5, 2021 – Jan 6, 2021

lore
Share & tools
lore
#0 lore raw

cover kernel-shark: Improve the build system

All changes and fixes from v8 of the "Start KernelShark v2 transformation" patch-set that did not managed to go upstream.

Yordan Karadzhov (1):
kernel-shark: Fix "github Actions" workflow

Yordan Karadzhov (VMware) (4):
kernel-shark: Start using libtracecmd
kernel-shark: Add missing SPDX license identifiers
kernel-shark: Change default libraries install location
kernel-shark: Split the installation in two components

 .github/workflows/main.yml       |   2 +
 CMakeLists.txt                   |  30 ++++++---
 build/FindTraceCmd.cmake         | 101 ++++++++++++++++++-------------
 build/FindTraceEvent.cmake       |   1 +
 build/FindTraceFS.cmake          |   1 +
 build/cmake_uninstall.sh         |  23 +++++--
 build/install_gui.sh             |   1 +
 build/install_libkshark-devel.sh |   1 +
 src/CMakeLists.txt               |  55 +++++++++++++----
 src/libkshark-tepdata.c          |  18 +++---
 src/plugins/CMakeLists.txt       |   3 +-
 11 files changed, 161 insertions(+), 75 deletions(-)
 create mode 100755 build/install_gui.sh
 create mode 100755 build/install_libkshark-devel.sh
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/5 kernel-shark: Start using libtracecmd

libtracecmd is now a stand-alone libraries, similar to libtraceevent and libtracefs. Start building and linking KernelShark against this independent library.

---
 CMakeLists.txt             |   4 +-
 build/FindTraceCmd.cmake   | 101 ++++++++++++++++++++++---------------
 build/FindTraceEvent.cmake |   1 -
 build/FindTraceFS.cmake    |   1 -
 src/CMakeLists.txt         |   2 +-
 src/libkshark-tepdata.c    |  18 +++----
 6 files changed, 72 insertions(+), 55 deletions(-)
CMakeLists.txt +2 -2
index 303e47e..59bbe72 100644
@@ -21,11 +21,11 @@ if (NOT _LIBDIR)
     set(_LIBDIR "${_INSTALL_PREFIX}/lib")
 endif (NOT _LIBDIR)
 
-include(${KS_DIR}/build/FindTraceCmd.cmake)
-
 set(CMAKE_MODULE_PATH "${KS_DIR}/build")
 find_package(TraceEvent REQUIRED)
 find_package(TraceFS    REQUIRED)
+find_package(TraceCmd   REQUIRED)
+
 find_package(JSONC      REQUIRED)
 
 find_package(Doxygen)
build/FindTraceCmd.cmake +60 -41

119 lines not on this page · raw message

build/FindTraceEvent.cmake +0 -1
index 8525697..f3feca9 100644
@@ -1,4 +1,3 @@
-
 #[=======================================================================[.rst:
 FindTraceevent
 -------
build/FindTraceFS.cmake +0 -1
index 982a61d..2a5f7bd 100644
@@ -1,4 +1,3 @@
-
 #[=======================================================================[.rst:
 FindTraceFS
 -------
src/CMakeLists.txt +1 -1
index 285f88a..b393468 100644
@@ -9,7 +9,7 @@ add_library(kshark SHARED libkshark.c
                           libkshark-configio.c
                           libkshark-collection.c)
 
-target_link_libraries(kshark ${TRACECMD_LIBRARY}
+target_link_libraries(kshark trace::cmd
                              trace::fs
                              trace::event
                              jsonc::jsonc
src/libkshark-tepdata.c +9 -9
index a82f5c5..724cff2 100644
@@ -277,7 +277,7 @@ static void free_rec_list(struct rec_list **rec_list, int n_cpus,
 			temp_rec = rec_list[cpu];
 			rec_list[cpu] = temp_rec->next;
 			if (type == REC_RECORD)
-				free_record(temp_rec->rec);
+				tracecmd_free_record(temp_rec->rec);
 			free(temp_rec);
 		}
 	}
@@ -379,7 +379,7 @@ static ssize_t get_records(struct kshark_context *kshark_ctx,
 				    tep_filter_match(adv_filter, rec) != FILTER_MATCH)
 					unset_event_filter_flag(kshark_ctx, entry);
 
-				free_record(rec);
+				tracecmd_free_record(rec);
 				break;
 			} /* REC_ENTRY */
 			}
@@ -571,7 +571,7 @@ static ssize_t tepdata_load_matrix(struct kshark_data_stream *stream,
  *
  * @param kshark_ctx: Input location for the session context pointer.
  * @param sd: Data stream identifier.
- * @param data_rows: Output location for the trace data. Use free_record()
+ * @param data_rows: Output location for the trace data. Use tracecmd_free_record()
  *	 	     to free the elements of the outputted array.
  *
  * @returns The size of the outputted data in the case of success, or a
@@ -657,7 +657,7 @@ static const int tepdata_get_event_id(struct kshark_data_stream *stream,
 		if (record)
 			event_id = tep_data_type(kshark_get_tep(stream), record);
 
-		free_record(record);
+		tracecmd_free_record(record);
 
 		pthread_mutex_unlock(&stream->input_mutex);
 	}
@@ -749,7 +749,7 @@ static const int tepdata_get_pid(struct kshark_data_stream *stream,
 		if (record)
 			pid = tep_data_pid(kshark_get_tep(stream), record);
 
-		free_record(record);
+		tracecmd_free_record(record);
 
 		pthread_mutex_unlock(&stream->input_mutex);
 	}
@@ -798,7 +798,7 @@ static char *tepdata_get_latency(struct kshark_data_stream *stream,
 	tep_print_event(kshark_get_tep(stream), &seq, record,
 			"%s", TEP_PRINT_LATENCY);
 
-	free_record(record);
+	tracecmd_free_record(record);
 
 	pthread_mutex_unlock(&stream->input_mutex);
 
@@ -869,7 +869,7 @@ static char *tepdata_get_info(struct kshark_data_stream *stream,
 	if (event)
 		info = get_info_str(stream, record, event);
 
-	free_record(record);
+	tracecmd_free_record(record);
 
 	pthread_mutex_unlock(&stream->input_mutex);
 
@@ -1178,7 +1178,7 @@ int tepdata_read_event_field(struct kshark_data_stream *stream,
 
 	ret = tep_read_number_field(evt_field, record->data,
 				    (unsigned long long *) val);
-	free_record(record);
+	tracecmd_free_record(record);
 
 	return ret;
 }
@@ -1308,7 +1308,7 @@ static int kshark_tep_stream_init(struct kshark_data_stream *stream,
 		goto fail;
 
 	tep_handle->input = input;
-	tep_handle->tep = tracecmd_get_pevent(tep_handle->input);
+	tep_handle->tep = tracecmd_get_tep(tep_handle->input);
 	if (!tep_handle->tep)
 		goto fail;
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/5 kernel-shark: Add missing SPDX license identifiers

In reply to Yordan Karadzhov (VMware)
---
 build/FindTraceEvent.cmake | 2 ++
 build/FindTraceFS.cmake    | 2 ++
 2 files changed, 4 insertions(+)
build/FindTraceEvent.cmake +2 -0
index f3feca9..ae391b6 100644
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1
+
 #[=======================================================================[.rst:
 FindTraceevent
 -------
build/FindTraceFS.cmake +2 -0
index 2a5f7bd..82fa012 100644
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1
+
 #[=======================================================================[.rst:
 FindTraceFS
 -------
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/5 kernel-shark: Change default libraries install location

In reply to Yordan Karadzhov (VMware)

The default installation path for the KernelShark libraries changes from /usr/local/lib/kernelshark/ to /usr/local/lib64 (or /usr/local/lib on 32 but systems). This is done in order to be consistent with the install locations of libtraceevent, libtracefs and libtracecmd.

---
 CMakeLists.txt     | 28 ++++++++++++++++++++++------
 src/CMakeLists.txt |  6 +++---
 2 files changed, 25 insertions(+), 9 deletions(-)
CMakeLists.txt +22 -6
index 59bbe72..543d7da 100644
@@ -13,13 +13,28 @@ message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n")
 
 set(KS_DIR ${CMAKE_SOURCE_DIR})
 
-if (NOT _INSTALL_PREFIX)
+execute_process(COMMAND bash "-c" "echo __LP64__ | ${CMAKE_C_COMPILER} -E -x c - | tail -n 1"
+                OUTPUT_VARIABLE __LP64__)
+
+if (NOT _INSTALL_PREFIX AND NOT _LIBDIR)
+
     set(_INSTALL_PREFIX "/usr/local")
-endif (NOT _INSTALL_PREFIX)
 
-if (NOT _LIBDIR)
-    set(_LIBDIR "${_INSTALL_PREFIX}/lib")
-endif (NOT _LIBDIR)
+    if (__LP64__ MATCHES 1)
+        set(_LIBDIR "/usr/local/lib64")
+    else (__LP64__ MATCHES 1)
+        set(_LIBDIR "/usr/local/lib")
+    endif (__LP64__ MATCHES 1)
+
+elseif (NOT _INSTALL_PREFIX)
+
+    set(_INSTALL_PREFIX "/usr/local")
+
+elseif (NOT _LIBDIR)
+
+   set(_LIBDIR "${_INSTALL_PREFIX}/lib")
+
+endif ()
 
 set(CMAKE_MODULE_PATH "${KS_DIR}/build")
 find_package(TraceEvent REQUIRED)
@@ -71,7 +86,8 @@ set(KS_ICON_FIN    KS_icon_fin.svg)
 set(KS_LOGO        KS_logo_symbol.svg)
 set(KS_LOGO_LABEL  KS_logo_horizontal.svg)
 
-set(CMAKE_INSTALL_RPATH "${_LIBDIR}/${KS_APP_NAME}/")
+set(CMAKE_INSTALL_RPATH "${_LIBDIR}")
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
 if (CMAKE_BUILD_TYPE MATCHES Package)
 
src/CMakeLists.txt +3 -3
index b393468..fe3a3eb 100644
@@ -17,7 +17,7 @@ target_link_libraries(kshark trace::cmd
 
 set_target_properties(kshark  PROPERTIES SUFFIX	".so.${KS_VERSION_STRING}")
 
-install(TARGETS kshark LIBRARY DESTINATION ${_LIBDIR}/${KS_APP_NAME})
+install(TARGETS kshark LIBRARY DESTINATION ${_LIBDIR})
 
 if (OPENGL_FOUND)
 
@@ -31,7 +31,7 @@ if (OPENGL_FOUND)
 
     set_target_properties(kshark-plot PROPERTIES  SUFFIX ".so.${KS_VERSION_STRING}")
 
-    install(TARGETS kshark-plot LIBRARY DESTINATION ${_LIBDIR}/${KS_APP_NAME})
+    install(TARGETS kshark-plot LIBRARY DESTINATION ${_LIBDIR})
 
 endif (OPENGL_FOUND)
 
@@ -84,7 +84,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
 
     install(TARGETS ${KS_APP_NAME} kshark-record kshark-gui
             RUNTIME DESTINATION ${_INSTALL_PREFIX}/bin/
-            LIBRARY DESTINATION ${_LIBDIR}/${KS_APP_NAME}/)
+            LIBRARY DESTINATION ${_LIBDIR})
 
     install(FILES "${KS_DIR}/${KS_APP_NAME}.desktop"
             DESTINATION ${_INSTALL_PREFIX}/share/applications/)
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/5 kernel-shark: Split the installation in two components

In reply to Yordan Karadzhov (VMware)

The user can choose to install only the KernelShark GUI via "install_gui.sh". It is also possible to install the library headers and this can be done via "install_libkshark-devel.sh".

The changes implemented in this patch are inspired by the talk "Deep CMake For Library Authors" presented at CppCon 2019 by Craig Scott.
https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/

---
 CMakeLists.txt                   |  2 +-
 build/cmake_uninstall.sh         | 23 ++++++++++----
 build/install_gui.sh             |  1 +
 build/install_libkshark-devel.sh |  1 +
 src/CMakeLists.txt               | 53 ++++++++++++++++++++++++++------
 src/plugins/CMakeLists.txt       |  3 +-
 6 files changed, 65 insertions(+), 18 deletions(-)
 create mode 100755 build/install_gui.sh
 create mode 100755 build/install_libkshark-devel.sh
CMakeLists.txt +1 -1
index 543d7da..9abacd0 100644
@@ -86,7 +86,7 @@ set(KS_ICON_FIN    KS_icon_fin.svg)
 set(KS_LOGO        KS_logo_symbol.svg)
 set(KS_LOGO_LABEL  KS_logo_horizontal.svg)
 
-set(CMAKE_INSTALL_RPATH "${_LIBDIR}")
+set(CMAKE_INSTALL_RPATH "${_LIBDIR}" "$ORIGIN")
 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
 if (CMAKE_BUILD_TYPE MATCHES Package)
build/cmake_uninstall.sh +17 -6
index ae9eab5..0d93a8d 100755
@@ -4,14 +4,25 @@ CYAN='\e[36m'
 PURPLE='\e[35m'
 NC='\e[0m' # No Color
 
+uninstall () {
+    NAME=$1
+    NAME=${NAME##*_}
+    NAME=${NAME%.*}
+    NAME=${NAME/manifest/the project}
+    if [ -e $1 ]
+    then
+        echo -e "${CYAN}Uninstall " $NAME"...${NC}"
+        xargs rm -v < $1
+        rm -f $1
+    fi
+}
+
 if [[ $EUID -ne 0 ]]; then
    echo -e "${PURPLE}Permission denied${NC}" 1>&2
    exit 100
 fi
 
-if [ -e install_manifest.txt ]
-then
-    echo -e "${CYAN}Uninstall the project...${NC}"
-    xargs rm -v < install_manifest.txt
-    rm -f install_manifest.txt
-fi
+for manifest in "$search_dir"${PWD}/install_manifest*
+do
+   uninstall $manifest
+done
build/install_gui.sh new file +1 -0
new file mode 100755
index 0000000..1583fb9
@@ -0,0 +1 @@
+sudo cmake -DCOMPONENT=kernelshark -P cmake_install.cmake
build/install_libkshark-devel.sh new file +1 -0
new file mode 100755
index 0000000..a7e420d
@@ -0,0 +1 @@
+sudo cmake -DCOMPONENT=libkshark-devel -P cmake_install.cmake
src/CMakeLists.txt +43 -10

87 lines not on this page · raw message

src/plugins/CMakeLists.txt +2 -1
index 6c77179..2da73f8 100644
@@ -28,6 +28,7 @@ BUILD_PLUGIN(NAME missed_events
 list(APPEND PLUGIN_LIST "missed_events default") # This plugin will be loaded by default
 
 install(TARGETS sched_events missed_events
-        LIBRARY DESTINATION ${KS_PLUGIN_INSTALL_PREFIX})
+        LIBRARY DESTINATION ${KS_PLUGIN_INSTALL_PREFIX}
+        COMPONENT kernelshark)
 
 set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH 4/5] kernel-shark: Split the installation in two components

Quoted 8 lines · On Tue, 5 Jan 2021 17:54:52 +0200 "Yordan Karadzhov (VMware)"…

The user can choose to install only the KernelShark GUI via "install_gui.sh". It is also possible to install the library headers and this can be done via "install_libkshark-devel.sh".

The changes implemented in this patch are inspired by the talk "Deep CMake For Library Authors" presented at CppCon 2019 by Craig Scott.
https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/

I applied the series. But is there a way to install in a specific directory and not in the system directories? (I didn't watch the talk).

For example, I can do:

 $ mkdir /tmp/install
 $ make DESTDIR=/tmp/install/ install

for libtraceveent, libtracefs and trace-cmd / libtracecmd and it will install into /tmp/install/... just like it would have installed in /. The big difference is, I don't need to be root to run that command.

Then what I can do is:

 $ cd /tmp/install
 $ tar -cvjf ../package.tar.bz2 .
 $ scp ../package.tar.bz2 root@somebox:/tmp
 $ ssh root@somebox
 # cd /
 # tar -xvjf /tmp/package.tar.bz2

And that would have installed the package on to the machine "somebox".

-- Steve

#6 lore raw

Re: [PATCH 4/5] kernel-shark: Split the installation in two components

Hi Steven,

Quoted 15 lines · Steven Rostedt
Quoted 8 lines · On Tue, 5 Jan 2021 17:54:52 +0200 "Yordan Karadzhov (VMware)"…

The user can choose to install only the KernelShark GUI via "install_gui.sh". It is also possible to install the library headers and this can be done via "install_libkshark-devel.sh".

The changes implemented in this patch are inspired by the talk "Deep CMake For Library Authors" presented at CppCon 2019 by Craig Scott.
https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/

I applied the series. But is there a way to install in a specific directory and not in the system directories? (I didn't watch the talk).

Quoted 9 lines

For example, I can do:

  $ mkdir /tmp/install
  $ make DESTDIR=/tmp/install/ install

for libtraceveent, libtracefs and trace-cmd / libtracecmd and it will install into /tmp/install/... just like it would have installed in /. The big difference is, I don't need to be root to run that command.

Yes, we have a similar functionality since the very beginning of KS 1.0 and it is not been changed here. You can specify the install destination using a cmake command line argument like this:

cmake -D_INSTALL_PREFIX=/tmp/install/ ..

All this is documented in the README file. The only difference is that in your case you provide the destination at the very end when you do "make install", while here it has to be done at the very beginning when you call cmake.

Note that the two new helper scripts (install_gui.sh and install_libkshark-devel.sh) can be used instead of "sudo make install" but this is needed only if you want to split the installation. A normal "make install" will just install everything.

However, you are right that it is probably better if we remove the sudo from the two helper scripts.

Thanks!
Yordan

Quoted 13 lines

Then what I can do is:

  $ cd /tmp/install
  $ tar -cvjf ../package.tar.bz2 .
  $ scp ../package.tar.bz2 root@somebox:/tmp
  $ ssh root@somebox
  # cd /
  # tar -xvjf /tmp/package.tar.bz2

And that would have installed the package on to the machine "somebox".

-- Steve

#7 lore raw

PATCH 5/5 kernel-shark: Fix "github Actions" workflow

In reply to Yordan Karadzhov (VMware)

Fix the part of the script that installs the third party libraries.

---
 .github/workflows/main.yml | 2 ++
 1 file changed, 2 insertions(+)
.github/workflows/main.yml +2 -0
index e818f46..a35f003 100644
@@ -16,6 +16,7 @@ jobs:
     - name: Install Dependencies
       shell: bash
       run: |
+        sudo apt-get update
         sudo apt-get install build-essential git cmake libjson-c-dev -y
         sudo apt-get install freeglut3-dev libxmu-dev libxi-dev -y
         sudo apt-get install qtbase5-dev libboost-all-dev -y
@@ -32,6 +33,7 @@ jobs:
         git clone git://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git
         cd trace-cmd
         make
+        sudo make install
         sudo make install_libs
     - name: Create Build Environment
       # Some projects don't allow in-source building, so create a separate build directory
Signature · 1 line
2.25.1