Start KernelShark v2 transformation
Subsystems (2)
v8 cover Start KernelShark v2 transformation
In this patch-set we are starting the introduction of the changes in the C API of libkshark. The goal of this transformation is to turn KernelShark into a general purpose toolkit for analysis of tracing data that is no longer strongly coupled to the Ftrace/trace-cmd data format. At the end of the transformation KernelShark will be able to merge and simultaneously visualize data from different tracers, recorded in different data formats. It will also significantly extend the possibilities for user customization.
This patch-set transforms the way KernelShark processes the raw tracing data. Later, in a consecutive patch-sets we will introduce the changes in the visualization instruments and in the KernelShark GUI itself.
Changes in v8:
* In particular patch 6 splits the installation of the project in two components. This can be used to create two packages. One for the GUI and one "devel" package installing the headers. 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/
* Patches 35-44 has been sent already, but as part of a separated patch-set.
Changes in v7:
* Patches 1-5 are new, but these are only infrastructureal changes that have no functional effects on the API.
- License info is added.
- README is updated.
- KernelShark now builds and links against the stand-alone versions of libtraceevent and libtracefs.
Changes in v6:
* The patches from the "OpenGL wrapper" patch-set (already reviewed by Steven) have been added here (patches 21-24).
* Patches 25-27 are new, but these are only infrastructureal changes that have no functional effects on the API.
Changes in v5:
* Only minor modifications addressing issues pointed out by Steven in his reviews of v4.
Changes in v4:
* The integer data format identifier is replaced with a string value that gets registered by the readout plugin.
* Plus several small modifications addressing the issues pointed out by Steven.
Changes in v3.
This version contains number of small modifications addressing the issues pointed out by Steven in his review. However, it also contains the following major changes:
* The session context (kshark_context) holds a pointer to unspecified data processing interface (void *interface). This will allow to easily introduce new versions of this interface in the future, while keeping the interface that we have now for backward compatibility. The necessary type checking when using the interface made the helper functions wrapping the corresponding methods of the interface relatively complicated, so the implementations have been moved from the header to the source file.
* A more sophisticated management of the Data stream descriptors that can handle the case when Data streams are constantly added and removed has been implemented. The design for this change was suggested by Steven in his review.
Changes in v2:
* Tried to address review comments for "kernel-shark: Introduce libkshark-hash"
* The huge patch "kernel-shark: Integrate the stream definitions with
the C API" in the previous version is now split into 8 smaller patches. The last of these 8 new patches (kernel-shark: Complete the stream integration) is still a bit entangled. I can try to further break this patch in future versions of the patch-set, if this is needed.
Yordan Karadzhov (1):
kernel-shark: Add "github Actions" workflow
Yordan Karadzhov (VMware) (43):
kernel-shark: Adopt trace-cmd API changes
kernel-shark: Use libtraceevent and libtracefs
kernel-shark: Add license information
kernel-shark: Change the CMake minimum version required
kernel-shark: Change default libraries install location
kernel-shark: Split the installation in two components
kernel-shark: Update README
kernel-shark: Define build target for JSONC
kernel-shark: Use only signed types in kshark_entry
kernel-shark: Add stream_id to kshark_entry
kernel-shark: Introduce libkshark-hash
kernel-shark: Introduce Data streams
kernel-shark: Rename static methods in libkshark
kernel-shark: Add basic methods for Data streams
kernel-shark: Housekeeping before implementing stream interface
kernel-shark: Add stream interface for trace-cmd data
kernel-shark: Start introducing KernelShark 2.0
kernel-shark: Start using data streams
kernel-shark: Remove dead code
kernel-shark: Redesign the plugin interface
kernel-shark: Complete the stream integration
kernel-shark: Provide merging of multiple data streams
kernel-shark: Integrate the stream definitions with data model
kernel-shark: Use only signed types for model defs
kernel-shark: Add ksmodel_get_bin()
kernel-shark: Protect ksmodel_set_in_range_bining()
kernel-shark: Add methods for time calibration
kernel-shark: Integrate streams with libkshark-configio
kernel-shark: Add support for drawing text
kernel-shark: Make GLUT optional dependency
kernel-shark: Add ksplot_draw_polyline()
kernel-shark: Optimize ksplot_draw_polygon()
kernel-shark: Add basic infrastructure for testing
kernel-shark: Integrate streams with KsPlotTools
kernel-shark: Add getStreamColorTable()
kernel-shark: Redefine the args of KsPlot::getColor()
kernel-shark: Add TextBox class to KsPlot namespace
kernel-shark: Consistent method naming in KsPlotTools
kernel-shark: Make the label part of the graph
kernel-shark: Remove the hard-coded Idle PID
kernel-shark: Add class Polyline to KsPlot namespace
kernel-shark: Add VirtBridge and VirtGap classes
kernel-shark: Add double click interface to PlotObject
.github/workflows/main.yml | 63 + CMakeLists.txt | 55 +- Documentation/doxygen/dox_config | 1 + LICENSES/GPL-2.0 | 359 +++ LICENSES/LGPL-2.1 | 503 +++ README | 129 +- build/FindJSONC.cmake | 70 +- build/FindTraceCmd.cmake | 138 +- build/FindTraceEvent.cmake | 76 + build/FindTraceFS.cmake | 76 + build/cmake_clean.sh | 4 + build/cmake_uninstall.sh | 23 +- build/deff.h.cmake | 15 +- build/install_gui.sh | 1 + build/install_libkshark-devel.sh | 1 + examples/CMakeLists.txt | 34 +- examples/configio.c | 20 +- examples/datafilter.c | 67 +- examples/datahisto.c | 38 +- examples/dataload.c | 28 +- examples/multibufferload.c | 53 + src/CMakeLists.txt | 70 +- src/KsPlotTools.cpp | 412 ++- src/KsPlotTools.hpp | 199 +- src/libkshark-collection.c | 121 +- src/libkshark-configio.c | 1208 +++++-- src/libkshark-hash.c | 239 ++ src/libkshark-model.c | 154 +- src/libkshark-model.h | 55 +- src/libkshark-plot.c | 317 +- src/libkshark-plot.h | 73 + src/libkshark-plugin.c | 658 +++- src/libkshark-plugin.h | 294 +- src/libkshark-tepdata.c | 1914 ++++++++++++ src/libkshark-tepdata.h | 112 + src/libkshark.c | 2619 +++++++++------- src/libkshark.h | 704 ++++- src/plugins/CMakeLists.txt | 3 +- src/plugins/sched_events.c | 4 +- src/stb_truetype.h | 5011 ++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 14 + tests/libkshark-tests.cpp | 48 + 42 files changed, 13839 insertions(+), 2144 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 LICENSES/GPL-2.0 create mode 100644 LICENSES/LGPL-2.1 create mode 100644 build/FindTraceEvent.cmake create mode 100644 build/FindTraceFS.cmake create mode 100755 build/install_gui.sh create mode 100755 build/install_libkshark-devel.sh create mode 100644 examples/multibufferload.c create mode 100644 src/libkshark-hash.c create mode 100644 src/libkshark-tepdata.c create mode 100644 src/libkshark-tepdata.h create mode 100644 src/stb_truetype.h create mode 100644 tests/CMakeLists.txt create mode 100644 tests/libkshark-tests.cpp
Signature · 1 line
2.25.1
PATCH v8 1/44 kernel-shark: Adopt trace-cmd API changes
Use the new names of the methods
free_record() -> tracecmd_free_record()tracecmd_get_pevent() -> tracecmd_get_tep()
follow the tracecmd library naming convention.
--- src/libkshark.c | 20 ++++++++++---------- src/plugins/sched_events.c | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-)
src/libkshark.c +10 -10
@@ -151,7 +151,7 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file) } kshark_ctx->handle = handle; - kshark_ctx->pevent =tracecmd_get_pevent (handle); + kshark_ctx->pevent =tracecmd_get_tep (handle); kshark_ctx->advanced_event_filter =tep_filter_alloc (kshark_ctx->pevent);
@@ -674,7 +674,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); } }
@@ -774,14 +774,14 @@ static ssize_t get_records(struct kshark_context *kshark_ctx,if (!kshark_show_task (kshark_ctx, entry->pid)) { entry->visible &= ~kshark_ctx->filter_mask; } -free_record (rec); +tracecmd_free_record (rec);break ; }/* REC_ENTRY */ } task =kshark_add_task (kshark_ctx, pid);if (!task) { -free_record (rec); +tracecmd_free_record (rec); goto fail; }
@@ -902,7 +902,7 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,* to all fields of the record. * * @param kshark_ctx: Input location for the session context pointer. -* @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
@@ -1167,7 +1167,7 @@ int kshark_get_pid_easy(struct kshark_entry *entry) data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); pid =tep_data_pid (kshark_ctx->pevent, data); -free_record (data); +tracecmd_free_record (data);pthread_mutex_unlock (&kshark_ctx->input_mutex); }
@@ -1234,7 +1234,7 @@ const char *kshark_get_latency_easy(struct kshark_entry *entry) data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); lat =kshark_get_latency (kshark_ctx->pevent, data); -free_record (data); +tracecmd_free_record (data);pthread_mutex_unlock (&kshark_ctx->input_mutex);
@@ -1279,7 +1279,7 @@ int kshark_get_event_id_easy(struct kshark_entry *entry) data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); event_id =tep_data_type (kshark_ctx->pevent, data); -free_record (data); +tracecmd_free_record (data);pthread_mutex_unlock (&kshark_ctx->input_mutex); }
@@ -1378,7 +1378,7 @@ const char *kshark_get_info_easy(struct kshark_entry *entry)if (event) info =kshark_get_info (kshark_ctx->pevent, data, event); -free_record (data); +tracecmd_free_record (data);pthread_mutex_unlock (&kshark_ctx->input_mutex);
@@ -1492,7 +1492,7 @@ char* kshark_dump_entry(const struct kshark_entry *entry)free (temp_str); } -free_record (data); +tracecmd_free_record (data);if (size <1 ) entry_str =NULL ; }else {
src/plugins/sched_events.c +2 -2
@@ -160,7 +160,7 @@ static int find_wakeup_pid(struct kshark_context *kshark_ctx, struct kshark_entr record =tracecmd_read_at (kshark_ctx->handle, e->offset,NULL ); ret =tep_read_number_field (pid_field, record->data, &val); -free_record (record); +tracecmd_free_record (record);if (ret)return -1 ;
@@ -252,7 +252,7 @@ bool plugin_switch_match_rec_pid(struct kshark_context *kshark_ctx,if (ret ==0 && !(val &0x7f )) switch_pid =tep_data_pid (plugin_ctx->pevent, record); -free_record (record); +tracecmd_free_record (record); }if (switch_pid >=0 && switch_pid == pid)
Signature · 1 line
2.25.1
PATCH v8 2/44 kernel-shark: Use libtraceevent and libtracefs
In reply to Yordan Karadzhov (VMware)libtraceevent and libtracefs are now stand-alone libraries, independent form trace-cmd. Start building and linking KernelShark against those independent libraries. All 3 libraries (libtraceevent, libtracefs and libtracecmd) are being detected by using pkg-config. Since trace-filter-hash.h is no longer distributed as a public header by the libtracecmd, we are adding a copy of it. This is a temporary solution. In the folowing patches we will introduce a new implementation of the hash table provided by trace-filter-hash.h and the header itself will be removed once it is no longer needed.
--- CMakeLists.txt | 9 ++- build/FindTraceCmd.cmake | 138 +++++++++++++++---------------------- build/FindTraceEvent.cmake | 76 ++++++++++++++++++++ build/FindTraceFS.cmake | 76 ++++++++++++++++++++ src/CMakeLists.txt | 6 +- src/libkshark.c | 10 +-- src/libkshark.h | 2 +- src/trace-filter-hash.h | 64 +++++++++++++++++ 8 files changed, 286 insertions(+), 95 deletions(-) create mode 100644 build/FindTraceEvent.cmake create mode 100644 build/FindTraceFS.cmake create mode 100644 src/trace-filter-hash.h
CMakeLists.txt +6 -3
@@ -21,7 +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) + include(${KS_DIR}/build/FindJSONC.cmake) find_package(Doxygen)
@@ -80,8 +84,7 @@ endif (CMAKE_BUILD_TYPE MATCHES Package) include_directories(${KS_DIR}/src/ ${KS_DIR}/build/src/ ${JSONC_INCLUDE_DIR} - ${TRACECMD_INCLUDE_DIR} - ${TRACEFS_INCLUDE_DIR}) + ${TRACECMD_INCLUDE_DIR}) message("") message(STATUS "C flags : " ${CMAKE_C_FLAGS})
build/FindTraceCmd.cmake +55 -83
161 lines not on this page · raw message
build/FindTraceEvent.cmake new file +76 -0
76 lines not on this page · raw message
build/FindTraceFS.cmake new file +76 -0
76 lines not on this page · raw message
src/CMakeLists.txt +3 -3
@@ -7,9 +7,9 @@ add_library(kshark SHARED libkshark.c libkshark-configio.c libkshark-collection.c) -target_link_libraries(kshark ${TRACECMD_LIBRARY} - ${TRACEFS_LIBRARY} - ${TRACEEVENT_LIBRARY} +target_link_libraries(kshark trace::cmd + trace::fs + trace::event ${JSONC_LIBRARY} ${CMAKE_DL_LIBS})
src/libkshark.c +5 -5
@@ -141,7 +141,7 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)kshark_free_task_list (kshark_ctx); - handle =tracecmd_open (file); + handle =tracecmd_open_head (file);if (!handle)return false;
@@ -696,7 +696,7 @@ static ssize_t get_records(struct kshark_context *kshark_ctx,int pid;int cpu; - n_cpus =tracecmd_cpus (kshark_ctx->handle); + n_cpus =tep_get_cpus (kshark_ctx->pevent); cpu_list =calloc (n_cpus,sizeof (*cpu_list));if (!cpu_list)return -ENOMEM ;
@@ -867,7 +867,7 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,if (total <0 ) goto fail; - n_cpus =tracecmd_cpus (kshark_ctx->handle); + n_cpus =tep_get_cpus (kshark_ctx->pevent); rows =calloc (total,sizeof (struct kshark_entry *));if (!rows)
@@ -923,7 +923,7 @@ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx,if (total <0 ) goto fail; - n_cpus =tracecmd_cpus (kshark_ctx->handle); + n_cpus =tep_get_cpus (kshark_ctx->pevent); rows =calloc (total,sizeof (struct tep_record *));if (!rows)
@@ -1047,7 +1047,7 @@ size_t kshark_load_data_matrix(struct kshark_context *kshark_ctx,if (total <0 ) goto fail; - n_cpus =tracecmd_cpus (kshark_ctx->handle); + n_cpus =tep_get_cpus (kshark_ctx->pevent); status = data_matrix_alloc(total, offset_array, cpu_array,
src/libkshark.h +1 -1
@@ -26,7 +26,7 @@ extern "C" {// trace-cmd #include "trace-cmd/trace-cmd.h" -#include "trace-cmd/trace-filter-hash.h" +#include "trace-filter-hash.h" #include "traceevent/event-parse.h" #include "tracefs/tracefs.h"
src/trace-filter-hash.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 3/44 kernel-shark: Add license information
In reply to Yordan Karadzhov (VMware)The GPL-2.0 and LGPL-2.1licenses are added to the LICENSES directory.
--- LICENSES/GPL-2.0 | 359 +++++++++++++++++++++++++++++++++ LICENSES/LGPL-2.1 | 503 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 862 insertions(+) create mode 100644 LICENSES/GPL-2.0 create mode 100644 LICENSES/LGPL-2.1
LICENSES/GPL-2.0 new file +359 -0
@@ -0,0 +1,359 @@ +Valid-License-Identifier: GPL-2.0 +Valid-License-Identifier: GPL-2.0-only +Valid-License-Identifier: GPL-2.0+ +Valid-License-Identifier: GPL-2.0-or-later +SPDX-URL: https://spdx.org/licenses/GPL-2.0.html +Usage-Guide: + To use this license in source code, put one of the following SPDX + tag/value pairs into a comment according to the placement + guidelines in the licensing rules documentation. + For 'GNU General Public License (GPL) version 2 only' use: + SPDX-License-Identifier: GPL-2.0 + or + SPDX-License-Identifier: GPL-2.0-only + For 'GNU General Public License (GPL) version 2 or any later version' use: + SPDX-License-Identifier: GPL-2.0+ + or + SPDX-License-Identifier: GPL-2.0-or-later +License-Text: + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License.
LICENSES/LGPL-2.1 new file +503 -0
503 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 4/44 kernel-shark: Change the CMake minimum version required
In reply to Yordan Karadzhov (VMware)We use some CMake features that are available since version 3.1.2
--- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
CMakeLists.txt +1 -1
@@ -1,5 +1,5 @@ # Check if cmake has the required version -cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) +cmake_minimum_required(VERSION 3.1.2 FATAL_ERROR) # Set the name and version of the project project(kernel-shark)
Signature · 1 line
2.25.1
PATCH v8 5/44 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
@@ -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)
@@ -69,7 +84,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
@@ -15,7 +15,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 AND GLUT_FOUND)
@@ -29,7 +29,7 @@ if (OPENGL_FOUND AND GLUT_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 AND GLUT_FOUND)
@@ -82,7 +82,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
PATCH v8 6/44 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
@@ -84,7 +84,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
@@ -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
@@ -0,0 +1 @@ +sudo cmake -DCOMPONENT=kernelshark -P cmake_install.cmake
build/install_libkshark-devel.sh new file +1 -0
@@ -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
@@ -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
PATCH v8 7/44 kernel-shark: Update README
In reply to Yordan Karadzhov (VMware)KernelShark is now separated from libtraceevent, libtracefs and trace-cmd. The README file has to be updated to reflect this.
--- README | 129 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 62 deletions(-)
README +67 -62
@@ -1,11 +1,13 @@ -This directory contains the new Qt-based version of the KernelShark GUI. +KernelShark is a front-end reader of tracing data. +The official repository is here: + https://git.kernel.org/pub/scm/utils/trace-cmd/kernel-shark.git Third Party Software: ------------------------------------------------------------ KernelShark has the following external dependencies: - Cmake, Json-C, OpenGL/Glut, Qt5Base. + Cmake, Json-C, OpenGL/Glut, Qt5Base, libtraceevent, libtracefs, trace-cmd. 1. In order to install the packages on Ubuntu do the following: sudo apt-get install build-essential git cmake libjson-c-dev -y
@@ -25,88 +27,91 @@ KernelShark has the following external dependencies: dnf install graphviz doxygen -y -Building: ------------------------------------------------------------- -1. Follow the instructions given in trace-cmd/README and build -the original trace-cmd end traceevent libraries. - -2. Building KernelShark: - -2.1 There is a simple and expert way to build KernelShark +3. In order to install the final dependencies do the following: + git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ + cd libtraceevent + make + sudo make install -2.1.1 Option 1 (simple) : build KernelShark as part of trace-cmd + git clone https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ + cd libtracefs + make + sudo make install - (from the toplevel git tree) + git clone https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/ + cd trace-cmd + make + sudo make install_libs - make gui +Building: +------------------------------------------------------------ +2. Building KernelShark: - This will build the necessary parts of trace-cmd needed - by KernelShark. + cd kernel-shark/build + cmake ../ + make + sudo make install -2.1.1.1 By default, the installation prefix is "/usr/local". It can be -changed by passing in "prefix" to the build. +2.1 In order to create a Doxygen documentation add -D_DOXYGEN_DOC=1 +as a CMake Command-Line option. - make prefix=/usr gui +2.2 KernelShark has multiple build types. By default, the build type is +RelWithDebInfo, which will build a release candidate with debug information. +To change the type, pass in the option CMAKE_BUILD_TYPE=<type>. -2.1.1.2 Use "make clean" if you want to delete all already compiled objects. -This will also clean up all the files created by cmake. + cmake -DCMAKE_BUILD_TYPE=Debug - for "-g" option + cmake -DCMAKE_BUILD_TYPE=Release - for "-O3" option + cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo - for "-g -O2" option (default) + cmake -DCMAKE_BUILD_TYPE=MinSizeRel - for "-Os" option -2.1.1.3 KernelShark has multiple build types (See section 2.1.2.3 for more -details. By default, the build type is RelWithDebInfo, which will build -a release candidate with debug information. To change the type, pass in -the option BUILD_TYPE=<type> to the make process. +2.3 In addition to the standard CMake build types (Debug, Release, +RelWithDebInfo, MinSizeRel) KernelShark supports a "Package" build type. +By default this build type adds the "-O3" compiler flag. Package maintainers +can chose their own compiler flags by providing the corresponding +CMAKE_XXXX_FLAGS_PACKAGE Command-Line options (see the example below). - make BUILD_TYPE=Debug gui - for "-g" option - make BUILD_TYPE=Release gui - for "-O3" option - make BUILD_TYPE=RelWithDebInfo gui - for "-g -O2" option (default) - make BUILD_TYPE=MinSizeRel gui - for "-Os" option +-- Note that when built as a "Package" the RPATH-s of the executables are +set directly to _INSTALL_PREFIX/lib/kernelshark/ -2.1.2 Option 2 (expert) : standalone build of KernelShark (for hackers only) +2.4 After building the code "kernel-shark/lib" will contain all libraries +and "kernel-shark/bin" will contain all executables. - (note, you may need to do a normal make from the toplevel git - tree before performing the following) +2.5 Use the script "cmake_clean.sh" if you want to delete all already +compiled objects and all files generated by CMake. - make - cd kernel-shark/build - cmake ../ - make + cd kernel-shark/build + ./cmake-clean.sh - This gives you a bit more control as you may easily pass in - your own cmake options. +2.6 By default, installation prefix is "/usr/local". It can be changed using +-D_INSTALL_PREFIX= as a CMake Command-Line option. -2.1.2.1 In order to create a Doxygen documentation add -D_DOXYGEN_DOC=1 -as a CMake Command-Line option. +2.7 In order to uninstall KernelShark do: + cd kernel-shark/build + ./cmake_uninstall.sh -2.1.2.2 By default, installation prefix is "/usr/local". It can be changed using --D_INSTALL_PREFIX= as a CMake Command-Line option. -2.1.2.3 In addition to the standard CMake build types (Debug, Release, -RelWithDebInfo, MinSizeRel) KernelShark supports a "Package" build type. -By default this build type adds the "-O2" compiler flag. Package maintainers -can chose their own compiler flags by providing the corresponding -CMAKE_XXXX_FLAGS_PACKAGE Command-Line options (see the example below). +CMake examples: --- Note that when built as a "Package" the RPATH-s of the executables are -set directly to _INSTALL_PREFIX/lib/kernelshark/ + cmake -D_DOXYGEN_DOC=1 -D_INSTALL_PREFIX=/usr ../ --- Note that when built as a "Debug" the "Record" dialog will try to use the -version of the trace-cmd executable from the build location. In all other cases -the dialog will derive the absolut path to the trace-cmd executable from -"_INSTALL_PREFIX", hence the dialog will use the installed version. + cmake -DCMAKE_BUILD_TYPE=Package -DCMAKE_C_FLAGS_PACKAGE="-O3 -pedantic" ../ -If no build types is specified, the type will be "RelWithDebInfo". -Examples: +Contributions: +------------------------------------------------------------ +3. For questions about the use of the library, please send email to: + [email protected] - cmake -D_DOXYGEN_DOC=1 -D_INSTALL_PREFIX=/usr ../ + Subscribe: http://vger.kernel.org/vger-lists.html#linux-trace-users + Archives: https://lore.kernel.org/linux-trace-users/ - cmake -DCMAKE_BUILD_TYPE=Package -DCMAKE_C_FLAGS_PACKAGE="-O3 -pedantic" ../ +3.1 For contributions to development, please send patches to: + [email protected] -2.1.2.4 Use the script "cmake_clean.sh" if you want to delete all already -compiled objects and all files generated by CMake. + Subscribe: http://vger.kernel.org/vger-lists.html#linux-trace-devel + Archives: https://lore.kernel.org/linux-trace-devel/ - cd kernel-shark/build - ./cmake-clean.sh +3.2 Note, this project follows the style of submitting patches as described +by the Linux kernel. -3. After building the code "kernel-shark/lib" will contain all libraries -and "kernel-shark/bin" will contain all executables. + https://www.kernel.org/doc/html/v5.4/process/submitting-patches.html
Signature · 1 line
2.25.1
PATCH v8 8/44 kernel-shark: Define build target for JSONC
In reply to Yordan Karadzhov (VMware)Having the JSONC libs as a target simplifies the build/linking of the KernelShark libraries and executables because all necessary information, like include paths, compiler flags and library names can be retriever directly from the target.
The patch also adds to FindJSONC.cmake the standard module documentation header.
--- CMakeLists.txt | 3 +- build/FindJSONC.cmake | 70 +++++++++++++++++++++++++++++++++---------- src/CMakeLists.txt | 2 +- 3 files changed, 57 insertions(+), 18 deletions(-)
CMakeLists.txt +1 -2
@@ -41,7 +41,7 @@ find_package(TraceEvent REQUIRED) find_package(TraceFS REQUIRED) find_package(TraceCmd REQUIRED) -include(${KS_DIR}/build/FindJSONC.cmake) +find_package(JSONC REQUIRED) find_package(Doxygen)
@@ -99,7 +99,6 @@ endif (CMAKE_BUILD_TYPE MATCHES Package) include_directories(${KS_DIR}/src/ ${KS_DIR}/build/src/ - ${JSONC_INCLUDE_DIR} ${TRACECMD_INCLUDE_DIR}) message("")
build/FindJSONC.cmake +55 -15
87 lines not on this page · raw message
src/CMakeLists.txt +1 -1
@@ -12,7 +12,7 @@ add_library(kshark SHARED libkshark.c target_link_libraries(kshark trace::cmd trace::fs trace::event - ${JSONC_LIBRARY} + jsonc::jsonc ${CMAKE_DL_LIBS}) set_target_properties(kshark PROPERTIES
Signature · 1 line
2.25.1
PATCH v8 9/44 kernel-shark: Use only signed types in kshark_entry
In reply to Yordan Karadzhov (VMware)Using uint64_t for the value of the offset was just wrong. According to the POSIX standard off_t is a signed integer type with unspecified size. Here we stick to a 64 bit integer, because this size guaranties optimal packing of the kshark_entry structure.
Using unsigned values for the timestamps is also a source of problems and has been a reason for the introduction of multiple bugs in the past. In principal the value of the timestamps cannot be negative. However, this value must have the same type as the values used to define the state of the visualization model, like the range of the model or the size of the bin. The model state definitions should not take negative values as well, however their values are recalculated automatically when the user browses the data and those calculations may result in negative values in some corner cases. Because of this it is better to use a signed integer type and treat the negative values as an indicator of an error rather than have the negative result of the calculations casted into unsigned type which results into unpredictable behavior of the model.
--- src/libkshark.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/libkshark.h +2 -2
@@ -61,7 +61,7 @@ struct kshark_entry {int32_t event_id;/** The offset into the trace file, used to find the record. */ -uint64_t offset; +int64_t offset;/** * The time of the record in nano seconds. The value is taken from
@@ -69,7 +69,7 @@ struct kshark_entry {* dependent. The time usually is the timestamp from when the system * started. */ -uint64_t ts; +int64_t ts; };/** Size of the task's hash table. */
Signature · 1 line
2.25.1
PATCH v8 10/44 kernel-shark: Add stream_id to kshark_entry
In reply to Yordan Karadzhov (VMware)kshark_entry contains all information from one trace record, needed in order to visualize the time-series of trace records. Here we reorganize the data fields of kshark_entry in order to make room for the unique identifier of the Data stream this entry belongs to.
The Id is coded in 16 bits that are taken from the "event_id" field. So far "event_id" uses 32 bits but we found that it is coded with only 16 bits inside the kernel, so we still have 16 unused (spare) bits in it.
Because the stream Id is coded with int8_t, we need to set an upper limit (127) for the total number of Data streams loaded.
--- src/libkshark.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
src/libkshark.h +7 -4
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: LGPL-2.1 */ /* -* Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> +* Copyright (C) 2017 VMware Inc, Yordan Karadzhov (VMware) <[email protected]> */ /**
@@ -51,15 +51,18 @@ struct kshark_entry {*/ uint16_t visible; +/** Data stream identifier. */ +int16_t stream_id; + +/** Unique Id of the trace event type. */ +int16_t event_id; +/** The CPU core of the record. */ int16_t cpu;/** The PID of the task the record was generated. */ int32_t pid; -/** Unique Id ot the trace event type. */ -int32_t event_id; -/** The offset into the trace file, used to find the record. */ int64_t offset;
Signature · 1 line
2.25.1
PATCH v8 11/44 kernel-shark: Introduce libkshark-hash
In reply to Yordan Karadzhov (VMware)So far KernelShark have been using an implementation of a hash table from trace-cmd/include/trace-cmd/trace-filter-hash.h. However it turns that KernelShark is the only user of trace-filter-hash, which means that it make more sense to make this implementation of the hash table part of KernelShark. In this patch we adapt the original trace-cmd implementation and change the naming convention used.
--- src/CMakeLists.txt | 1 + src/libkshark-hash.c | 239 +++++++++++++++++++++++++++++++++++++++++++ src/libkshark.h | 46 +++++++++ 3 files changed, 286 insertions(+) create mode 100644 src/libkshark-hash.c
src/CMakeLists.txt +1 -0
@@ -4,6 +4,7 @@ set(KS_INCLUDS_DESTINATION "${_INSTALL_PREFIX}/include/${KS_APP_NAME}") message(STATUS "libkshark") add_library(kshark SHARED libkshark.c + libkshark-hash.c libkshark-model.c libkshark-plugin.c libkshark-configio.c
src/libkshark-hash.c new file +239 -0
239 lines not on this page · raw message
src/libkshark.h +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 12/44 kernel-shark: Introduce Data streams
In reply to Yordan Karadzhov (VMware)With the help of Data stream, KernelShark will be able to load and merge multiple trace files (streams). Each stream can have different plugins or filters, registered for it, which means that the raw trace data of the streams can have different formats, and will allow for a great degree of customization of the provided data visualization. In this patch we only provide the basic definitions. The actual integration of the Data streams into the C API of KernelShark will happen in the following patches.
--- src/libkshark.h | 199 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+)
src/libkshark.h +199 -0
@@ -121,6 +121,205 @@ void kshark_hash_id_free(struct kshark_hash_id *hash);int *kshark_hash_ids (struct kshark_hash_id *hash); +struct kshark_data_stream ; + +/** A function type to be used by the method interface of the data stream. */ +typedef char *(*stream_get_str_func ) (struct kshark_data_stream *, +const struct kshark_entry *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_get_int_func ) (struct kshark_data_stream *, +const struct kshark_entry *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int (*stream_find_id_func ) (struct kshark_data_stream *, +const char *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int *(*stream_get_ids_func ) (struct kshark_data_stream *); + +/** A function type to be used by the method interface of the data stream. */ +typedef int (*stream_get_names_func ) (struct kshark_data_stream *, +const struct kshark_entry *, +char ***); + +/** Event field format identifier. */ +typedef enum kshark_event_field_format { +/** A field of unknown type. */ +KS_INVALID_FIELD , + +/** Integer number */ +KS_INTEGER_FIELD , + +/** Floating-point number */ +KS_FLOAT_FIELD +}kshark_event_field_format ; + +/** A function type to be used by the method interface of the data stream. */ +typedef kshark_event_field_format +(*stream_event_field_type ) (struct kshark_data_stream *, +const struct kshark_entry *, +const char *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_read_event_field ) (struct kshark_data_stream *, +const struct kshark_entry *, +const char *, +int64_t *); + +/** A function type to be used by the method interface of the data stream. */ +typedef const int (*stream_read_record_field ) (struct kshark_data_stream *, +void *, +const char *, +int64_t *); + +struct kshark_context ; + +/** A function type to be used by the method interface of the data stream. */ +typedef ssize_t (*load_entries_func ) (struct kshark_data_stream *, +struct kshark_context *, +struct kshark_entry ***); + +/** A function type to be used by the method interface of the data stream. */ +typedef ssize_t (*load_matrix_func ) (struct kshark_data_stream *, +struct kshark_context *, +int16_t **event_array, +int16_t **cpu_array, +int32_t **pid_array, +int64_t **offset_array, +int64_t **ts_array); + +/** Data interface identifier. */ +typedef enum kshark_data_interface_id { +/** An interface with unknown type. */ +KS_INVALID_INTERFACE , + +/** Generic interface suitable for Ftrace data. */ +KS_GENERIC_DATA_INTERFACE , +}kshark_data_interface_id ; + +/** +* Structure representing the interface of methods used to operate over +* the data from a given stream. +*/ +struct kshark_generic_stream_interface { +/** Interface version identifier. */ +kshark_data_interface_id type;/* MUST BE FIRST ENTRY. */ + +/** Method used to retrieve the Process Id of the entry. */ +stream_get_int_func get_pid; + +/** Method used to retrieve the Event Id of the entry. */ +stream_get_int_func get_event_id; + +/** Method used to retrieve the Event name of the entry. */ +stream_get_str_func get_event_name; + +/** Method used to retrieve the Task name of the entry. */ +stream_get_str_func get_task; + +/** Method used to retrieve the Info string of the entry. */ +stream_get_str_func get_info; + +/** +* Method used to retrieve an unspecified auxiliary info of the trace +* record. +*/ +stream_get_str_func aux_info; + +/** Method used to retrieve Id of the Event from its name. */ +stream_find_id_func find_event_id; + +/** Method used to retrieve the array of Ids of all Events. */ +stream_get_ids_func get_all_event_ids; + +/** Method used to dump the entry's content to string. */ +stream_get_str_func dump_entry; + +/** +* Method used to retrieve the array of all field names of a given +* event. +*/ +stream_get_names_func get_all_event_field_names; + +/** Method used to access the type of an event's data field. */ +stream_event_field_type get_event_field_type; + +/** Method used to access the value of an event's data field. */ +stream_read_event_field read_event_field_int64; + +/** Method used to access the value of an event's data field. */ +stream_read_record_field read_record_field_int64; + +/** Method used to load the data in the form of entries. */ +load_entries_func load_entries; + +/** Method used to load the data in matrix form. */ +load_matrix_func load_matrix; + +/** Generic data handle. */ +void *handle; +}; + +/** The limit in size of the data format identifier string. */ +#define KS_DATA_FORMAT_SIZE 15 + +/** Structure representing a stream of trace data. */ +struct kshark_data_stream { +/** Data stream identifier. */ +uint16_t stream_id; + +/** The number of CPUs presented in this data stream. */ +int n_cpus; + +/** +* The number of distinct event types presented in this data stream. +*/ +int n_events; + +/** The Process Id of the Idle task. */ +int idle_pid; + +/** Trace data file pathname. */ +char *file; + +/** Stream name. */ +char *name; + +/** Hash table of task PIDs. */ +struct kshark_hash_id *tasks; + +/** A mutex, used to protect the access to the input file. */ +pthread_mutex_t input_mutex; + +/** Hash of tasks to filter on. */ +struct kshark_hash_id *show_task_filter; + +/** Hash of tasks to not display. */ +struct kshark_hash_id *hide_task_filter; + +/** Hash of events to filter on. */ +struct kshark_hash_id *show_event_filter; + +/** Hash of events to not display. */ +struct kshark_hash_id *hide_event_filter; + +/** Hash of CPUs to filter on. */ +struct kshark_hash_id *show_cpu_filter; + +/** Hash of CPUs to not display. */ +struct kshark_hash_id *hide_cpu_filter; + +/** The type of the data. */ +char data_format[KS_DATA_FORMAT_SIZE ]; + +/** +* The interface of methods used to operate over the data from a given +* stream. +*/ +void *interface; +}; +/** Size of the task's hash table. */ #define KS_TASK_HASH_SHIFT 16#define KS_TASK_HASH_SIZE (1 << KS_TASK_HASH_SHIFT)
Signature · 1 line
2.25.1
PATCH v8 13/44 kernel-shark: Rename static methods in libkshark
In reply to Yordan Karadzhov (VMware)"kshark" prefix is needed only for the public methods of the API. We are changing the names of those static methods because we need to use those names when integrating the data streams into the API.i
--- src/libkshark.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
src/libkshark.c +7 -7
@@ -1097,8 +1097,8 @@ size_t kshark_load_data_matrix(struct kshark_context *kshark_ctx,return -ENOMEM ; } -static const char *kshark_get_latency (struct tep_handle *pe, -struct tep_record *record) +static const char *get_latency (struct tep_handle *pe, +struct tep_record *record) {if (!record)return NULL ;
@@ -1108,7 +1108,7 @@ static const char *kshark_get_latency(struct tep_handle *pe,return seq.buffer; } -static const char *kshark_get_info (struct tep_handle *pe, +static const char *get_info (struct tep_handle *pe,struct tep_record *record,struct tep_event *event) {
@@ -1233,7 +1233,7 @@ const char *kshark_get_latency_easy(struct kshark_entry *entry)pthread_mutex_lock (&kshark_ctx->input_mutex); data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); - lat =kshark_get_latency (kshark_ctx->pevent, data); + lat =get_latency (kshark_ctx->pevent, data);tracecmd_free_record (data);pthread_mutex_unlock (&kshark_ctx->input_mutex);
@@ -1376,7 +1376,7 @@ const char *kshark_get_info_easy(struct kshark_entry *entry) event_id =tep_data_type (kshark_ctx->pevent, data); event =tep_find_event (kshark_ctx->pevent, event_id);if (event) - info =kshark_get_info (kshark_ctx->pevent, data, event); + info =get_info (kshark_ctx->pevent, data, event);tracecmd_free_record (data);
@@ -1471,7 +1471,7 @@ char* kshark_dump_entry(const struct kshark_entry *entry) event =tep_find_event (kshark_ctx->pevent, entry->event_id); event_name = event? event->name :"[UNKNOWN EVENT]" ; - lat =kshark_get_latency (kshark_ctx->pevent, data); + lat =get_latency (kshark_ctx->pevent, data); size = asprintf(&temp_str, "%" PRIu64 "; %s-%i; CPU %i; %s;", entry->ts,
@@ -1480,7 +1480,7 @@ char* kshark_dump_entry(const struct kshark_entry *entry) entry->cpu, lat); - info =kshark_get_info (kshark_ctx->pevent, data, event); + info =get_info (kshark_ctx->pevent, data, event);if (size >0 ) { size = asprintf(&entry_str, "%s %s; %s; 0x%x",
Signature · 1 line
2.25.1
PATCH v8 14/44 kernel-shark: Add basic methods for Data streams
In reply to Yordan Karadzhov (VMware)Here we introduce the basic mechanisms for using data streams. For the moment these are just stand alone definitions and the integration with the API is yet to be introduced in the following patches.
--- src/libkshark.c | 716 ++++++++++++++++++++++++++++++++++++++++++++++++ src/libkshark.h | 104 +++++++ 2 files changed, 820 insertions(+)
src/libkshark.c +716 -0
@@ -166,6 +166,258 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)return true; } +static void kshark_stream_free (struct kshark_data_stream *stream) +{ +if (!stream) +return ; + +kshark_hash_id_free (stream->show_task_filter); +kshark_hash_id_free (stream->hide_task_filter); + +kshark_hash_id_free (stream->show_event_filter); +kshark_hash_id_free (stream->hide_event_filter); + +kshark_hash_id_free (stream->show_cpu_filter); +kshark_hash_id_free (stream->hide_cpu_filter); + +kshark_hash_id_free (stream->tasks); + +free (stream->file); +free (stream->name); +free (stream->interface); +free (stream); +} + +static struct kshark_data_stream *kshark_stream_alloc () +{ +struct kshark_data_stream *stream; + + stream =calloc (1 ,sizeof (*stream)); +if (!stream) + goto fail; + + stream->show_task_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + stream->hide_task_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + + stream->show_event_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + stream->hide_event_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + + stream->show_cpu_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + stream->hide_cpu_filter =kshark_hash_id_alloc (KS_FILTER_HASH_NBITS ); + + stream->tasks =kshark_hash_id_alloc (KS_TASK_HASH_NBITS ); + +if (!stream->show_task_filter || + !stream->hide_task_filter || + !stream->show_event_filter || + !stream->hide_event_filter || + !stream->tasks) { + goto fail; + } + +kshark_set_data_format (stream->data_format,KS_INVALID_DATA ); + stream->name =strdup (KS_UNNAMED ); + +return stream; + + fail: +kshark_stream_free (stream); + +return NULL ; +} +/** +* The maximum number of Data streams that can be added simultaneously. +* The limit is determined by the 16 bit integer used to store the stream Id +* inside struct kshark_entry. +*/ +#define KS_MAX_STREAM_ID INT16_MAX + +/** +* Bit mask (0 - 15) used when converting indexes to pointers and vise-versa. +*/ +#define INDEX_MASK UINT16_MAX + +/** +* Bit mask (16 - 31/63) used when converting indexes to pointers and +* vise-versa. +*/ +#define INVALID_STREAM_MASK (~((unsigned long) INDEX_MASK)) + +static int index_from_ptr (void *ptr) +{ +unsigned long index = (unsigned long ) ptr; + +return (int ) (index &INDEX_MASK ); +} + +static void *index_to_ptr (unsigned int index) +{ +unsigned long p; + + p =INVALID_STREAM_MASK | index; + +return (void *) p; +} + +static bool kshark_is_valid_stream (void *ptr) +{ +unsigned long p = (unsigned long ) ptr; +bool v = !((p & ~INDEX_MASK ) ==INVALID_STREAM_MASK ); + +return p && v; +} + +/** +* @brief Add new Data stream. +* +* @param kshark_ctx: Input location for context pointer. +* +* @returns Zero on success or a negative errno code on failure. +*/ +int kshark_add_stream (struct kshark_context *kshark_ctx) +{ +struct kshark_data_stream *stream; +int new_stream; + +if (kshark_ctx->stream_info.next_free_stream_id >KS_MAX_STREAM_ID ) +return -ENODEV ; + +if (kshark_ctx->stream_info.next_free_stream_id == + kshark_ctx->stream_info.array_size) { +size_t new_size =2 * kshark_ctx->stream_info.array_size; +struct kshark_data_stream **streams_tmp; + + streams_tmp =realloc (kshark_ctx->stream, + new_size *sizeof (*kshark_ctx->stream)); +if (!streams_tmp) +return -ENOMEM ; + + kshark_ctx->stream = streams_tmp; + kshark_ctx->stream_info.array_size = new_size; + } + + stream =kshark_stream_alloc (); +if (!stream) +return -ENOMEM ; + +if (pthread_mutex_init (&stream->input_mutex,NULL ) !=0 ) { +kshark_stream_free (stream); +return -EAGAIN ; + } + +if (kshark_ctx->stream_info.next_free_stream_id > + kshark_ctx->stream_info.max_stream_id) { + new_stream = ++kshark_ctx->stream_info.max_stream_id; + + kshark_ctx->stream_info.next_free_stream_id = new_stream +1 ; + + kshark_ctx->stream[new_stream] = stream; + stream->stream_id = new_stream; + }else { + new_stream = kshark_ctx->stream_info.next_free_stream_id; + + kshark_ctx->stream_info.next_free_stream_id = +index_from_ptr (kshark_ctx->stream[new_stream]); + + kshark_ctx->stream[new_stream] = stream; + stream->stream_id = new_stream; + } + + kshark_ctx->n_streams++; + +return stream->stream_id; +} + +/** +* @brief Remove Data stream. +* +* @param kshark_ctx: Input location for context pointer. +* @param sd: Data stream identifier. +* +* @returns Zero on success or a negative errno code on failure. +*/ +int kshark_remove_stream (struct kshark_context *kshark_ctx,int sd) +{ +struct kshark_data_stream *stream; + +if (sd <0 || + sd > kshark_ctx->stream_info.max_stream_id || + !kshark_is_valid_stream (kshark_ctx->stream[sd])) +return -EFAULT ; + + stream = kshark_ctx->stream[sd]; + +pthread_mutex_destroy (&stream->input_mutex); + +kshark_stream_free (stream); + kshark_ctx->stream[sd] = +index_to_ptr (kshark_ctx->stream_info.next_free_stream_id); + kshark_ctx->stream_info.next_free_stream_id = sd; + kshark_ctx->n_streams--; + +return 0 ; +} + +/** +* @brief Get the Data stream object having given Id. +* +* @param kshark_ctx: Input location for context pointer. +* @param sd: Data stream identifier. +* +* @returns Pointer to a Data stream object if the sream exists. Otherwise +* NULL. +*/ +struct kshark_data_stream * +kshark_get_data_stream (struct kshark_context *kshark_ctx,int sd) +{ +if (sd >=0 && sd <= kshark_ctx->stream_info.max_stream_id) +if (kshark_ctx->stream[sd] && +kshark_is_valid_stream (kshark_ctx->stream[sd]) && + kshark_ctx->stream[sd]->interface) +return kshark_ctx->stream[sd]; + +return NULL ; +} + +/** +* @brief Get the Data stream object corresponding to a given entry +* +* @param entry: Input location for the KernelShark entry. +* +* @returns Pointer to a Data stream object on success. Otherwise NULL. +*/ +struct kshark_data_stream * +kshark_get_stream_from_entry (const struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + +return kshark_get_data_stream (kshark_ctx, entry->stream_id); +} + +/** +* @brief Get an array containing the Ids of all opened Trace data streams. +* The User is responsible for freeing the array. +* +* @param kshark_ctx: Input location for context pointer. +*/ +int *kshark_all_streams (struct kshark_context *kshark_ctx) +{ +int *ids, i, count =0 ; + + ids =calloc (kshark_ctx->n_streams, (sizeof (*ids))); +if (!ids) +return NULL ; + +for (i =0 ; i <= kshark_ctx->stream_info.max_stream_id; ++i) +if (kshark_ctx->stream[i] && +kshark_is_valid_stream (kshark_ctx->stream[i])) + ids[count++] = i; + +return ids; +}/** * @brief Close the trace data file and free the trace data handle. *
@@ -252,6 +504,470 @@ void kshark_free(struct kshark_context *kshark_ctx)free (kshark_ctx); } +/** +* @brief Get the name of the command/task from its Process Id. +* +* @param sd: Data stream identifier. +* @param pid: Process Id of the command/task. +*/ +char *kshark_comm_from_pid (int sd,int pid) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_context *kshark_ctx =NULL ; +struct kshark_data_stream *stream; +struct kshark_entry e; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + stream =kshark_get_data_stream (kshark_ctx, sd); +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_task) { + e.visible =KS_PLUGIN_UNTOUCHED_MASK ; + e.pid = pid; + +return interface->get_task (stream, &e); + } + +return NULL ; +} + +/** +* @brief Get the name of the event from its Id. +* +* @param sd: Data stream identifier. +* @param event_id: The unique Id of the event type. +*/ +char *kshark_event_from_id (int sd,int event_id) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_context *kshark_ctx =NULL ; +struct kshark_data_stream *stream; +struct kshark_entry e; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + stream =kshark_get_data_stream (kshark_ctx, sd); +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_event_name) { + e.visible =KS_PLUGIN_UNTOUCHED_MASK ; + e.event_id = event_id; + +return interface->get_event_name (stream, &e); + } + +return NULL ; +} + +/** +* @brief Get the original process Id of the entry. Using this function make +* sense only in cases when the original value can be overwritten by +* plugins. If you know that no plugins are loaded use "entry->pid" +* directly. +* +* @param entry: Input location for an entry. +*/ +int kshark_get_pid (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_pid) +return interface->get_pid (stream, entry); + +return -EFAULT ; +} + +/** +* @brief Get the original event Id of the entry. Using this function make +* sense only in cases when the original value can be overwritten by +* plugins. If you know that no plugins are loaded use "entry->event_id" +* directly. +* +* @param entry: Input location for an entry. +*/ +int kshark_get_event_id (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_event_id) +return interface->get_event_id (stream, entry); + +return -EFAULT ; +} + +/** +* @brief Get an array of all event Ids for a given data stream. +* +* @param stream: Input location for a Trace data stream pointer. +* +* @returns An array of event Ids. The user is responsible for freeing the +* outputted array. +*/ +int *kshark_get_all_event_ids (struct kshark_data_stream *stream) +{ +struct kshark_generic_stream_interface *interface; + +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_all_event_ids) +return interface->get_all_event_ids (stream); + +return NULL ; +} + +/** +* @brief Find the event Ids corresponding to a given event name. +* +* @param stream: Input location for a Trace data stream pointer. +* @param event_name: The name of the event. +* +* @returns Event Ids number. +*/ +int kshark_find_event_id (struct kshark_data_stream *stream, +const char *event_name) +{ +struct kshark_generic_stream_interface *interface; + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->find_event_id) +return interface->find_event_id (stream, event_name); + +return -EFAULT ; +} + +/** +* @brief Find the event name corresponding to a given entry. +* +* @param entry: Input location for an entry. +* +* @returns The mane of the event on success, or NULL in case of failure. +* The use is responsible for freeing the output string. +*/ +char *kshark_get_event_name (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_event_name) +return interface->get_event_name (stream, entry); + +return NULL ; +} + +/** +* @brief Find the task name corresponding to a given entry. +* +* @param entry: Input location for an entry. +* +* @returns The mane of the task on success, or NULL in case of failure. +* The use is responsible for freeing the output string. +*/ +char *kshark_get_task (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_task) +return interface->get_task (stream, entry); + +return NULL ; +} + +/** +* @brief Get the basic information (text) about the entry. +* +* @param entry: Input location for an entry. +* +* @returns A the info text. The user is responsible for freeing the +* outputted string. +*/ +char *kshark_get_info (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_info) +return interface->get_info (stream, entry); + +return NULL ; +} + +/** +* @brief Get the auxiliary information about the entry. In the case of +* TEP (Ftrace) data, this function provides the latency info. +* +* @param entry: Input location for an entry. +* +* @returns A the auxiliary text info. The user is responsible for freeing the +* outputted string. +*/ +char *kshark_get_aux_info (const struct kshark_entry *entry) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return NULL ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->aux_info) +return interface->aux_info (stream, entry); + +return NULL ; +} + +/** +* @brief Get an array of all data field names associated with a given entry. +* +* @param entry: Input location for an entry. +* @param fields: Output location of the array of field names. The user is +* responsible for freeing the elements of the outputted array. +* +* @returns Total number of event fields on success, or a negative errno in +* the case of a failure. +*/ +int kshark_get_all_event_field_names (const struct kshark_entry *entry, +char ***fields) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_all_event_field_names) +return interface->get_all_event_field_names (stream, + entry, fields); + +return -EFAULT ; +} + +/** +* @brief Get the value type of an event field corresponding to a given entry. +* +* @param entry: Input location for an entry. +* @param field: The name of the data field. +* +* @returns The type of the data field on success, or KS_INVALID_FIELD in +* the case of a failure. +*/ +kshark_event_field_format +kshark_get_event_field_type (const struct kshark_entry *entry, +const char *field) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return KS_INVALID_FIELD ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->get_event_field_type) +return interface->get_event_field_type (stream, entry, field); + +return KS_INVALID_FIELD ; +} + +/** +* @brief Get the value of an event field in a given trace record. +* +* @param stream: Input location for a Trace data stream pointer. +* @param rec: Input location for a record. +* @param field: The name of the data field. +* @param val: Output location for the value of the field. +* +* @returns Zero on success or a negative errno in the case of a failure. +*/ +int kshark_read_record_field_int (struct kshark_data_stream *stream,void *rec, +const char *field,int64_t *val) +{ +struct kshark_generic_stream_interface *interface; + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->read_record_field_int64) +return interface->read_record_field_int64 (stream, rec, + field, val); + +return -EFAULT ; +} + +/** +* @brief Get the value of an event field corresponding to a given entry. +* The value is retrieved via the offset in the file of the original +* record. +* +* @param entry: Input location for an entry. +* @param field: The name of the data field. +* @param val: Output location for the value of the field. +* +* @returns Zero on success or a negative errno in the case of a failure. +*/ +int kshark_read_event_field_int (const struct kshark_entry *entry, +const char * field,int64_t *val) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_stream_from_entry (entry); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->read_event_field_int64) +return interface->read_event_field_int64 (stream, entry, field, val); + +return -EFAULT ; +} + +/** @brief Print the entry. */ +void kshark_print_entry (const struct kshark_entry *entry) +{ +char *entry_str =kshark_dump_entry (entry); + +if (!entry_str) +puts ("(nil)" ); + +puts (entry_str); +free (entry_str); +} + +/** +* @brief Load the content of the trace data file asociated with a given +* Data stream into an array of kshark_entries. +* If one or more filters are set, the "visible" fields of each entry +* is updated according to the criteria provided by the filters. The +* field "filter_mask" of the session's context is used to control the +* level of visibility/invisibility of the filtered entries. +* +* @param kshark_ctx: Input location for context pointer. +* @param sd: Data stream identifier. +* @param data_rows: Output location for the trace data. The user is +* responsible for freeing the elements of the outputted +* array. +* +* @returns The size of the outputted data in the case of success, or a +* negative error code on failure. +*/ +ssize_t kshark_load_entries (struct kshark_context *kshark_ctx,int sd, +struct kshark_entry ***data_rows) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_data_stream (kshark_ctx, sd); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->load_entries) +return interface->load_entries (stream, kshark_ctx, data_rows); + +return -EFAULT ; +} + +/** +* @brief Load the content of the trace data file asociated with a given +* Data stream into a data matrix. The user is responsible +* for freeing the outputted data. +* +* @param kshark_ctx: Input location for context pointer. +* @param sd: Data stream identifier. +* @param cpu_array: Output location for the CPU column (array) of the matrix. +* @param event_array: Output location for the Event Id column (array) of the +* matrix. +* @param pid_array: Output location for the PID column (array) of the matrix. +* @param offset_array: Output location for the offset column (array) of the +* matrix. +* @param ts_array: Output location for the time stamp column (array) of the +* matrix. +*/ +ssize_t kshark_load_matrix (struct kshark_context *kshark_ctx,int sd, +int16_t **event_array, +int16_t **cpu_array, +int32_t **pid_array, +int64_t **offset_array, +int64_t **ts_array) +{ +struct kshark_generic_stream_interface *interface; +struct kshark_data_stream *stream = +kshark_get_data_stream (kshark_ctx, sd); + +if (!stream) +return -EFAULT ; + + interface = stream->interface; +if (interface->type ==KS_GENERIC_DATA_INTERFACE && + interface->load_matrix) +return interface->load_matrix (stream, kshark_ctx, event_array, + cpu_array, + pid_array, + offset_array, + ts_array); + +return -EFAULT ; +} +static struct kshark_task_list *kshark_find_task (struct kshark_context *kshark_ctx,uint32_t key,int pid) {
src/libkshark.h +104 -0
148 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 15/44 kernel-shark: Housekeeping before implementing stream interface
In reply to Yordan Karadzhov (VMware)kshark_load data_matrix() is a method that is used only in trace-cruncher prototype. The version of this function that is currently part of the API is anyway not compatible with the latest version of trace-cruncher because of the mismatch of the argument types, so we can directly remove the existing implementation. An equivalent functionality will be provided as part of the implantation of the Data stream interface in the following patch. Here we just make kshark_data_matrix_alloc() and unset_event_filter_flag() public, because the methods will be used in the stream interface implementation.
--- src/libkshark.c | 121 ++++++++---------------------------------------- src/libkshark.h | 28 ++++++++--- 2 files changed, 40 insertions(+), 109 deletions(-)
src/libkshark.c +19 -102
@@ -1190,21 +1190,6 @@ bool kshark_filter_is_set(struct kshark_context *kshark_ctx) -kshark_this_filter_is_set (kshark_ctx->hide_event_filter); } -static inline void unset_event_filter_flag (struct kshark_context *kshark_ctx, -struct kshark_entry *e) -{ -/* -* All entries, filtered-out by the event filters, will be treated -* differently, when visualized. Because of this, ignore the value -* of the GRAPH_VIEW flag provided by the user via -* kshark_ctx->filter_mask. The value of the EVENT_VIEW flag in -* kshark_ctx->filter_mask will be used instead. -*/ -int event_mask = kshark_ctx->filter_mask & ~KS_GRAPH_VIEW_FILTER_MASK ; - - e->visible &= ~event_mask; -} -static void set_all_visible (uint16_t *v) {/* Keep the original value of the PLUGIN_UNTOUCHED bit flag. */ *v |=0xFF & ~KS_PLUGIN_UNTOUCHED_MASK ;
@@ -1680,11 +1665,25 @@ static inline void free_ptr(void *ptr)free (*(void **)ptr); } -static bool data_matrix_alloc (size_t n_rows,uint64_t **offset_array, -uint16_t **cpu_array, -uint64_t **ts_array, -uint16_t **pid_array, -int **event_array) +/** +* @brief Allocate data arrays (matrix columns) to be used to load the tracing +* data into a data matrix form. +* +* @param n_rows: Number matrix rows to be allocated. Must be equal to the +* number of trace records. +* @param cpu_array: Output location for the CPU Id column. +* @param pid_array: Output location for the PID column. +* @param event_array: Output location for the Event Id column. +* @param offset_array: Output location for the record offset column. +* @param ts_array: Output location for the timestamp column. +* +* @returns True on success. Else false. +*/ +bool kshark_data_matrix_alloc (size_t n_rows,int16_t **event_array, +int16_t **cpu_array, +int32_t **pid_array, +int64_t **offset_array, +int64_t **ts_array) {if (offset_array) { *offset_array =calloc (n_rows,sizeof (**offset_array));
@@ -1731,88 +1730,6 @@ static bool data_matrix_alloc(size_t n_rows, uint64_t **offset_array,return false; } -/** -* @brief Load the content of the trace data file into a table / matrix made -* of columns / arrays of data. The user is responsible for freeing the -* elements of the outputted array -* -* @param kshark_ctx: Input location for the session context pointer. -* @param offset_array: Output location for the array of record offsets. -* @param cpu_array: Output location for the array of CPU Ids. -* @param ts_array: Output location for the array of timestamps. -* @param pid_array: Output location for the array of Process Ids. -* @param event_array: Output location for the array of Event Ids. -* -* @returns The size of the outputted arrays in the case of success, or a -* negative error code on failure. -*/ -size_t kshark_load_data_matrix (struct kshark_context *kshark_ctx, -uint64_t **offset_array, -uint16_t **cpu_array, -uint64_t **ts_array, -uint16_t **pid_array, -int **event_array) -{ -enum rec_type type =REC_ENTRY ; -struct rec_list **rec_list; -ssize_t count, total =0 ; -bool status; -int n_cpus; - - total =get_records (kshark_ctx, &rec_list, type); -if (total <0 ) - goto fail; - - n_cpus =tep_get_cpus (kshark_ctx->pevent); - - status =data_matrix_alloc (total, offset_array, - cpu_array, - ts_array, - pid_array, - event_array); -if (!status) - goto fail_free; - -for (count =0 ; count < total; count++) { -int next_cpu; - - next_cpu =pick_next_cpu (rec_list, n_cpus, type); -if (next_cpu >=0 ) { -struct rec_list *rec = rec_list[next_cpu]; -struct kshark_entry *e = &rec->entry; - -if (offset_array) - (*offset_array)[count] = e->offset; - -if (cpu_array) - (*cpu_array)[count] = e->cpu; - -if (ts_array) - (*ts_array)[count] = e->ts; - -if (pid_array) - (*pid_array)[count] = e->pid; - -if (event_array) - (*event_array)[count] = e->event_id; - - rec_list[next_cpu] = rec_list[next_cpu]->next; -free (rec); - } - } - -/* There should be no entries left in rec_list. */ -free_rec_list (rec_list, n_cpus, type); -return total; - - fail_free: -free_rec_list (rec_list, n_cpus, type); - - fail: -fprintf (stderr,"Failed to allocate memory during data loading.\n" ); -return -ENOMEM ; -} -static const char *get_latency (struct tep_handle *pe,struct tep_record *record) {
src/libkshark.h +21 -7
@@ -456,13 +456,6 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,ssize_t kshark_load_data_records (struct kshark_context *kshark_ctx,struct tep_record ***data_rows); -size_t kshark_load_data_matrix (struct kshark_context *kshark_ctx, -uint64_t **offset_array, -uint16_t **cpu_array, -uint64_t **ts_array, -uint16_t **pid_array, -int **event_array); -ssize_t kshark_get_task_pids (struct kshark_context *kshark_ctx,int **pids);void kshark_close (struct kshark_context *kshark_ctx);
@@ -617,6 +610,21 @@ bool kshark_this_filter_is_set(struct tracecmd_filter_id *filter);bool kshark_filter_is_set (struct kshark_context *kshark_ctx); +static inline void unset_event_filter_flag (struct kshark_context *kshark_ctx, +struct kshark_entry *e) +{ +/* +* All entries, filtered-out by the event filters, will be treated +* differently, when visualized. Because of this, ignore the value +* of the GRAPH_VIEW flag provided by the user via +* stream->filter_mask. The value of the EVENT_VIEW flag in +* stream->filter_mask will be used instead. +*/ +int event_mask = kshark_ctx->filter_mask & ~KS_GRAPH_VIEW_FILTER_MASK ; + + e->visible &= ~event_mask; +} +void kshark_filter_entries (struct kshark_context *kshark_ctx,struct kshark_entry **data,size_t n_entries);
@@ -995,6 +1003,12 @@ struct kshark_config_doc *kshark_open_config_file(const char *file_name,struct kshark_config_doc *kshark_json_to_conf (struct json_object *jobj); +bool kshark_data_matrix_alloc (size_t n_rows,int16_t **event_array, +int16_t **cpu_array, +int32_t **pid_array, +int64_t **offset_array, +int64_t **ts_array); + #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
PATCH v8 16/44 kernel-shark: Add stream interface for trace-cmd data
In reply to Yordan Karadzhov (VMware)Here we provide an implementation of the Data stream interface that will process the trace-cmd (Ftrace) data. This can be considered the most essential change in the transformation of the C API towards version 2. However, for the moment we only have stand alone definitions that are not made functional yet. The actual integration with the API will be introduced in the following patches.
--- src/CMakeLists.txt | 1 + src/libkshark-tepdata.c | 1512 +++++++++++++++++++++++++++++++++++++++ src/libkshark-tepdata.h | 63 ++ 3 files changed, 1576 insertions(+) create mode 100644 src/libkshark-tepdata.c create mode 100644 src/libkshark-tepdata.h
src/CMakeLists.txt +1 -0
@@ -7,6 +7,7 @@ add_library(kshark SHARED libkshark.c libkshark-hash.c libkshark-model.c libkshark-plugin.c + libkshark-tepdata.c libkshark-configio.c libkshark-collection.c)
src/libkshark-tepdata.c new file +1512 -0
1,512 lines not on this page · raw message
src/libkshark-tepdata.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 17/44 kernel-shark: Start introducing KernelShark 2.0
In reply to Yordan Karadzhov (VMware)This is the very first patch from a series of patches that will introduce KernelShark 2.0. The new version will take advantage of the definition of Data streams and will imply significant changes in the low level C API, used by the KernelShark GUI. As a consequence of the API modifications, significant changes are needed in every source file of the project. Because, we want to avoid having a huge and ugly single commit that will be extremely hard to review, we will introduce a regression. We will first disable the compilation of all sub-components of KernelShark, except the API itself. This is done by bypassing the search of the necessary third party components (OpenGL and Qt). Later we will introduce the changes of the API in several sub-steps and will re-enable one by one the modified components of the GUI.
--- CMakeLists.txt | 10 ++++---- build/deff.h.cmake | 14 ++--------- examples/CMakeLists.txt | 54 ++++++++++++++++++++--------------------- src/CMakeLists.txt | 6 ++--- 4 files changed, 37 insertions(+), 47 deletions(-)
CMakeLists.txt +5 -5
@@ -45,12 +45,12 @@ find_package(JSONC REQUIRED) find_package(Doxygen) -set(OpenGL_GL_PREFERENCE LEGACY) -find_package(OpenGL) -find_package(GLUT) +# set(OpenGL_GL_PREFERENCE LEGACY) +# find_package(OpenGL) +# find_package(GLUT) -find_package(Qt5Widgets 5.7.1) -find_package(Qt5Network) +# find_package(Qt5Widgets 5.7.1) +# find_package(Qt5Network) if (Qt5Widgets_FOUND) message(STATUS "Found Qt5Widgets: (version ${Qt5Widgets_VERSION})")
build/deff.h.cmake +2 -12
@@ -23,17 +23,7 @@ /** "pkexec" executable. */ #cmakedefine DO_AS_ROOT "@DO_AS_ROOT@" -#ifdef __cplusplus - - #include <QString> - - /** - * String containing semicolon-separated list of plugin names. - * The plugins to be loaded when KernelShark starts are tagged - * with "default". - */ - const QString plugins = "@PLUGINS@"; - -#endif /* __cplusplus */ +/** Semicolon-separated list of plugin names. */ +#define KS_BUILTIN_PLUGINS "@PLUGINS@" #endif // _KS_CONFIG_H
examples/CMakeLists.txt +27 -27
57 lines not on this page · raw message
src/CMakeLists.txt +3 -3
@@ -5,10 +5,10 @@ set(KS_INCLUDS_DESTINATION "${_INSTALL_PREFIX}/include/${KS_APP_NAME}") message(STATUS "libkshark") add_library(kshark SHARED libkshark.c libkshark-hash.c - libkshark-model.c +# libkshark-model.c libkshark-plugin.c libkshark-tepdata.c - libkshark-configio.c +# libkshark-configio.c libkshark-collection.c) target_link_libraries(kshark trace::cmd
@@ -134,7 +134,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) -add_subdirectory(plugins) +# add_subdirectory(plugins) find_program(DO_AS_ROOT pkexec)
Signature · 1 line
2.25.1
PATCH v8 18/44 kernel-shark: Start using data streams
In reply to Yordan Karadzhov (VMware)Here we switch to using the trace data readout, provided by the Data stream interface. The actual implementation of the new readout was done in the previous commits.
--- examples/dataload.c | 28 ++-- src/libkshark.c | 345 ++++++++++++++++++-------------------------- src/libkshark.h | 14 +- 3 files changed, 166 insertions(+), 221 deletions(-)
examples/dataload.c +11 -17
@@ -19,8 +19,7 @@ int main(int argc, char **argv)struct kshark_entry **data =NULL ;ssize_t r, n_rows, n_tasks;char *entry_str; -bool status; -int *pids; +int sd, *pids;/* Create a new kshark session. */ kshark_ctx =NULL ;
@@ -29,30 +28,28 @@ int main(int argc, char **argv)/* Open a trace data file produced by trace-cmd. */ if (argc >1 ) - status =kshark_open (kshark_ctx, argv[1 ]); + sd =kshark_open (kshark_ctx, argv[1 ]);else - status =kshark_open (kshark_ctx, default_file); + sd =kshark_open (kshark_ctx, default_file); -if (!status) { +if (sd <0 ) {kshark_free (kshark_ctx);return 1 ; }/* Load the content of the file into an array of entries. */ - n_rows =kshark_load_data_entries (kshark_ctx, &data); + n_rows =kshark_load_entries (kshark_ctx, sd, &data);if (n_rows <1 ) {kshark_free (kshark_ctx);return 1 ; }/* Print to the screen the list of all tasks. */ - n_tasks =kshark_get_task_pids (kshark_ctx, &pids); + n_tasks =kshark_get_task_pids (kshark_ctx, sd, &pids);for (r =0 ; r < n_tasks; ++r) { -const char *task_str = -tep_data_comm_from_pid (kshark_ctx->pevent, - pids[r]); - +char *task_str =kshark_comm_from_pid (sd, pids[r]);printf ("task: %s-%i\n" , task_str, pids[r]); +free (task_str); }free (pids);
@@ -69,11 +66,8 @@ int main(int argc, char **argv)puts ("\n...\n" );/* Print the last 10 entries. */ -for (r = n_rows -10 ; r < n_rows; ++r) { - entry_str =kshark_dump_entry (data[r]); -puts (entry_str); -free (entry_str); - } +for (r = n_rows -10 ; r < n_rows; ++r) +kshark_print_entry (data[r]);/* Free the memory. */ for (r =0 ; r < n_rows; ++r)
@@ -82,7 +76,7 @@ int main(int argc, char **argv)free (data);/* Close the file. */ -kshark_close (kshark_ctx); +kshark_close (kshark_ctx, sd);/* Close the session. */ kshark_free (kshark_ctx);
src/libkshark.c +144 -201
446 lines not on this page · raw message
src/libkshark.h +11 -3
@@ -342,6 +342,9 @@ static inline char *kshark_set_data_format(char *dest_format,return strncpy (dest_format, src_format,KS_DATA_FORMAT_SIZE -1 ); } +/** Hard-coded default number of data streams available at initialization. */ +#define KS_DEFAULT_NUM_STREAMS 256 +/** Size of the task's hash table. */ #define KS_TASK_HASH_SHIFT 16#define KS_TASK_HASH_SIZE (1 << KS_TASK_HASH_SHIFT)
@@ -436,7 +439,9 @@ struct kshark_context {bool kshark_instance (struct kshark_context **kshark_ctx); -bool kshark_open (struct kshark_context *kshark_ctx,const char *file); +int kshark_open (struct kshark_context *kshark_ctx,const char *file); + +int kshark_stream_open (struct kshark_data_stream *stream,const char *file);int kshark_add_stream (struct kshark_context *kshark_ctx);
@@ -456,9 +461,12 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,ssize_t kshark_load_data_records (struct kshark_context *kshark_ctx,struct tep_record ***data_rows); -ssize_t kshark_get_task_pids (struct kshark_context *kshark_ctx,int **pids); +ssize_t kshark_get_task_pids (struct kshark_context *kshark_ctx,int sd, +int **pids); + +int kshark_close (struct kshark_context *kshark_ctx,int sd); -void kshark_close (struct kshark_context *kshark_ctx); +void kshark_close_all (struct kshark_context *kshark_ctx);void kshark_free (struct kshark_context *kshark_ctx);
Signature · 1 line
2.25.1
PATCH v8 19/44 kernel-shark: Remove dead code
In reply to Yordan Karadzhov (VMware)Clean up the old readout code that is no longer used after switching to the implementation provided by the Data stream interface.
--- src/libkshark.c | 825 +----------------------------------------------- src/libkshark.h | 70 +--- 2 files changed, 8 insertions(+), 887 deletions(-)
src/libkshark.c +7 -818
@@ -6,7 +6,7 @@/** * @file libkshark.c -* @brief API for processing of FTRACE (trace-cmd) data. +* @brief API for processing of tracing data. */ /** Use GNU C Library. */
@@ -21,8 +21,6 @@#include "libkshark.h" #include "libkshark-tepdata.h" -static __threadstruct trace_seq seq; -static struct kshark_context *kshark_context_handler =NULL ;static bool kshark_default_context (struct kshark_context **context)
@@ -35,6 +33,8 @@ static bool kshark_default_context(struct kshark_context **context) kshark_ctx->stream =calloc (KS_DEFAULT_NUM_STREAMS ,sizeof (*kshark_ctx->stream)); + kshark_ctx->stream_info.array_size =KS_DEFAULT_NUM_STREAMS ; + kshark_ctx->stream_info.max_stream_id =-1 ; kshark_ctx->event_handlers =NULL ; kshark_ctx->collections =NULL ;
@@ -65,14 +65,6 @@ static bool kshark_default_context(struct kshark_context **context)return true; } -static bool init_thread_seq (void ) -{ -if (!seq.buffer) -trace_seq_init (&seq); - -return seq.buffer !=NULL ; -} -/** * @brief Initialize a kshark session. This function must be called before * calling any other kshark function. If the session has been
@@ -109,9 +101,6 @@ bool kshark_instance(struct kshark_context **kshark_ctx) } } -if (!init_thread_seq ()) -return false; -return true; }
@@ -478,19 +467,10 @@ int kshark_close(struct kshark_context *kshark_ctx, int sd)*/ void kshark_close_all (struct kshark_context *kshark_ctx) { -int i, *stream_ids, n_streams; - - stream_ids =kshark_all_streams (kshark_ctx); - -/* -* Get a copy of shark_ctx->n_streams befor you start closing. Be aware -* that kshark_close() will decrement shark_ctx->n_streams. -*/ - n_streams = kshark_ctx->n_streams; -for (i =0 ; i < n_streams; ++i) -kshark_close (kshark_ctx, stream_ids[i]); +int i; -free (stream_ids); +for (i =0 ; i <= kshark_ctx->stream_info.max_stream_id; ++i) +kshark_close (kshark_ctx, i); }/**
@@ -1014,42 +994,6 @@ ssize_t kshark_load_matrix(struct kshark_context *kshark_ctx, int sd,return -EFAULT ; } -static struct kshark_task_list * -kshark_find_task (struct kshark_context *kshark_ctx,uint32_t key,int pid) -{ -struct kshark_task_list *list; - -for (list = kshark_ctx->tasks[key]; list; list = list->next) { -if (list->pid == pid) -return list; - } - -return NULL ; -} - -static struct kshark_task_list * -kshark_add_task (struct kshark_context *kshark_ctx,int pid) -{ -struct kshark_task_list *list; -uint32_t key; - - key =tracecmd_quick_hash (pid,KS_TASK_HASH_SHIFT ); - - list =kshark_find_task (kshark_ctx, key, pid); -if (list) -return list; - - list =malloc (sizeof (*list)); -if (!list) -return NULL ; - - list->pid = pid; - list->next = kshark_ctx->tasks[key]; - kshark_ctx->tasks[key] = list; - -return list; -} -/** * @brief Get an array containing the Process Ids of all tasks presented in * the loaded trace data file.
@@ -1217,7 +1161,7 @@ static void set_all_visible(uint16_t *v) {* are filtered-out. * WARNING: Do not use this function if the advanced filter is set. * Applying the advanced filter requires access to prevent_record, -* hence the data has to be reloaded using kshark_load_data_entries(). +* hence the data has to be reloaded using kshark_load_entries(). * * @param kshark_ctx: Input location for the session context pointer. * @param data: Input location for the trace data to be filtered.
@@ -1278,400 +1222,6 @@ void kshark_clear_all_filters(struct kshark_context *kshark_ctx,set_all_visible (&data[i]->visible); } -static void kshark_set_entry_values (struct kshark_context *kshark_ctx, -struct tep_record *record, -struct kshark_entry *entry) -{ -/* Offset of the record */ - entry->offset = record->offset; - -/* CPU Id of the record */ - entry->cpu = record->cpu; - -/* Time stamp of the record */ - entry->ts = record->ts; - -/* Event Id of the record */ - entry->event_id =tep_data_type (kshark_ctx->pevent, record); - -/* -* Is visible mask. This default value means that the entry -* is visible everywhere. -*/ - entry->visible =0xFF ; - -/* Process Id of the record */ - entry->pid =tep_data_pid (kshark_ctx->pevent, record); -} - -/** Prior time offset of the "missed_events" entry. */ -#define ME_ENTRY_TIME_SHIFT 10 - -static void missed_events_action (struct kshark_context *kshark_ctx, -struct tep_record *record, -struct kshark_entry *entry) -{ -/* -* Use the offset field of the entry to store the number of missed -* events. -*/ - entry->offset = record->missed_events; - - entry->cpu = record->cpu; - -/* -* Position the "missed_events" entry a bit before (in time) -* the original record. -*/ - entry->ts = record->ts -ME_ENTRY_TIME_SHIFT ; - -/* All custom entries must have negative event Identifiers. */ - entry->event_id =KS_EVENT_OVERFLOW ; - - entry->visible =0xFF ; - - entry->pid =tep_data_pid (kshark_ctx->pevent, record); -} - -static const char *missed_events_dump (struct kshark_context *kshark_ctx, -const struct kshark_entry *entry, -bool get_info) -{ -int size =0 ; -static char *buffer; - -if (get_info) - size =asprintf (&buffer,"missed_events=%i" , (int ) entry->offset); -else - size =asprintf (&buffer,"missed_events" ); -if (size >0 ) -return buffer; - -return NULL ; -} - -/** -* rec_list is used to pass the data to the load functions. -* The rec_list will contain the list of entries from the source, -* and will be a link list of per CPU entries. -*/ -struct rec_list { -union { -/* Used by kshark_load_data_records */ -struct { -/** next pointer, matches entry->next */ -struct rec_list *next; -/** pointer to the raw record data */ -struct tep_record *rec; - }; -/** entry - Used for kshark_load_data_entries() */ -struct kshark_entry entry; - }; -}; - -/** -* rec_type defines what type of rec_list is being used. -*/ -enum rec_type { -REC_RECORD , -REC_ENTRY , -}; - -static void free_rec_list (struct rec_list **rec_list,int n_cpus, -enum rec_type type) -{ -struct rec_list *temp_rec; -int cpu; - -for (cpu =0 ; cpu < n_cpus; ++cpu) { -while (rec_list[cpu]) { - temp_rec = rec_list[cpu]; - rec_list[cpu] = temp_rec->next; -if (type ==REC_RECORD ) -tracecmd_free_record (temp_rec->rec); -free (temp_rec); - } - } -free (rec_list); -} - -static ssize_t get_records (struct kshark_context *kshark_ctx, -struct rec_list ***rec_list,enum rec_type type) -{ -struct kshark_event_handler *evt_handler; -struct tep_event_filter *adv_filter; -struct kshark_task_list *task; -struct tep_record *rec; -struct rec_list **temp_next; -struct rec_list **cpu_list; -struct rec_list *temp_rec; -size_t count, total =0 ; -int n_cpus; -int pid; -int cpu; - - n_cpus =tep_get_cpus (kshark_ctx->pevent); - cpu_list =calloc (n_cpus,sizeof (*cpu_list)); -if (!cpu_list) -return -ENOMEM ; - -/* Just to shorten the name */ -if (type ==REC_ENTRY ) - adv_filter = kshark_ctx->advanced_event_filter; - -for (cpu =0 ; cpu < n_cpus; ++cpu) { - count =0 ; - cpu_list[cpu] =NULL ; - temp_next = &cpu_list[cpu]; - - rec =tracecmd_read_cpu_first (kshark_ctx->handle, cpu); -while (rec) { - *temp_next = temp_rec =calloc (1 ,sizeof (*temp_rec)); -if (!temp_rec) - goto fail; - - temp_rec->next =NULL ; - -switch (type) { -case REC_RECORD : - temp_rec->rec = rec; - pid =tep_data_pid (kshark_ctx->pevent, rec); -break ; -case REC_ENTRY : { -struct kshark_entry *entry; -int ret; - -if (rec->missed_events) { -/* -* Insert a custom "missed_events" entry just -* befor this record. -*/ - entry = &temp_rec->entry; -missed_events_action (kshark_ctx, rec, entry); - - temp_next = &temp_rec->next; - ++count; - -/* Now allocate a new rec_list node and comtinue. */ - *temp_next = temp_rec =calloc (1 ,sizeof (*temp_rec)); - } - - entry = &temp_rec->entry; -kshark_set_entry_values (kshark_ctx, rec, entry); - -/* Execute all plugin-provided actions (if any). */ - evt_handler = kshark_ctx->event_handlers; -while ((evt_handler =kshark_find_event_handler (evt_handler, - entry->event_id))) { - evt_handler->event_func (kshark_ctx, rec, entry); - evt_handler = evt_handler->next; - entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK ; - } - - pid = entry->pid; -/* Apply event filtering. */ - ret =FILTER_MATCH ; -if (adv_filter->filters) - ret =tep_filter_match (adv_filter, rec); - -if (!kshark_show_event (kshark_ctx, entry->event_id) || - ret !=FILTER_MATCH ) { -unset_event_filter_flag (kshark_ctx, entry); - } - -/* Apply CPU filtering. */ -if (!kshark_show_cpu (kshark_ctx, entry->pid)) { - entry->visible &= ~kshark_ctx->filter_mask; - } - -/* Apply task filtering. */ -if (!kshark_show_task (kshark_ctx, entry->pid)) { - entry->visible &= ~kshark_ctx->filter_mask; - } -tracecmd_free_record (rec); -break ; - }/* REC_ENTRY */ - } - - task =kshark_add_task (kshark_ctx, pid); -if (!task) { -tracecmd_free_record (rec); - goto fail; - } - - temp_next = &temp_rec->next; - - ++count; - rec =tracecmd_read_data (kshark_ctx->handle, cpu); - } - - total += count; - } - - *rec_list = cpu_list; -return total; - - fail: -free_rec_list (cpu_list, n_cpus, type); -return -ENOMEM ; -} - -static int pick_next_cpu (struct rec_list **rec_list,int n_cpus, -enum rec_type type) -{ -uint64_t ts =0 ; -uint64_t rec_ts; -int next_cpu =-1 ; -int cpu; - -for (cpu =0 ; cpu < n_cpus; ++cpu) { -if (!rec_list[cpu]) -continue ; - -switch (type) { -case REC_RECORD : - rec_ts = rec_list[cpu]->rec->ts; -break ; -case REC_ENTRY : - rec_ts = rec_list[cpu]->entry.ts; -break ; - } -if (!ts || rec_ts < ts) { - ts = rec_ts; - next_cpu = cpu; - } - } - -return next_cpu; -} - -/** -* @brief Load the content of the trace data file into an array of -* kshark_entries. This function provides an abstraction of the -* entries from the raw data that is read, however the "latency" -* and the "info" fields can be accessed only via the offset -* into the file. This makes the access to these two fields much -* slower. -* If one or more filters are set, the "visible" fields of each entry -* is updated according to the criteria provided by the filters. The -* field "filter_mask" of the session's context is used to control the -* level of visibility/invisibility of the filtered entries. -* -* @param kshark_ctx: Input location for context pointer. -* @param data_rows: Output location for the trace data. The user is -* responsible for freeing the elements of the outputted -* array. -* -* @returns The size of the outputted data in the case of success, or a -* negative error code on failure. -*/ -ssize_t kshark_load_data_entries (struct kshark_context *kshark_ctx, -struct kshark_entry ***data_rows) -{ -struct kshark_entry **rows; -struct rec_list **rec_list; -enum rec_type type =REC_ENTRY ; -ssize_t count, total =0 ; -int n_cpus; - -if (*data_rows) -free (*data_rows); - - total =get_records (kshark_ctx, &rec_list, type); -if (total <0 ) - goto fail; - - n_cpus =tep_get_cpus (kshark_ctx->pevent); - - rows =calloc (total,sizeof (struct kshark_entry *)); -if (!rows) - goto fail_free; - -for (count =0 ; count < total; count++) { -int next_cpu; - - next_cpu =pick_next_cpu (rec_list, n_cpus, type); - -if (next_cpu >=0 ) { - rows[count] = &rec_list[next_cpu]->entry; - rec_list[next_cpu] = rec_list[next_cpu]->next; - } - } - -free_rec_list (rec_list, n_cpus, type); - *data_rows = rows; -return total; - - fail_free: -free_rec_list (rec_list, n_cpus, type); - - fail: -fprintf (stderr,"Failed to allocate memory during data loading.\n" ); -return -ENOMEM ; -} - -/** -* @brief Load the content of the trace data file into an array of -* tep_records. Use this function only if you need fast access -* to all fields of the record. -* -* @param kshark_ctx: Input location for the session context pointer. -* @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 -* negative error code on failure. -*/ -ssize_t kshark_load_data_records (struct kshark_context *kshark_ctx, -struct tep_record ***data_rows) -{ -struct tep_record **rows; -struct tep_record *rec; -struct rec_list **rec_list; -struct rec_list *temp_rec; -enum rec_type type =REC_RECORD ; -ssize_t count, total =0 ; -int n_cpus; - - total =get_records (kshark_ctx, &rec_list, type); -if (total <0 ) - goto fail; - - n_cpus =tep_get_cpus (kshark_ctx->pevent); - - rows =calloc (total,sizeof (struct tep_record *)); -if (!rows) - goto fail_free; - -for (count =0 ; count < total; count++) { -int next_cpu; - - next_cpu =pick_next_cpu (rec_list, n_cpus, type); - -if (next_cpu >=0 ) { - rec = rec_list[next_cpu]->rec; - rows[count] = rec; - - temp_rec = rec_list[next_cpu]; - rec_list[next_cpu] = rec_list[next_cpu]->next; -free (temp_rec); -/* The record is still referenced in rows */ - } - } - -/* There should be no records left in rec_list */ -free_rec_list (rec_list, n_cpus, type); - *data_rows = rows; -return total; - - fail_free: -free_rec_list (rec_list, n_cpus, type); - - fail: -fprintf (stderr,"Failed to allocate memory during data loading.\n" ); -return -ENOMEM ; -} -static inline void free_ptr (void *ptr) {if (ptr)
@@ -1743,294 +1293,6 @@ bool kshark_data_matrix_alloc(size_t n_rows, int16_t **event_array,return false; } -static const char *get_latency (struct tep_handle *pe, -struct tep_record *record) -{ -if (!record) -return NULL ; - -trace_seq_reset (&seq); -tep_print_event (pe, &seq, record,"%s" ,TEP_PRINT_LATENCY ); -return seq.buffer; -} - -static const char *get_info (struct tep_handle *pe, -struct tep_record *record, -struct tep_event *event) -{ -char *pos; - -if (!record || !event) -return NULL ; - -trace_seq_reset (&seq); -tep_print_event (pe, &seq, record,"%s" ,TEP_PRINT_INFO ); - -/* -* The event info string contains a trailing newline. -* Remove this newline. -*/ -if ((pos =strchr (seq.buffer,'\n' )) !=NULL ) - *pos ='\0' ; - -return seq.buffer; -} - -/** -* @brief This function allows for an easy access to the original value of the -* Process Id as recorded in the tep_record object. The record is read -* from the file only in the case of an entry being touched by a plugin. -* Be aware that using the kshark_get_X_easy functions can be -* inefficient if you need an access to more than one of the data fields -* of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns The original value of the Process Id as recorded in the -* tep_record object on success, otherwise negative error code. -*/ -int kshark_get_pid_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -struct tep_record *data; -int pid; - -if (!kshark_instance (&kshark_ctx)) -return -ENODEV ; - -if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) { - pid = entry->pid; - }else { -/* -* The entry has been touched by a plugin callback function. -* Because of this we do not trust the value of "entry->pid". -* -* Currently the data reading operations are not thread-safe. -* Use a mutex to protect the access. -*/ -pthread_mutex_lock (&kshark_ctx->input_mutex); - - data =tracecmd_read_at (kshark_ctx->handle, entry->offset, -NULL ); - pid =tep_data_pid (kshark_ctx->pevent, data); -tracecmd_free_record (data); - -pthread_mutex_unlock (&kshark_ctx->input_mutex); - } - -return pid; -} - -/** -* @brief This function allows for an easy access to the original value of the -* Task name as recorded in the tep_record object. The record is read -* from the file only in the case of an entry being touched by a plugin. -* Be aware that using the kshark_get_X_easy functions can be -* inefficient if you need an access to more than one of the data fields -* of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns The original name of the task, retrieved from the Process Id -* recorded in the tep_record object on success, otherwise NULL. -*/ -const char *kshark_get_task_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -int pid =kshark_get_pid_easy (entry); - -if (pid <0 ) -return NULL ; - -kshark_instance (&kshark_ctx); -return tep_data_comm_from_pid (kshark_ctx->pevent, pid); -} - -/** -* @brief This function allows for an easy access to the latency information -* recorded in the tep_record object. The record is read from the file -* using the offset field of kshark_entry. Be aware that using the -* kshark_get_X_easy functions can be inefficient if you need an access -* to more than one of the data fields of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns On success the function returns a string showing the latency -* information, coded into 5 fields: -* interrupts disabled, need rescheduling, hard/soft interrupt, -* preempt count and lock depth. On failure it returns NULL. -*/ -const char *kshark_get_latency_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -struct tep_record *data; -const char *lat; - -if (!kshark_instance (&kshark_ctx)) -return NULL ; - -if (entry->event_id <0 ) -return NULL ; - -/* -* Currently the data reading operations are not thread-safe. -* Use a mutex to protect the access. -*/ -pthread_mutex_lock (&kshark_ctx->input_mutex); - - data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); - lat =get_latency (kshark_ctx->pevent, data); -tracecmd_free_record (data); - -pthread_mutex_unlock (&kshark_ctx->input_mutex); - -return lat; -} - -/** -* @brief This function allows for an easy access to the original value of the -* Event Id as recorded in the tep_record object. The record is read -* from the file only in the case of an entry being touched by a plugin. -* Be aware that using the kshark_get_X_easy functions can be -* inefficient if you need an access to more than one of the data fields -* of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns The original value of the Event Id as recorded in the -* tep_record object on success, otherwise negative error code. -*/ -int kshark_get_event_id_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -struct tep_record *data; -int event_id; - -if (!kshark_instance (&kshark_ctx)) -return -ENODEV ; - -if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) { - event_id = entry->event_id; - }else { -/* -* The entry has been touched by a plugin callback function. -* Because of this we do not trust the value of -* "entry->event_id". -* -* Currently the data reading operations are not thread-safe. -* Use a mutex to protect the access. -*/ -pthread_mutex_lock (&kshark_ctx->input_mutex); - - data =tracecmd_read_at (kshark_ctx->handle, entry->offset, -NULL ); - event_id =tep_data_type (kshark_ctx->pevent, data); -tracecmd_free_record (data); - -pthread_mutex_unlock (&kshark_ctx->input_mutex); - } - -return (event_id ==-1 )? -EFAULT : event_id; -} - -/** -* @brief This function allows for an easy access to the original name of the -* trace event as recorded in the tep_record object. The record is read -* from the file only in the case of an entry being touched by a plugin. -* Be aware that using the kshark_get_X_easy functions can be -* inefficient if you need an access to more than one of the data fields -* of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns The mane of the trace event recorded in the tep_record object on -* success, otherwise "[UNKNOWN EVENT]" or NULL. -*/ -const char *kshark_get_event_name_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -struct tep_event *event; - -int event_id =kshark_get_event_id_easy (entry); -if (event_id == -EFAULT ) -return NULL ; - -kshark_instance (&kshark_ctx); - -if (event_id <0 ) { -switch (event_id) { -case KS_EVENT_OVERFLOW : -return missed_events_dump (kshark_ctx, entry, false); -default : -return NULL ; - } - } - -/* -* Currently the data reading operations are not thread-safe. -* Use a mutex to protect the access. -*/ -pthread_mutex_lock (&kshark_ctx->input_mutex); - event =tep_find_event (kshark_ctx->pevent, event_id); -pthread_mutex_unlock (&kshark_ctx->input_mutex); - -if (event) -return event->name; - -return "[UNKNOWN EVENT]" ; -} - -/** -* @brief This function allows for an easy access to the tep_record's info -* streang. The record is read from the file using the offset field of -* kshark_entry. Be aware that using the kshark_get_X_easy functions can -* be inefficient if you need an access to more than one of the data -* fields of the record. -* -* @param entry: Input location for the KernelShark entry. -* -* @returns A string showing the data output of the trace event on success, -* otherwise NULL. -*/ -const char *kshark_get_info_easy (struct kshark_entry *entry) -{ -struct kshark_context *kshark_ctx =NULL ; -struct tep_event *event; -struct tep_record *data; -const char *info =NULL ; -int event_id; - -if (!kshark_instance (&kshark_ctx)) -return NULL ; - -if (entry->event_id <0 ) { -switch (entry->event_id) { -case KS_EVENT_OVERFLOW : -return missed_events_dump (kshark_ctx, entry, true); -default : -return NULL ; - } - } - -/* -* Currently the data reading operations are not thread-safe. -* Use a mutex to protect the access. -*/ -pthread_mutex_lock (&kshark_ctx->input_mutex); - - data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); - event_id =tep_data_type (kshark_ctx->pevent, data); - event =tep_find_event (kshark_ctx->pevent, event_id); -if (event) - info =get_info (kshark_ctx->pevent, data, event); - -tracecmd_free_record (data); - -pthread_mutex_unlock (&kshark_ctx->input_mutex); - -return info; -} -/** * @brief Convert the timestamp of the trace record (nanosecond precision) into * seconds and microseconds.
@@ -2047,43 +1309,6 @@ void kshark_convert_nano(uint64_t time, uint64_t *sec, uint64_t *usec) *usec = (time - s *1000000000ULL ) /1000 ; } -/** -* @brief Dump into a string the content a custom entry. The function allocates -* a null terminated string and returns a pointer to this string. -* -* @param kshark_ctx: Input location for the session context pointer. -* @param entry: A Kernel Shark entry to be printed. -* @param info_func: -* -* @returns The returned string contains a semicolon-separated list of data -* fields. The user has to free the returned string. -*/ -char *kshark_dump_custom_entry (struct kshark_context *kshark_ctx, -const struct kshark_entry *entry, -kshark_custom_info_func info_func) -{ -const char *event_name, *task, *info; -char *entry_str; -int size =0 ; - - task =tep_data_comm_from_pid (kshark_ctx->pevent, entry->pid); - event_name =info_func (kshark_ctx, entry, false); - info =info_func (kshark_ctx, entry, true); - - size =asprintf (&entry_str,"%" PRIu64"; %s-%i; CPU %i; ; %s; %s" , - entry->ts, - task, - entry->pid, - entry->cpu, - event_name, - info); - -if (size >0 ) -return entry_str; - -return NULL ; -} -/** * @brief Binary search inside a time-sorted array of kshark_entries. *
@@ -2120,42 +1345,6 @@ ssize_t kshark_find_entry_by_time(uint64_t time,return h; } -/** -* @brief Binary search inside a time-sorted array of tep_records. -* -* @param time: The value of time to search for. -* @param data: Input location for the trace data. -* @param l: Array index specifying the lower edge of the range to search in. -* @param h: Array index specifying the upper edge of the range to search in. -* -* @returns On success, the first tep_record inside the range, having a -timestamp equal or bigger than "time". -If all entries inside the range have timestamps greater than "time" -the function returns BSEARCH_ALL_GREATER (negative value). -If all entries inside the range have timestamps smaller than "time" -the function returns BSEARCH_ALL_SMALLER (negative value). -*/ -ssize_t kshark_find_record_by_time (uint64_t time, -struct tep_record **data, -size_t l,size_t h) -{ -size_t mid; - -if (data[l]->ts > time) -return BSEARCH_ALL_GREATER ; - -if (data[h]->ts < time) -return BSEARCH_ALL_SMALLER ; - -/* -* After executing the BSEARCH macro, "l" will be the index of the last -* record having timestamp < time and "h" will be the index of the -* first record having timestamp >= time. -*/ -BSEARCH (h, l, data[mid]->ts < time); -return h; -} -/** * @brief Simple Pid matching function to be user for data requests. *
src/libkshark.h +1 -69
124 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 20/44 kernel-shark: Redesign the plugin interface
In reply to Yordan Karadzhov (VMware)This patch can be treated as an almost complete rewrite of the way the C API of KernelShark deals with plugins. First of all, the two pluggable user actions (one executed during data loading and another executed during plotting) have separate handlers. This way the user can register only one of the two callback functions, if this is what is needed.
The second substantial change is that instead of having a single interface for loading the plugin, we now have 3 different interfaces. The one that exists in version 1 of KernelShark is now renamed to Data Processing Interface (dpi).
The first new interface for loading can be used to register user provided implementation of the Data stream readout and is called Data Readout Interface (dri). Via this plugin loading interface the user can open trace data having an arbitrary format. In order to make this possible the user has to provide a plugin that contains an implementation of the data readout methods defined by the kshark_data_stream_interface and to register all those methods.
The second new plugin loading interface is called Control interface and can be used to provide the plugin with an access to the GUI's Main window object. Via this interface the plugin can became capable to modify the GUI. Such a modification for example can be to add new dialog to the menus or to change the state of the GUI (to select entry 1with the marker, to zoom, ...).
--- src/libkshark-plugin.c | 658 +++++++++++++++++++++++++++++++++++------ src/libkshark-plugin.h | 294 ++++++++++++++---- src/libkshark.c | 48 ++- src/libkshark.h | 28 +- 4 files changed, 866 insertions(+), 162 deletions(-)
src/libkshark-plugin.c +562 -96
@@ -1,7 +1,7 @@// SPDX-License-Identifier: LGPL-2.1 /* -* Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> +* Copyright (C) 2017 VMware Inc, Yordan Karadzhov (VMware) <[email protected]> */ /**
@@ -13,8 +13,7 @@#ifndef _GNU_SOURCE/** Use GNU C Library. */ #define _GNU_SOURCE - -#endif +#endif // _GNU_SOURCE #include <stdio.h> #include <stdlib.h>
@@ -25,25 +24,39 @@// KernelShark #include "libkshark-plugin.h" +#include "libkshark-tepdata.h" #include "libkshark.h" -static struct kshark_event_handler * -gui_event_handler_alloc (int event_id, -kshark_plugin_event_handler_func evt_func, -kshark_plugin_draw_handler_func dw_func) +static struct kshark_event_proc_handler * +data_event_handler_alloc (int event_id, +kshark_plugin_event_handler_func evt_func) { -struct kshark_event_handler *handler =malloc (sizeof (*handler)); +struct kshark_event_proc_handler *handler =malloc (sizeof (*handler));if (!handler) { -fprintf (stderr, -"failed to allocate memory for gui eventhandler" ); +fputs ("failed to allocate memory for event handler\n" , stderr);return NULL ; } handler->next =NULL ; handler->id = event_id; handler->event_func = evt_func; - handler->draw_func = dw_func; + +return handler; +} + +static struct kshark_draw_handler * +data_draw_handler_alloc (kshark_plugin_draw_handler_func draw_func) +{ +struct kshark_draw_handler *handler =malloc (sizeof (*handler)); + +if (!handler) { +fputs ("failed to allocate memory for draw handler\n" , stderr); +return NULL ; + } + + handler->next =NULL ; + handler->draw_func = draw_func;return handler; }
@@ -55,8 +68,8 @@ gui_event_handler_alloc(int event_id,* @param handlers: Input location for the Event handler list. * @param event_id: Event Id to search for. */ -struct kshark_event_handler * -kshark_find_event_handler (struct kshark_event_handler *handlers,int event_id) +struct kshark_event_proc_handler * +kshark_find_event_handler (struct kshark_event_proc_handler *handlers,int event_id) {for (; handlers; handlers = handlers->next)if (handlers->id == event_id)
@@ -68,26 +81,25 @@ kshark_find_event_handler(struct kshark_event_handler *handlers, int event_id)/** * @brief Add new event handler to an existing list of handlers. * -* @param handlers: Input location for the Event handler list. +* @param stream: Input location for a Trace data stream pointer. * @param event_id: Event Id. * @param evt_func: Input location for an Event action provided by the plugin. -* @param dw_func: Input location for a Draw action provided by the plugin. * * @returns Zero on success, or a negative error code on failure. */ -int kshark_register_event_handler (struct kshark_event_handler **handlers, +int kshark_register_event_handler (struct kshark_data_stream *stream,int event_id, -kshark_plugin_event_handler_func evt_func, -kshark_plugin_draw_handler_func dw_func) +kshark_plugin_event_handler_func evt_func) { -struct kshark_event_handler *handler = -gui_event_handler_alloc (event_id, evt_func, dw_func); +struct kshark_event_proc_handler *handler = +data_event_handler_alloc (event_id, evt_func);if (!handler)return -ENOMEM ; - handler->next = *handlers; - *handlers = handler; + handler->next = stream->event_handlers; + stream->event_handlers = handler; +return 0 ; }
@@ -95,30 +107,29 @@ int kshark_register_event_handler(struct kshark_event_handler **handlers,* @brief Search the list for a specific plugin handle. If such a plugin handle * exists, unregister (remove and free) this handle from the list. * -* @param handlers: Input location for the Event handler list. +* @param stream: Input location for a Trace data stream pointer. * @param event_id: Event Id of the plugin handler to be unregistered. -* @param evt_func: Event action function of the handler to be unregistered. -* @param dw_func: Draw action function of the handler to be unregistered. +* @param evt_func: Event action function to be unregistered. */ -void kshark_unregister_event_handler (struct kshark_event_handler **handlers, -int event_id, -kshark_plugin_event_handler_func evt_func, -kshark_plugin_draw_handler_func dw_func) +int kshark_unregister_event_handler (struct kshark_data_stream *stream, +int event_id, +kshark_plugin_event_handler_func evt_func) { -struct kshark_event_handler **last; +struct kshark_event_proc_handler **last; -for (last = handlers; *last; last = &(*last)->next) { +for (last = &stream->event_handlers; *last; last = &(*last)->next) {if ((*last)->id == event_id && - (*last)->event_func == evt_func && - (*last)->draw_func == dw_func) { -struct kshark_event_handler *this_handler; + (*last)->event_func == evt_func) { +struct kshark_event_proc_handler *this_handler; this_handler = *last; *last = this_handler->next;free (this_handler); -return ; +return 0 ; } } + +return -EFAULT ; }/**
@@ -126,9 +137,9 @@ void kshark_unregister_event_handler(struct kshark_event_handler **handlers,* * @param handlers: Input location for the Event handler list. */ -void kshark_free_event_handler_list (struct kshark_event_handler *handlers) +void kshark_free_event_handler_list (struct kshark_event_proc_handler *handlers) { -struct kshark_event_handler *last; +struct kshark_event_proc_handler *last;while (handlers) { last = handlers;
@@ -137,98 +148,255 @@ void kshark_free_event_handler_list(struct kshark_event_handler *handlers) } } +/** +* @brief Add new event handler to an existing list of handlers. +* +* @param stream: Input location for a Trace data stream pointer. +* @param draw_func: Input location for a Draw action provided by the plugin. +* +* @returns Zero on success, or a negative error code on failure. +*/ +int kshark_register_draw_handler (struct kshark_data_stream *stream, +kshark_plugin_draw_handler_func draw_func) +{ +struct kshark_draw_handler *handler =data_draw_handler_alloc (draw_func); + +if (!handler) +return -ENOMEM ; + + handler->next = stream->draw_handlers; + stream->draw_handlers = handler; + +return 0 ; +} + +/** +* @brief Search the list for a specific plugin handle. If such a plugin handle +* exists, unregister (remove and free) this handle from the list. +* +* @param stream: Input location for a Trace data stream pointer. +* @param draw_func: Draw action function to be unregistered. +*/ +void kshark_unregister_draw_handler (struct kshark_data_stream *stream, +kshark_plugin_draw_handler_func draw_func) +{ +struct kshark_draw_handler **last; + +for (last = &stream->draw_handlers; *last; last = &(*last)->next) { +if ((*last)->draw_func == draw_func) { +struct kshark_draw_handler *this_handler; + this_handler = *last; + *last = this_handler->next; +free (this_handler); + +return ; + } + } +} + +/** +* @brief Free all DRaw handlers in a given list. +* +* @param handlers: Input location for the Draw handler list. +*/ +void kshark_free_draw_handler_list (struct kshark_draw_handler *handlers) +{ +struct kshark_draw_handler *last; + +while (handlers) { + last = handlers; + handlers = handlers->next; +free (last); + } +} + +/** Close and free this plugin. */ +static void free_plugin (struct kshark_plugin_list *plugin) +{ +dlclose (plugin->handle); + +if (plugin->process_interface){ +free (plugin->process_interface->name); +free (plugin->process_interface); + } + +if (plugin->readout_interface) { +free (plugin->readout_interface->name); +free (plugin->readout_interface); + } + +free (plugin->name); +free (plugin->file); +free (plugin); +} +/** * @brief Allocate memory for a new plugin. Add this plugin to the list of -* plugins used by the session. +* plugins. * * @param kshark_ctx: Input location for the session context pointer. +* @param name: The name of the plugin to register. * @param file: The plugin object file to load. * -* @returns Zero on success, or a negative error code on failure. +* @returns The plugin object on success, or NULL on failure. */ -int kshark_register_plugin (struct kshark_context *kshark_ctx, -const char *file) +struct kshark_plugin_list * +kshark_register_plugin (struct kshark_context *kshark_ctx, +const char *name, +const char *file) { -struct kshark_plugin_list *plugin = kshark_ctx->plugins; +kshark_plugin_load_func init_func, close_func; +kshark_check_data_func check_func; +kshark_format_func format_func; +struct kshark_plugin_list *plugin;struct stat st;int ret; -while (plugin) { -if (strcmp (plugin->file, file) ==0 ) -return -EEXIST ; +printf ("loading plugin \"%s\" from %s\n" , name, file); - plugin = plugin->next; + plugin =kshark_find_plugin (kshark_ctx->plugins, file); +if (plugin) { +fputs ("the plugin is already loaded.\n" , stderr); +return NULL ; } ret =stat (file, &st);if (ret <0 ) { -fprintf (stderr,"plugin %s not found\n" , file); -return -ENODEV ; +fprintf (stderr,"plugin %s not found.\n" , file); +return NULL ; } - plugin =calloc (sizeof (struct kshark_plugin_list ),1 ); + plugin =calloc (1 ,sizeof (struct kshark_plugin_list ));if (!plugin) { -fprintf (stderr,"failed to allocate memory for plugin\n" ); -return -ENOMEM ; +fputs ("failed to allocate memory for plugin.\n" , stderr); +return NULL ; } -if (asprintf (&plugin->file,"%s" , file) <=0 ) { + plugin->handle =dlopen (file,RTLD_NOW |RTLD_GLOBAL ); +if (!plugin->handle) {fprintf (stderr, -"failed to allocate memory for plugin file name" ); -return -ENOMEM ; +"failed to open plugin file.\n%s\n" , +dlerror ()); + goto fail; } - plugin->handle =dlopen (plugin->file,RTLD_NOW |RTLD_GLOBAL ); -if (!plugin->handle) + plugin->file =strdup (file); + plugin->name =strdup (name); +if (!plugin->file|| !plugin->name) goto fail; - plugin->init =dlsym (plugin->handle, -KSHARK_PLUGIN_INITIALIZER_NAME ); + plugin->ctrl_interface = +dlsym (plugin->handle,KSHARK_MENU_PLUGIN_INITIALIZER_NAME ); + + init_func =dlsym (plugin->handle, +KSHARK_PLOT_PLUGIN_INITIALIZER_NAME ); + + close_func =dlsym (plugin->handle, +KSHARK_PLOT_PLUGIN_DEINITIALIZER_NAME ); + +if (init_func && close_func) { + plugin->process_interface = +calloc (1 ,sizeof (*plugin->process_interface)); + +if (!plugin->process_interface) + goto fail; + + plugin->process_interface->name =strdup (plugin->name); +if (!plugin->process_interface->name) + goto fail; + + plugin->process_interface->init = init_func; + plugin->process_interface->close = close_func; + }else if (init_func || close_func) { +fprintf (stderr, +"incomplete draw interface found (will be ignored).\n%s\n" , +dlerror ()); + } + + init_func =dlsym (plugin->handle, +KSHARK_INPUT_INITIALIZER_NAME ); + + close_func =dlsym (plugin->handle, +KSHARK_INPUT_DEINITIALIZER_NAME ); + + check_func =dlsym (plugin->handle, +KSHARK_INPUT_CHECK_NAME ); - plugin->close =dlsym (plugin->handle, -KSHARK_PLUGIN_DEINITIALIZER_NAME ); + format_func =dlsym (plugin->handle, +KSHARK_INPUT_FORMAT_NAME ); -if (!plugin->init || !plugin->close) +if (init_func && close_func && check_func && format_func) { + plugin->readout_interface = +calloc (1 ,sizeof (*plugin->readout_interface)); + +if (!plugin->readout_interface) + goto fail; + + plugin->readout_interface->name =strdup (plugin->name); +if (!plugin->readout_interface->name) + goto fail; + + plugin->readout_interface->init = init_func; + plugin->readout_interface->close = close_func; + plugin->readout_interface->check_data = check_func; + +kshark_set_data_format (plugin->readout_interface->data_format, +format_func ()); + +kshark_register_input (kshark_ctx, plugin->readout_interface); + }else if (init_func || close_func || check_func) { +fprintf (stderr, +"incomplete input interface found (will be ignored).\n%s\n" , +dlerror ()); + } + +if (!plugin->process_interface && + !plugin->readout_interface && + !plugin->ctrl_interface) { +fputs ("no interfaces found in this plugin.\n" , stderr); goto fail; + } plugin->next = kshark_ctx->plugins; kshark_ctx->plugins = plugin; + kshark_ctx->n_plugins++; -return 0 ; +return plugin; fail: -fprintf (stderr,"cannot load plugin '%s'\n%s\n" , - plugin->file,dlerror ()); +fprintf (stderr,"cannot load plugin '%s'\n" , file); -if (plugin->handle) { +if (plugin->handle)dlclose (plugin->handle); - plugin->handle =NULL ; - } -free (plugin); +free_plugin (plugin); -return EFAULT ; +return NULL ; }/** * @brief Unrgister a plugin. * -* @param kshark_ctx: Input location for context pointer. +* @param kshark_ctx: Input location for the session context pointer. +* @param name: The name of the plugin to unregister. * @param file: The plugin object file to unregister. */ void kshark_unregister_plugin (struct kshark_context *kshark_ctx, +const char *name,const char *file) {struct kshark_plugin_list **last;for (last = &kshark_ctx->plugins; *last; last = &(*last)->next) { -if (strcmp ((*last)->file, file) ==0 ) { +if (strcmp ((*last)->process_interface->name, name) ==0 && +strcmp ((*last)->file, file) ==0 ) {struct kshark_plugin_list *this_plugin; + this_plugin = *last; *last = this_plugin->next; +free_plugin (this_plugin); -dlclose (this_plugin->handle); -free (this_plugin); + kshark_ctx->n_plugins--;return ; }
@@ -248,48 +416,346 @@ void kshark_free_plugin_list(struct kshark_plugin_list *plugins) last = plugins; plugins = plugins->next; -free (last->file); -dlclose (last->handle); +free_plugin (last); + } +} + +/** +* @brief Register a data readout interface (input). +* +* @param kshark_ctx: Input location for the context pointer. +* @param plugin: Input location for the data readout interface (input). +*/ +struct kshark_dri_list * +kshark_register_input (struct kshark_context *kshark_ctx, +struct kshark_dri *plugin) +{ +struct kshark_dri_list *input; +struct kshark_dri_list **last; +const char *name_err, *format_err; + +if (strcmp (plugin->data_format,TEP_DATA_FORMAT_IDENTIFIER ) ==0 ) { + name_err ="built in" ; + format_err =TEP_DATA_FORMAT_IDENTIFIER ; + goto conflict; + } + +for (last = &kshark_ctx->inputs; *last; last = &(*last)->next) +if (strcmp ((*last)->interface->name, plugin->name) ==0 || +strcmp ((*last)->interface->data_format, plugin->data_format) ==0 ) { + name_err = (*last)->interface->name; + format_err = (*last)->interface->data_format; + goto conflict; + } + + input =calloc (1 ,sizeof (*input)); +if (!input) { +fputs ("failed to allocate memory for readout plugin.\n" , stderr); +return NULL ; + } + + input->interface = plugin; + input->next = kshark_ctx->inputs; + kshark_ctx->inputs = input; + +return input; + + conflict: +fprintf (stderr, +"Failed to register readout plugin (name=\'%s\', data_format=\'%s\')\n" , + plugin->name, plugin->data_format); + +fprintf (stderr, +"Conflict with registered readout (name=\'%s\', data_format=\'%s\')\n" , + name_err, format_err); + +return NULL ; +} + +/** +* @brief Unrgister a data readout interface (input). +* +* @param kshark_ctx: Input location for the context pointer. +* @param name: The data readout's name. +*/ +void kshark_unregister_input (struct kshark_context *kshark_ctx, +const char *name) +{ +struct kshark_dri_list **last; + +for (last = &kshark_ctx->inputs; *last; last = &(*last)->next) { +if (strcmp ((*last)->interface->name, name) ==0 ) { +struct kshark_dri_list *this_input; + this_input = *last; + *last = this_input->next; + +free (this_input); + +return ; + } + } +} +/** +* @brief Free a list of plugin interfaces. +* +* @param plugins: Input location for the plugins list. +*/ +void +kshark_free_dpi_list (struct kshark_dpi_list *plugins) +{ +struct kshark_dpi_list *last; + +while (plugins) { + last = plugins; + plugins = plugins->next;free (last); } }/** -* @brief Use this function to initialize/update/deinitialize all registered -* plugins. +* @brief Find a plugin by its library file. * -* @param kshark_ctx: Input location for context pointer. +* @param plugins: A list of plugins to search in. +* @param lib: The plugin object file to load. +* +* @returns The plugin object on success, or NULL on failure. +*/ +struct kshark_plugin_list * +kshark_find_plugin (struct kshark_plugin_list *plugins,const char *lib) +{ +for (; plugins; plugins = plugins->next) +if (strcmp (plugins->file, lib) ==0 ) +return plugins; + +return NULL ; +} + +/** +* @brief Find a plugin by its name. +* +* @param plugins: A list of plugins to search in. +* @param name: The plugin object file to load. +* +* @returns The plugin object on success, or NULL on failure. +*/ +struct kshark_plugin_list * +kshark_find_plugin_by_name (struct kshark_plugin_list *plugins, +const char *name) +{ +for (; plugins; plugins = plugins->next) +if (strcmp (plugins->name, name) ==0 ) +return plugins; + +return NULL ; +} + +/** +* @brief Register plugin to a given data stream without initializing it. +* In order to initialize this plugin use kshark_handle_dpi() or +* kshark_handle_all_dpis(). +* +* @param stream: Input location for a Trace data stream pointer. +* @param plugin: Input location for the data processing interface. +* @param active: If false, the plugin will be registered but disabled. +* Otherwise the plugin will be active. +* +* @returns The plugin object on success, or NULL on failure. +*/ +struct kshark_dpi_list * +kshark_register_plugin_to_stream (struct kshark_data_stream *stream, +struct kshark_dpi *plugin, +bool active) +{ +struct kshark_dpi_list *plugin_list = stream->plugins; + +/* Check if the plugin is already registered to this stream. */ +while (plugin_list) { +if (strcmp (plugin_list->interface->name, plugin->name) ==0 && + plugin_list->interface->init == plugin->init && + plugin_list->interface->close == plugin->close) { +/* +* The plugin has been registered already. Check if it +* is initialized and if this is the case, close the +* existing initialization. This way we guarantee a +* clean new initialization from. +*/ +if (plugin_list->status &KSHARK_PLUGIN_LOADED ) +kshark_handle_dpi (stream, plugin_list, +KSHARK_PLUGIN_CLOSE ); + + plugin_list->status = + active ?KSHARK_PLUGIN_ENABLED :0 ; + +return plugin_list; + } + + plugin_list = plugin_list->next; + } + + plugin_list =calloc (1 ,sizeof (*plugin_list)); + plugin_list->interface = plugin; + +if (active) + plugin_list->status =KSHARK_PLUGIN_ENABLED ; + + plugin_list->next = stream->plugins; + stream->plugins = plugin_list; + stream->n_plugins++; + +return plugin_list; +} + +/** +* @brief Unregister plugin to a given data stream. +* +* @param stream: Input location for a Trace data stream pointer. +* @param plugin: Input location for the data processing interface. +*/ +void kshark_unregister_plugin_from_stream (struct kshark_data_stream *stream, +struct kshark_dpi *plugin) +{ +struct kshark_dpi_list **last; + +for (last = &stream->plugins; *last; last = &(*last)->next) { +if ((*last)->interface->init == plugin->init && + (*last)->interface->close == plugin->close && +strcmp ((*last)->interface->name, plugin->name) ==0 ) { +struct kshark_dpi_list *this_plugin; + + this_plugin = *last; + *last = this_plugin->next; + this_plugin->interface->close (stream); +free (this_plugin); + + stream->n_plugins--; + +return ; + } + } +} + +static void plugin_init (struct kshark_data_stream *stream, +struct kshark_dpi_list *plugin) +{ +int handler_count = plugin->interface->init (stream); + +if (handler_count >0 ) { + plugin->status &= ~KSHARK_PLUGIN_FAILED ; + plugin->status |=KSHARK_PLUGIN_LOADED ; + }else { +if (strcmp (stream->name,KS_UNNAMED ) ==0 ) { +fprintf (stderr, +"plugin \"%s\" failed to initialize on stream %s\n" , + plugin->interface->name, + stream->file); + }else { +fprintf (stderr, +"plugin \"%s\" failed to initialize on stream %s:%s\n" , + plugin->interface->name, + stream->file, + stream->name); + } + + plugin->status |=KSHARK_PLUGIN_FAILED ; + plugin->status &= ~KSHARK_PLUGIN_LOADED ; + } +} + +static void plugin_close (struct kshark_data_stream *stream, +struct kshark_dpi_list *plugin) +{ + plugin->interface->close (stream); + plugin->status &= ~KSHARK_PLUGIN_LOADED ; +} + +/** +* @brief Use this function to initialize/update/deinitialize a plugin for +* a given Data stream. +* +* @param stream: Input location for a Trace data stream pointer. +* @param plugin: The plugin to be handled. * @param task_id: Action identifier specifying the action to be executed. * * @returns The number of successful added/removed plugin handlers on success, * or a negative error code on failure. */ -int kshark_handle_plugins (struct kshark_context *kshark_ctx, -enum kshark_plugin_actions task_id) +int kshark_handle_dpi (struct kshark_data_stream *stream, +struct kshark_dpi_list *plugin, +enum kshark_plugin_actions task_id) { -struct kshark_plugin_list *plugin;int handler_count =0 ; -for (plugin = kshark_ctx->plugins; plugin; plugin = plugin->next) { -switch (task_id) { -case KSHARK_PLUGIN_INIT : - handler_count += plugin->init (kshark_ctx); -break ; +switch (task_id) { +case KSHARK_PLUGIN_INIT : +if (plugin->status &KSHARK_PLUGIN_ENABLED ) +plugin_init (stream, plugin); -case KSHARK_PLUGIN_UPDATE : - plugin->close (kshark_ctx); - handler_count += plugin->init (kshark_ctx); -break ; +break ; -case KSHARK_PLUGIN_CLOSE : - handler_count += plugin->close (kshark_ctx); -break ; +case KSHARK_PLUGIN_UPDATE : +if (plugin->status &KSHARK_PLUGIN_LOADED ) +plugin_close (stream, plugin); -default : -return -EINVAL ; - } + plugin->status &= ~KSHARK_PLUGIN_FAILED ; + +if (plugin->status &KSHARK_PLUGIN_ENABLED ) +plugin_init (stream, plugin); + +break ; + +case KSHARK_PLUGIN_CLOSE : +if (plugin->status &KSHARK_PLUGIN_LOADED ) +plugin_close (stream, plugin); + + plugin->status &= ~KSHARK_PLUGIN_FAILED ; +break ; + +default : +return -EINVAL ; }return handler_count; } + +/** +* @brief Use this function to initialize/update/deinitialize all registered +* data processing plugins for a given Data stream. +* +* @param stream: Input location for a Trace data stream pointer. +* @param task_id: Action identifier specifying the action to be executed. Can +* be KSHARK_PLUGIN_INIT, KSHARK_PLUGIN_UPDATE or +* KSHARK_PLUGIN_CLOSE. +* +* @returns The number of successful added/removed plugin handlers on success, +* or a negative error code on failure. +*/ +int kshark_handle_all_dpis (struct kshark_data_stream *stream, +enum kshark_plugin_actions task_id) +{ +struct kshark_dpi_list *plugin; +int handler_count =0 ; + +for (plugin = stream->plugins; plugin; plugin = plugin->next) + handler_count += +kshark_handle_dpi (stream, plugin, task_id); + +return handler_count; +} + +/** +* @brief Free all readout interfaces in a given list. +* +* @param inputs: Input location for the inputs list. +*/ +void kshark_free_dri_list (struct kshark_dri_list *inputs) +{ +struct kshark_dri_list *last; + +while (inputs) { + last = inputs; + inputs = inputs->next; + +free (last); + } +}
src/libkshark-plugin.h +234 -60
380 lines not on this page · raw message
src/libkshark.c +47 -1
102 lines not on this page · raw message
src/libkshark.h +23 -5
@@ -272,9 +272,6 @@ struct kshark_generic_stream_interface {void *handle; }; -/** The limit in size of the data format identifier string. */ -#define KS_DATA_FORMAT_SIZE 15 -/** Data format identifier string indicating invalid data. */ #define KS_INVALID_DATA "invalid data"
@@ -327,6 +324,18 @@ struct kshark_data_stream {/** The type of the data. */ char data_format[KS_DATA_FORMAT_SIZE ]; +/** List of Plugin interfaces. */ +struct kshark_dpi_list *plugins; + +/** The number of plugins registered for this stream.*/ +int n_plugins; + +/** List of Plugin's Event handlers. */ +struct kshark_event_proc_handler *event_handlers; + +/** List of Plugin's Draw handlers. */ +struct kshark_draw_handler *draw_handlers; +/** * The interface of methods used to operate over the data from a given * stream.
@@ -406,11 +415,17 @@ struct kshark_context {/** List of Data collections. */ struct kshark_entry_collection *collections; +/** List of data readout interfaces. */ +struct kshark_dri_list *inputs; + +/** The number of readout interfaces. */ +int n_inputs; +/** List of Plugins. */ struct kshark_plugin_list *plugins; -/** List of Plugin Event handlers. */ -struct kshark_event_handler *event_handlers; +/** The number of plugins. */ +int n_plugins; };bool kshark_instance (struct kshark_context **kshark_ctx);
@@ -587,6 +602,9 @@ void kshark_clear_all_filters(struct kshark_context *kshark_ctx,struct kshark_entry **data, size_t n_entries); +void kshark_plugin_actions (struct kshark_data_stream *stream, +void *record,struct kshark_entry *entry); +/** Search failed identifiers. */ enum kshark_search_failed {/** All entries have timestamps greater timestamps. */
Signature · 1 line
2.25.1
PATCH v8 21/44 kernel-shark: Complete the stream integration
In reply to Yordan Karadzhov (VMware)The patch contains a number various relatively small modifications needed in order to finalize the integration. Unfortunately those changes are hard to disentangle so we will do everything in a single patch.
--- examples/CMakeLists.txt | 8 +- examples/datafilter.c | 67 +++--- src/CMakeLists.txt | 1 + src/libkshark-collection.c | 121 ++++++++-- src/libkshark-tepdata.c | 391 ++++++++++++++++++++++++++++++++ src/libkshark-tepdata.h | 49 ++++ src/libkshark.c | 454 +++++++++++++++++++++++++------------ src/libkshark.h | 133 ++++++----- src/trace-filter-hash.h | 64 ------ 9 files changed, 959 insertions(+), 329 deletions(-) delete mode 100644 src/trace-filter-hash.h
examples/CMakeLists.txt +4 -4
@@ -4,10 +4,10 @@ message(STATUS "dataload") add_executable(dload dataload.c) target_link_libraries(dload kshark) -# message(STATUS "datafilter") -# add_executable(dfilter datafilter.c) -# target_link_libraries(dfilter kshark) -# +message(STATUS "datafilter") +add_executable(dfilter datafilter.c) +target_link_libraries(dfilter kshark) + # message(STATUS "datahisto") # add_executable(dhisto datahisto.c) # target_link_libraries(dhisto kshark)
examples/datafilter.c +34 -33
136 lines not on this page · raw message
src/CMakeLists.txt +1 -0
@@ -34,6 +34,7 @@ install(TARGETS kshark install(FILES "${KS_DIR}/src/libkshark.h" "${KS_DIR}/src/libkshark-model.h" "${KS_DIR}/src/libkshark-plugin.h" + "${KS_DIR}/src/libkshark-tepdata.h" DESTINATION ${KS_INCLUDS_DESTINATION} COMPONENT libkshark-devel)
src/libkshark-collection.c +96 -25
268 lines not on this page · raw message
src/libkshark-tepdata.c +391 -0
412 lines not on this page · raw message
src/libkshark-tepdata.h +49 -0
60 lines not on this page · raw message
src/libkshark.c +308 -146
620 lines not on this page · raw message
src/libkshark.h +76 -57
265 lines not on this page · raw message
src/trace-filter-hash.h deleted +0 -64
64 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 22/44 kernel-shark: Provide merging of multiple data streams
In reply to Yordan Karadzhov (VMware)The C API provides loading of the trace data in two different forms. The first one is an array of kshark_entries and is being used by the KernelShark GUI. The second is a matrix-like structure that has all the fields of the kshark_entry stored in separate arrays, forming the columns of the matrix. The second form of the data is used by trace-cruncher. In this patch we add methods for merging of several data streams into a single data set. Both kshark_entries and matrix forms of the data are supported. This patch includes a simple example that demonstrate how to open a file that contains multiple buffers. Each buffers is loaded into a separate Data stream and those streams are merged together.
--- examples/CMakeLists.txt | 4 + examples/multibufferload.c | 53 ++++++++ src/libkshark.c | 255 +++++++++++++++++++++++++++++++++++++ src/libkshark.h | 47 +++++++ 4 files changed, 359 insertions(+) create mode 100644 examples/multibufferload.c
examples/CMakeLists.txt +4 -0
@@ -8,6 +8,10 @@ message(STATUS "datafilter") add_executable(dfilter datafilter.c) target_link_libraries(dfilter kshark) +message(STATUS "multibufferload") +add_executable(mbload multibufferload.c) +target_link_libraries(mbload kshark) + # message(STATUS "datahisto") # add_executable(dhisto datahisto.c) # target_link_libraries(dhisto kshark)
examples/multibufferload.c new file +53 -0
53 lines not on this page · raw message
src/libkshark.c +255 -0
258 lines not on this page · raw message
src/libkshark.h +47 -0
59 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 23/44 kernel-shark: Integrate the stream definitions with data model
In reply to Yordan Karadzhov (VMware)The visualization model is adapted in order to be able to distinguish the entries belonging to different Data streams.
We re-enable the visualization model example as well.
--- examples/CMakeLists.txt | 8 ++-- examples/datahisto.c | 38 +++++++-------- src/CMakeLists.txt | 2 +- src/libkshark-model.c | 102 ++++++++++++++++++++++++---------------- src/libkshark-model.h | 34 +++++++------- 5 files changed, 102 insertions(+), 82 deletions(-)
examples/CMakeLists.txt +4 -4
@@ -12,10 +12,10 @@ message(STATUS "multibufferload") add_executable(mbload multibufferload.c) target_link_libraries(mbload kshark) -# message(STATUS "datahisto") -# add_executable(dhisto datahisto.c) -# target_link_libraries(dhisto kshark) -# +message(STATUS "datahisto") +add_executable(dhisto datahisto.c) +target_link_libraries(dhisto kshark) + # message(STATUS "confogio") # add_executable(confio configio.c) # target_link_libraries(confio kshark)
examples/datahisto.c +19 -19
@@ -7,6 +7,7 @@// C #include <stdio.h> #include <stdlib.h> +#include <string.h> // KernelShark #include "libkshark.h"
@@ -16,7 +17,7 @@const char *default_file ="trace.dat" ; -void dump_bin (struct kshark_trace_histo *histo,int bin, +void dump_bin (struct kshark_trace_histo *histo,int bin,int sd,const char *type,int val) {const struct kshark_entry *e_front, *e_back;
@@ -26,22 +27,22 @@ void dump_bin(struct kshark_trace_histo *histo, int bin,printf ("bin %i {\n" , bin);if (strcmp (type,"cpu" ) ==0 ) { e_front =ksmodel_get_entry_front (histo, bin, true, - kshark_match_cpu, val, + kshark_match_cpu, sd, &val,NULL , &i_front); e_back =ksmodel_get_entry_back (histo, bin, true, - kshark_match_cpu, val, + kshark_match_cpu, sd, &val,NULL , &i_back); }else if (strcmp (type,"task" ) ==0 ) { e_front =ksmodel_get_entry_front (histo, bin, true, - kshark_match_pid, val, + kshark_match_pid, sd, &val,NULL , &i_front); e_back =ksmodel_get_entry_back (histo, bin, true, - kshark_match_pid, val, + kshark_match_pid, sd, &val,NULL , &i_back); }else {
@@ -67,12 +68,12 @@ void dump_bin(struct kshark_trace_histo *histo, int bin,puts ("}\n" ); } -void dump_histo (struct kshark_trace_histo *histo,const char *type,int val) +void dump_histo (struct kshark_trace_histo *histo,int sd,const char *type,int val) {size_t bin;for (bin =0 ; bin < histo->n_bins; ++bin) -dump_bin (histo, bin, type, val); +dump_bin (histo, bin, sd, type, val); }int main (int argc,char **argv)
@@ -81,8 +82,7 @@ int main(int argc, char **argv)struct kshark_entry **data =NULL ;struct kshark_trace_histo histo;ssize_t i, n_rows, n_tasks; -bool status; -int *pids; +int sd, *pids;/* Create a new kshark session. */ kshark_ctx =NULL ;
@@ -91,24 +91,24 @@ int main(int argc, char **argv)/* Open a trace data file produced by trace-cmd. */ if (argc >1 ) - status =kshark_open (kshark_ctx, argv[1 ]); + sd =kshark_open (kshark_ctx, argv[1 ]);else - status =kshark_open (kshark_ctx, default_file); + sd =kshark_open (kshark_ctx, default_file); -if (!status) { +if (sd <0 ) {kshark_free (kshark_ctx);return 1 ; }/* Load the content of the file into an array of entries. */ - n_rows =kshark_load_data_entries (kshark_ctx, &data); + n_rows =kshark_load_entries (kshark_ctx, sd, &data);if (n_rows <1 ) {kshark_free (kshark_ctx);return 1 ; }/* Get a list of all tasks. */ - n_tasks =kshark_get_task_pids (kshark_ctx, &pids); + n_tasks =kshark_get_task_pids (kshark_ctx, sd, &pids);/* Initialize the Visualization Model. */ ksmodel_init (&histo);
@@ -119,7 +119,7 @@ int main(int argc, char **argv)ksmodel_fill (&histo, data, n_rows);/* Dump the raw bins. */ -dump_histo (&histo,"" ,0 ); +dump_histo (&histo, sd,"" ,0 );puts ("\n...\n\n" );
@@ -127,13 +127,13 @@ int main(int argc, char **argv)* Change the state of the model. Do 50% Zoom-In and dump only CPU 0. */ ksmodel_zoom_in (&histo,.50 ,-1 ); -dump_histo (&histo,"cpu" ,0 ); +dump_histo (&histo, sd,"cpu" ,0 );puts ("\n...\n\n" );/* Shift forward by two bins and this time dump only CPU 1. */ ksmodel_shift_forward (&histo,2 ); -dump_histo (&histo,"cpu" ,1 ); +dump_histo (&histo, sd,"cpu" ,1 );puts ("\n...\n\n" );
@@ -142,7 +142,7 @@ int main(int argc, char **argv)* Task. */ ksmodel_zoom_out (&histo,.10 ,N_BINS -1 ); -dump_histo (&histo,"task" , pids[n_tasks -1 ]); +dump_histo (&histo, sd,"task" , pids[n_tasks -1 ]);/* Reset (clear) the model. */ ksmodel_clear (&histo);
@@ -154,7 +154,7 @@ int main(int argc, char **argv)free (data);/* Close the file. */ -kshark_close (kshark_ctx); +kshark_close (kshark_ctx, sd);/* Close the session. */ kshark_free (kshark_ctx);
src/CMakeLists.txt +1 -1
@@ -5,7 +5,7 @@ set(KS_INCLUDS_DESTINATION "${_INSTALL_PREFIX}/include/${KS_APP_NAME}") message(STATUS "libkshark") add_library(kshark SHARED libkshark.c libkshark-hash.c -# libkshark-model.c + libkshark-model.c libkshark-plugin.c libkshark-tepdata.c # libkshark-configio.c
src/libkshark-model.c +61 -41
358 lines not on this page · raw message
src/libkshark-model.h +17 -17
@@ -1,13 +1,13 @@/* SPDX-License-Identifier: LGPL-2.1 */ /* -* Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> +* Copyright (C) 2017 VMware Inc, Yordan Karadzhov (VMware) <[email protected]> */ -/** -* @file libkshark-model.h -* @brief Visualization model for FTRACE (trace-cmd) data. -*/ +/** +* @file libkshark-model.h +* @brief Time series visualization model for tracing data. +*/ #ifndef _LIB_KSHARK_MODEL_H#define _LIB_KSHARK_MODEL_H
@@ -102,64 +102,64 @@ ssize_t ksmodel_first_index_at_bin(struct kshark_trace_histo *histo, int bin);ssize_t ksmodel_last_index_at_bin (struct kshark_trace_histo *histo,int bin);ssize_t ksmodel_first_index_at_cpu (struct kshark_trace_histo *histo, -int bin,int cpu); +int bin,int sd,int cpu);ssize_t ksmodel_first_index_at_pid (struct kshark_trace_histo *histo, -int bin,int pid); +int bin,int sd,int pid);const struct kshark_entry *ksmodel_get_entry_front (struct kshark_trace_histo *histo,int bin,bool vis_only, -matching_condition_func func,int val, +matching_condition_func func,int sd,int *values,struct kshark_entry_collection *col,ssize_t *index);const struct kshark_entry *ksmodel_get_entry_back (struct kshark_trace_histo *histo,int bin,bool vis_only, -matching_condition_func func,int val, +matching_condition_func func,int sd,int *values,struct kshark_entry_collection *col,ssize_t *index);int ksmodel_get_pid_front (struct kshark_trace_histo *histo, -int bin,int cpu,bool vis_only, +int bin,int sd,int cpu,bool vis_only,struct kshark_entry_collection *col,ssize_t *index);int ksmodel_get_pid_back (struct kshark_trace_histo *histo, -int bin,int cpu,bool vis_only, +int bin,int sd,int cpu,bool vis_only,struct kshark_entry_collection *col,ssize_t *index);int ksmodel_get_cpu_front (struct kshark_trace_histo *histo, -int bin,int pid,bool vis_only, +int bin,int sd,int pid,bool vis_only,struct kshark_entry_collection *col,ssize_t *index);int ksmodel_get_cpu_back (struct kshark_trace_histo *histo, -int bin,int pid,bool vis_only, +int bin,int sd,int pid,bool vis_only,struct kshark_entry_collection *col,ssize_t *index);bool ksmodel_cpu_visible_event_exist (struct kshark_trace_histo *histo, -int bin,int cpu, +int bin,int sd,int cpu,struct kshark_entry_collection *col,ssize_t *index);bool ksmodel_task_visible_event_exist (struct kshark_trace_histo *histo, -int bin,int pid, +int bin,int sd,int pid,struct kshark_entry_collection *col,ssize_t *index);const struct kshark_entry *ksmodel_get_cpu_missed_events (struct kshark_trace_histo *histo, -int bin,int cpu, +int bin,int sd,int cpu,struct kshark_entry_collection *col,ssize_t *index);const struct kshark_entry *ksmodel_get_task_missed_events (struct kshark_trace_histo *histo, -int bin,int pid, +int bin,int sd,int pid,struct kshark_entry_collection *col,ssize_t *index);
Signature · 1 line
2.25.1
PATCH v8 24/44 kernel-shark: Use only signed types for model defs
In reply to Yordan Karadzhov (VMware)All variables that are used to describe the state of the model, like the range of the model or the size of the bin must have signed integer types. This is a continuation of the change started by switching to signed timestamps.
--- src/libkshark-model.c | 12 ++++++------ src/libkshark-model.h | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-)
src/libkshark-model.c +6 -6
@@ -91,10 +91,10 @@ static bool ksmodel_histo_alloc(struct kshark_trace_histo *histo, size_t n) }static void ksmodel_set_in_range_bining (struct kshark_trace_histo *histo, -size_t n,uint64_t min,uint64_t max, +size_t n,int64_t min,int64_t max,bool force_in_range) { -uint64_t corrected_range, delta_range, range = max - min; +int64_t corrected_range, delta_range, range = max - min;struct kshark_entry *last;/* The size of the bin must be >= 1, hence the range must be >= n. */
@@ -163,7 +163,7 @@ static void ksmodel_set_in_range_bining(struct kshark_trace_histo *histo,* @param max: Upper edge of the time-window to be visualized. */ void ksmodel_set_bining (struct kshark_trace_histo *histo, -size_t n,uint64_t min,uint64_t max) +size_t n,int64_t min,int64_t max) {ksmodel_set_in_range_bining (histo, n, min, max, false); }
@@ -256,7 +256,7 @@ static size_t ksmodel_set_upper_edge(struct kshark_trace_histo *histo)static void ksmodel_set_next_bin_edge (struct kshark_trace_histo *histo,size_t bin,size_t last_row) { -uint64_t time_min, time_max; +int64_t time_min, time_max;size_t next_bin = bin +1 ;ssize_t row;
@@ -598,9 +598,9 @@ void ksmodel_shift_backward(struct kshark_trace_histo *histo, size_t n)* @param histo: Input location for the model descriptor. * @param ts: position in time to be visualized. */ -void ksmodel_jump_to (struct kshark_trace_histo *histo,uint64_t ts) +void ksmodel_jump_to (struct kshark_trace_histo *histo,int64_t ts) { -uint64_t min, max, range_min; +int64_t min, max, range_min;if (ts > histo->min && ts < histo->max) {/*
src/libkshark-model.h +9 -9
@@ -58,16 +58,16 @@ struct kshark_trace_histo {* Lower edge of the time-window to be visualized. Only entries having * timestamp >= min will be visualized. */ -uint64_t min; +int64_t min;/** * Upper edge of the time-window to be visualized. Only entries having * timestamp <= max will be visualized. */ -uint64_t max; +int64_t max;/** The size in time for each bin. */ -uint64_t bin_size; +int64_t bin_size;/** Number of bins. */ int n_bins;
@@ -78,7 +78,7 @@ void ksmodel_init(struct kshark_trace_histo *histo);void ksmodel_clear (struct kshark_trace_histo *histo);void ksmodel_set_bining (struct kshark_trace_histo *histo, -size_t n,uint64_t min,uint64_t max); +size_t n,int64_t min,int64_t max);void ksmodel_fill (struct kshark_trace_histo *histo,struct kshark_entry **data,size_t n);
@@ -89,7 +89,7 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n);void ksmodel_shift_backward (struct kshark_trace_histo *histo,size_t n); -void ksmodel_jump_to (struct kshark_trace_histo *histo,uint64_t ts); +void ksmodel_jump_to (struct kshark_trace_histo *histo,int64_t ts);void ksmodel_zoom_out (struct kshark_trace_histo *histo,double r,int mark);
@@ -163,16 +163,16 @@ ksmodel_get_task_missed_events(struct kshark_trace_histo *histo,struct kshark_entry_collection *col, ssize_t *index); -static inline double ksmodel_bin_time (struct kshark_trace_histo *histo, +static inline int64_t ksmodel_bin_ts (struct kshark_trace_histo *histo,int bin) { -return (histo->min + bin*histo->bin_size) *1e-9 ; +return (histo->min + bin*histo->bin_size); } -static inline uint64_t ksmodel_bin_ts (struct kshark_trace_histo *histo, +static inline double ksmodel_bin_time (struct kshark_trace_histo *histo,int bin) { -return (histo->min + bin*histo->bin_size); +return ksmodel_bin_ts (histo, bin) *1e-9 ; }#ifdef __cplusplus
Signature · 1 line
2.25.1
PATCH v8 25/44 kernel-shark: Add ksmodel_get_bin()
In reply to Yordan Karadzhov (VMware)The method retrieves the Id of the bin of the model that contains given entry.
--- src/libkshark-model.c | 27 +++++++++++++++++++++++++++ src/libkshark-model.h | 3 +++ 2 files changed, 30 insertions(+)
src/libkshark-model.c +27 -0
@@ -1325,3 +1325,30 @@ ksmodel_get_task_missed_events(struct kshark_trace_histo *histo, match_pid_missed_events, sd, &pid, col, index); } + +/** +* @brief Find the bin Id of a give entry. +* +* @param histo: Input location for the model descriptor. +* @param entry: Input location for entry. +* +* @returns If the timestamp of the entry is inside the range of the model the +* function returns the Id of the bin it belongs to. +* If the timestamp of the entry is outside of the range of the model +* the function returns UPPER_OVERFLOW_BIN or LOWER_OVERFLOW_BIN +* (negative values). +*/ +int ksmodel_get_bin (struct kshark_trace_histo *histo, +const struct kshark_entry *entry) +{ +if (entry->ts < histo->min) +return UPPER_OVERFLOW_BIN ; + +if (entry->ts > histo->max) +return LOWER_OVERFLOW_BIN ; + +if (entry->ts == histo->max) +return histo->n_bins -1 ; + +return (entry->ts - histo->min) / histo->bin_size; +}
src/libkshark-model.h +3 -0
@@ -175,6 +175,9 @@ static inline double ksmodel_bin_time(struct kshark_trace_histo *histo,return ksmodel_bin_ts (histo, bin) *1e-9 ; } +int ksmodel_get_bin (struct kshark_trace_histo *histo, +const struct kshark_entry *entry); + #ifdef __cplusplus }#endif // __cplusplus
Signature · 1 line
2.25.1
PATCH v8 26/44 kernel-shark: Protect ksmodel_set_in_range_bining()
In reply to Yordan Karadzhov (VMware)Handle the case when the number of bins is zero or negative.
--- src/libkshark-model.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
src/libkshark-model.c +12 -1
@@ -97,8 +97,19 @@ static void ksmodel_set_in_range_bining(struct kshark_trace_histo *histo,int64_t corrected_range, delta_range, range = max - min;struct kshark_entry *last; +if (n <=0 ) { + histo->n_bins = histo->bin_size =0 ; + histo->min = min; + histo->max = max; + +free (histo->bin_count); +free (histo->map); + +return ; + } +/* The size of the bin must be >= 1, hence the range must be >= n. */ -if (n ==0 || range < n) { +if (range < n) { range = n; max = min + n; }
Signature · 1 line
2.25.1
PATCH v8 27/44 kernel-shark: Add methods for time calibration
In reply to Yordan Karadzhov (VMware)We add an infrastructure for correcting the timestamps of the entries. This is needed in order to correlate Data streams that have been recorded using non-synchronized clocks. The infrastructure can handle an arbitrary timestamps correction formula, however for the moment we only provide calibration that adds a constant offset.
--- src/libkshark-tepdata.c | 13 +++++- src/libkshark.c | 99 +++++++++++++++++++++++++++++++++++++++++ src/libkshark.h | 27 +++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-)
src/libkshark-tepdata.c +12 -1
@@ -338,6 +338,9 @@ static ssize_t get_records(struct kshark_context *kshark_ctx, entry = &temp_rec->entry;missed_events_action (stream, rec, entry); +/* Apply time calibration. */ +kshark_postprocess_entry (stream, rec, entry); + entry->stream_id = stream->stream_id; temp_next = &temp_rec->next;
@@ -360,6 +363,12 @@ static ssize_t get_records(struct kshark_context *kshark_ctx, entry->stream_id = stream->stream_id; +/* +* Post-process the content of the entry. This includes +* time calibration and event-specific plugin actions. +*/ +kshark_postprocess_entry (stream, rec, entry); + pid = entry->pid;/* Apply Id filtering. */
@@ -527,8 +536,10 @@ static ssize_t tepdata_load_matrix(struct kshark_data_stream *stream,if (cpu_array) (*cpu_array)[count] = e->cpu; -if (ts_array) +if (ts_array) { +kshark_calib_entry (stream, e); (*ts_array)[count] = e->ts; + }if (pid_array) (*pid_array)[count] = e->pid;
src/libkshark.c +99 -0
117 lines not on this page · raw message
src/libkshark.h +27 -0
@@ -129,6 +129,12 @@ static const char top_name[] = { 0x1b, 0x00 }; // Non printable character*/ #define KS_UNNAMED (char *) &top_name +/** +* Timestamp calibration function type. To be user for system clock +* calibration. +*/ +typedef void (*time_calib_func ) (int64_t *,int64_t *); +struct kshark_data_stream ;/** A function type to be used by the method interface of the data stream. */
@@ -327,6 +333,15 @@ struct kshark_data_stream {/** The number of plugins registered for this stream.*/ int n_plugins; +/** System clock calibration function. */ +time_calib_func calib; + +/** An array of time calibration constants. */ +int64_t *calib_array; + +/** The size of the array of time calibration constants. */ +size_t calib_array_size; +/** List of Plugin's Event handlers. */ struct kshark_event_proc_handler *event_handlers;
@@ -590,6 +605,12 @@ void kshark_clear_all_filters(struct kshark_context *kshark_ctx,void kshark_plugin_actions (struct kshark_data_stream *stream,void *record,struct kshark_entry *entry); +void kshark_calib_entry (struct kshark_data_stream *stream, +struct kshark_entry *entry); + +void kshark_postprocess_entry (struct kshark_data_stream *stream, +void *record,struct kshark_entry *entry); +/** Search failed identifiers. */ enum kshark_search_failed {/** All entries have greater timestamps. */
@@ -980,6 +1001,12 @@ struct kshark_config_doc *kshark_open_config_file(const char *file_name,struct kshark_config_doc *kshark_json_to_conf (struct json_object *jobj); +void kshark_offset_calib (int64_t *ts,int64_t *atgv); + +void kshark_set_clock_offset (struct kshark_context *kshark_ctx, +struct kshark_entry **entries,size_t size, +int sd,int64_t offset); +/** Structure representing a data set made of KernelShark entries. */ struct kshark_entry_data_set {/** Array of entries pointers. */
Signature · 1 line
2.25.1
PATCH v8 28/44 kernel-shark: Integrate streams with libkshark-configio
In reply to Yordan Karadzhov (VMware)The configuration input/output is adapted in order to be able to work with the new version of the C API. Now it can handle multiple Data streams. We are re-enabling the corresponding example as well.
--- examples/CMakeLists.txt | 8 +- examples/configio.c | 20 +- src/CMakeLists.txt | 2 +- src/libkshark-configio.c | 1208 ++++++++++++++++++++++++++++++++------ src/libkshark.h | 73 ++- 5 files changed, 1093 insertions(+), 218 deletions(-)
examples/CMakeLists.txt +4 -4
@@ -16,10 +16,10 @@ message(STATUS "datahisto") add_executable(dhisto datahisto.c) target_link_libraries(dhisto kshark) -# message(STATUS "confogio") -# add_executable(confio configio.c) -# target_link_libraries(confio 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)
examples/configio.c +12 -8
@@ -7,22 +7,26 @@ int main(int argc, char **argv) {struct kshark_config_doc *conf, *filter, *hello;struct kshark_context *kshark_ctx; -int *ids =NULL , i; +struct kshark_data_stream *stream; +int sd, *ids =NULL , i;/* Create a new kshark session. */ kshark_ctx =NULL ;if (!kshark_instance (&kshark_ctx))return 1 ; + sd =kshark_add_stream (kshark_ctx); + stream = kshark_ctx->stream[sd]; +if (argc ==1 ) { -tracecmd_filter_id_add (kshark_ctx->show_task_filter,314 ); -tracecmd_filter_id_add (kshark_ctx->show_task_filter,42 ); +kshark_hash_id_add (stream->show_task_filter,314 ); +kshark_hash_id_add (stream->show_task_filter,42 );/* Create a new Confog. doc. */ conf =kshark_config_new ("foo.bar.config" ,KS_CONFIG_JSON );/* Add filter's info. */ - filter =kshark_export_all_filters (kshark_ctx,KS_CONFIG_JSON ); + filter =kshark_export_all_filters (kshark_ctx, sd,KS_CONFIG_JSON );kshark_config_doc_add (conf,"Filters" ,filter);/* Add "Hello Kernel" message. */
@@ -39,11 +43,11 @@ int main(int argc, char **argv)/* Retrieve the filter's info. */ filter =kshark_config_alloc (KS_CONFIG_JSON );if (kshark_config_doc_get (conf,"Filters" ,filter)) { -kshark_import_all_filters (kshark_ctx, filter); +kshark_import_all_filters (kshark_ctx, sd, filter);/* Get the array of Ids to be fitered. */ - ids =tracecmd_filter_ids (kshark_ctx->show_task_filter); -for (i =0 ; i < kshark_ctx->show_task_filter->count; ++i) + ids =kshark_hash_ids (stream->show_task_filter); +for (i =0 ; i < stream->show_task_filter->count; ++i)printf ("pid: %i\n" , ids[i]); }
@@ -58,7 +62,7 @@ int main(int argc, char **argv) }kshark_free_config_doc (conf); - +kshark_close (kshark_ctx, sd);kshark_free (kshark_ctx);return 0 ;
src/CMakeLists.txt +1 -1
@@ -8,7 +8,7 @@ add_library(kshark SHARED libkshark.c libkshark-model.c libkshark-plugin.c libkshark-tepdata.c -# libkshark-configio.c + libkshark-configio.c libkshark-collection.c) target_link_libraries(kshark trace::cmd
src/libkshark-configio.c +1017 -191
1,775 lines not on this page · raw message
src/libkshark.h +59 -14
129 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 29/44 kernel-shark: Add support for drawing text
In reply to Yordan Karadzhov (VMware)OpenGL doesn't provide support for text rendering. Here we first re-enable the compilation of the OpenGL wrapper and add the capability of printing text to the OpenGL scene by using the single-file public domain library "stb_truetype":
https://github.com/nothings/stb/blob/master/stb_truetype.h
--- CMakeLists.txt | 6 +- Documentation/doxygen/dox_config | 1 + src/CMakeLists.txt | 4 +- src/libkshark-plot.c | 256 +- src/libkshark-plot.h | 57 + src/stb_truetype.h | 5011 ++++++++++++++++++++++++++++++ 6 files changed, 5324 insertions(+), 11 deletions(-) create mode 100644 src/stb_truetype.h
CMakeLists.txt +3 -3
@@ -45,9 +45,9 @@ find_package(JSONC REQUIRED) find_package(Doxygen) -# set(OpenGL_GL_PREFERENCE LEGACY) -# find_package(OpenGL) -# find_package(GLUT) +set(OpenGL_GL_PREFERENCE LEGACY) +find_package(OpenGL) +find_package(GLUT) # find_package(Qt5Widgets 5.7.1) # find_package(Qt5Network)
Documentation/doxygen/dox_config +1 -0
@@ -14,3 +14,4 @@ SORT_MEMBER_DOCS = NO STRICT_PROTO_MATCHING = YES DOT_MULTI_TARGETS = YES PROJECT_LOGO = ../../icons/KS_logo_stacked.svg +EXCLUDE = ../../src/stb_truetype.h
src/CMakeLists.txt +2 -2
@@ -41,8 +41,8 @@ install(FILES "${KS_DIR}/src/libkshark.h" if (OPENGL_FOUND AND GLUT_FOUND) message(STATUS "libkshark-plot") - add_library(kshark-plot SHARED libkshark-plot.c - KsPlotTools.cpp) + add_library(kshark-plot SHARED libkshark-plot.c) +# KsPlotTools.cpp) target_link_libraries(kshark-plot kshark ${GLUT_LIBRARY}
src/libkshark-plot.c +250 -6
279 lines not on this page · raw message
src/libkshark-plot.h +57 -0
69 lines not on this page · raw message
src/stb_truetype.h new file +5011 -0
2,626 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
PATCH v8 30/44 kernel-shark: Make GLUT optional dependency
In reply to Yordan Karadzhov (VMware)GLUT is not needed in order to build the KernelShark GUI. Currently it is being used only by the plotting example, so it makes more sense to removed it from the list of compulsory third party packages. The patch optimizes the way the OpenGL and GLUT headers are included and removes some duplicated code.
--- build/deff.h.cmake | 3 +++ src/CMakeLists.txt | 4 ++-- src/libkshark-plot.c | 20 +++++++------------- src/libkshark-plot.h | 11 +++++++++++ 4 files changed, 23 insertions(+), 15 deletions(-)
build/deff.h.cmake +3 -0
@@ -23,6 +23,9 @@ /** "pkexec" executable. */ #cmakedefine DO_AS_ROOT "@DO_AS_ROOT@" +/** GLUT has been found. */ +#cmakedefine GLUT_FOUND + /** Semicolon-separated list of plugin names. */ #define KS_BUILTIN_PLUGINS "@PLUGINS@"
src/CMakeLists.txt +2 -2
@@ -38,7 +38,7 @@ install(FILES "${KS_DIR}/src/libkshark.h" DESTINATION ${KS_INCLUDS_DESTINATION} COMPONENT libkshark-devel) -if (OPENGL_FOUND AND GLUT_FOUND) +if (OPENGL_FOUND) message(STATUS "libkshark-plot") add_library(kshark-plot SHARED libkshark-plot.c)
@@ -61,7 +61,7 @@ if (OPENGL_FOUND AND GLUT_FOUND) ARCHIVE DESTINATION ${_LIBDIR} COMPONENT libkshark-devel) -endif (OPENGL_FOUND AND GLUT_FOUND) +endif (OPENGL_FOUND) if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
src/libkshark-plot.c +7 -13
@@ -19,10 +19,6 @@#include <string.h> #include <stdio.h> -// OpenGL -#include <GL/freeglut.h> -#include <GL/gl.h> -// KernelShark #include "libkshark-plot.h"
@@ -37,6 +33,10 @@#define STBTT_STATIC #include "stb_truetype.h" +#ifdef GLUT_FOUND + +#include <GL/freeglut.h> +/** * @brief Create an empty scene for drawing. *
@@ -61,17 +61,11 @@ void ksplot_make_scene(int width, int height)/* Open the screen window. */ glutCreateWindow ("KernelShark Plot" ); -/* -* Set the origin of the coordinate system to be the top left corner. -* The "Y" coordinate is inverted. -*/ -gluOrtho2D (0 , width, height,0 ); -glViewport (0 ,0 , width, height); - -glMatrixMode (GL_PROJECTION ); -glLoadIdentity (); + ksplot_resize_opengl(width, height); } +#endif // GLUT_FOUND +/** * @brief Initialize OpenGL. *
src/libkshark-plot.h +11 -0
@@ -15,6 +15,10 @@// C #include <stdbool.h> +// OpenGL +#include <GL/gl.h> +#include <GL/glu.h> +/* * STB TrueType (single-file public domain library) * https://github.com/nothings/stb
@@ -25,6 +29,9 @@ extern "C" { #endif +// KernelShark +#include "KsCmakeDef.hpp" + /** Structure defining a RGB color. */ struct ksplot_color { /** The Red component of the color. */
@@ -46,8 +53,12 @@ struct ksplot_point {int y; }; +#ifdef GLUT_FOUND +void ksplot_make_scene (int width,int height); +#endif // GLUT_FOUND +void ksplot_init_opengl (int dpr);void ksplot_resize_opengl (int width,int height);
Signature · 1 line
2.25.1
PATCH v8 31/44 kernel-shark: Add ksplot_draw_polyline()
In reply to Yordan Karadzhov (VMware)The method draws continuous line between an ordered array of points (poly-line).
--- src/libkshark-plot.c | 32 ++++++++++++++++++++++++++------ src/libkshark-plot.h | 5 +++++ 2 files changed, 31 insertions(+), 6 deletions(-)
src/libkshark-plot.c +26 -6
@@ -151,6 +151,30 @@ void ksplot_draw_line(const struct ksplot_point *a,glEnd (); } +/** +* @brief Draw the a polyline. +* +* @param points: Input location for the array of points defining the polyline. +* @param n_points: The size of the array of points. +* @param col: The color of the polyline. +* @param size: The size of the polyline. +*/ +void ksplot_draw_polyline (const struct ksplot_point *points, +size_t n_points, +const struct ksplot_color *col, +float size) +{ +if (!points || !n_points || !col || size <.5f ) +return ; + +/* Loop over the points of the polygon and draw connecting lines. */ +for (size_t i =1 ; i < n_points; ++i) +ksplot_draw_line (&points[i -1 ], + &points[i], + col, + size); +} +/** * @brief Draw a polygon. *
@@ -212,12 +236,8 @@ void ksplot_draw_polygon_contour(const struct ksplot_point *points,if (!points || !n_points || !col || size <.5f )return ; -/* Loop over the points of the polygon and draw connecting lines. */ -for (size_t i =1 ; i < n_points; ++i) -ksplot_draw_line (&points[i -1 ], - &points[i], - col, - size); +/* Loop over the points of the polygon and draw a polyline. */ +ksplot_draw_polyline (points, n_points, col, size);/* Close the contour. */ ksplot_draw_line(&points[0],
src/libkshark-plot.h +5 -0
@@ -72,6 +72,11 @@ void ksplot_draw_line(const struct ksplot_point *a,const struct ksplot_color *col, float size); +void ksplot_draw_polyline (const struct ksplot_point *points, +size_t n_points, +const struct ksplot_color *col, +float size); + void ksplot_draw_polygon(const struct ksplot_point *points, size_t n_points, const struct ksplot_color *col,
Signature · 1 line
2.25.1
PATCH v8 32/44 kernel-shark: Optimize ksplot_draw_polygon()
In reply to Yordan Karadzhov (VMware)Using a point inside the polygon to start the Triangle Fan looked more intuitive to me when I first implemented this method. I guess this was because when you use an internal point to start, the resulting set of triangles looks like fan indeed. However, as pointed out by Slavomir Kaslev, the Triangle Fan can be started from any corner of the polygon.
--- src/libkshark-plot.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
src/libkshark-plot.c +1 -10
@@ -201,18 +201,9 @@ void ksplot_draw_polygon(const struct ksplot_point *points,return ; } -/* Obtain a point inside the surface of the polygon. */ -struct ksplot_point in_point; - in_point.x = (points[0 ].x + points[2 ].x) /2 ; - in_point.y = (points[0 ].y + points[2 ].y) /2 ; - -/* -* Draw a Triangle Fan using the internal point as a central -* vertex. -*/ +/* Draw a Triangle Fan. */ glBegin (GL_TRIANGLE_FAN );glColor3ub (col->red, col->green, col->blue); -glVertex2i (in_point.x, in_point.y);for (size_t i =0 ; i < n_points; ++i)glVertex2i (points[i].x, points[i].y);
Signature · 1 line
2.25.1
PATCH v8 33/44 kernel-shark: Add basic infrastructure for testing
In reply to Yordan Karadzhov (VMware)The tasting infrastructure is based on GTest (CMake-provided feature for automated testing) and Boost Test Library. In the patch we also provide a very simple test of adding/removing Data streams. For the moment this single test is used mainly to validate the proper functioning of the tasting infrastructure itself. A proper test coverage of the libraries is yet to be implemented. In a following patch we will integrate the tasting infrastructure into a "github Actions" workflow that will help the CI process.
--- CMakeLists.txt | 9 ++++++++ build/cmake_clean.sh | 4 ++++ tests/CMakeLists.txt | 14 ++++++++++++ tests/libkshark-tests.cpp | 48 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/libkshark-tests.cpp
CMakeLists.txt +9 -0
@@ -57,6 +57,8 @@ if (Qt5Widgets_FOUND) endif (Qt5Widgets_FOUND) +find_package (Boost COMPONENTS unit_test_framework) + set(LIBRARY_OUTPUT_PATH "${KS_DIR}/lib") set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
@@ -109,6 +111,13 @@ message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS}) add_subdirectory(${KS_DIR}/src) add_subdirectory(${KS_DIR}/examples) +if (Boost_FOUND) + + enable_testing() + add_subdirectory(${KS_DIR}/tests) + +endif() + if (_DOXYGEN_DOC AND DOXYGEN_FOUND) message("\n doxygen documentation ...")
build/cmake_clean.sh +4 -0
@@ -2,9 +2,13 @@ make clean rm CMakeCache.txt rm cmake_install.cmake rm Makefile +rm CTestTestfile.cmake +rm -f DartConfiguration.tcl rm -rf CMakeFiles/ rm -rf src/ rm -rf examples/ +rm -rf tests/ +rm -rf Testing/ rm -f ../lib/* rm ../kernelshark.desktop rm ../org.freedesktop.kshark-record.policy
tests/CMakeLists.txt new file +14 -0
@@ -0,0 +1,14 @@ +message("\n tests ...") + +set(KS_TEST_DIR "${KS_DIR}/tests") +set(EXECUTABLE_OUTPUT_PATH ${KS_TEST_DIR}) + +add_executable(kshark-tests libkshark-tests.cpp) +target_include_directories(kshark-tests PRIVATE ${Boost_INCLUDE_DIRS}) +target_compile_definitions(kshark-tests PRIVATE "BOOST_TEST_DYN_LINK=1") +target_link_libraries(kshark-tests kshark + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + +add_test(NAME "libkshark_tests" + COMMAND ${KS_TEST_DIR}/kshark-tests --log_format=HRF + WORKING_DIRECTORY ${KS_TEST_DIR})
tests/libkshark-tests.cpp new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 34/44 kernel-shark: Add "github Actions" workflow
In reply to Yordan Karadzhov (VMware)From: Yordan Karadzhov <[email protected]>
The workflow will install all third party libraries, will build KernelShark and will run the tests.
--- .github/workflows/main.yml | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/main.yml
.github/workflows/main.yml new file +63 -0
@@ -0,0 +1,63 @@ +name: KernelShark CI (CMAKE) + +on: [push] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - 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 + git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ + cd libtraceevent + make + sudo make install + cd .. + git clone https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ + cd libtracefs + make + sudo make install + cd .. + 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 + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure CMake + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash + working-directory: ${{runner.workspace}}/build + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. + # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS_RELEASE="-Werror" + + - name: Build + working-directory: ${{runner.workspace}}/build + shell: bash + # Execute the build. You can specify a specific target with "--target <NAME>" + run: cmake --build . --config $BUILD_TYPE + + - name: Test + working-directory: ${{runner.workspace}}/build + shell: bash + # Execute tests defined by the CMake configuration. + run: ctest -C $BUILD_TYPE
Signature · 1 line
2.25.1
PATCH v8 35/44 kernel-shark: Integrate streams with KsPlotTools
In reply to Yordan Karadzhov (VMware)The C++ ploting toolls are adapted in order to be able to work with the new version of the C API. Now we can handle multiple Data streams.
--- src/CMakeLists.txt | 4 +- src/KsPlotTools.cpp | 94 ++++++++++++++++++++++++++++++++------------- src/KsPlotTools.hpp | 4 +- 3 files changed, 71 insertions(+), 31 deletions(-)
src/CMakeLists.txt +2 -2
@@ -41,8 +41,8 @@ install(FILES "${KS_DIR}/src/libkshark.h" if (OPENGL_FOUND) message(STATUS "libkshark-plot") - add_library(kshark-plot SHARED libkshark-plot.c) -# KsPlotTools.cpp) + add_library(kshark-plot SHARED libkshark-plot.c + KsPlotTools.cpp) target_link_libraries(kshark-plot kshark ${GLUT_LIBRARY}
src/KsPlotTools.cpp +67 -27
242 lines not on this page · raw message
src/KsPlotTools.hpp +2 -2
@@ -432,9 +432,9 @@ public: /** @brief Set the Hash table of Task's colors. */ void setBinColorTablePtr(KsPlot::ColorTable *ct) {_binColors = ct;} - void fillCPUGraph(int cpu); + void fillCPUGraph(int sd, int cpu); - void fillTaskGraph(int pid); + void fillTaskGraph(int sd, int pid); void draw(float s = 1);
Signature · 1 line
2.25.1
PATCH v8 36/44 kernel-shark: Add getStreamColorTable()
In reply to Yordan Karadzhov (VMware)This method provides a hash table that maps the stream Ids to rainbow-like colors.
--- src/KsPlotTools.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/KsPlotTools.hpp | 4 ++++ 2 files changed, 54 insertions(+)
src/KsPlotTools.cpp +50 -0
@@ -97,6 +97,23 @@ void Color::setRainbowColor(int n) set(r, g, b); } +/** Alpha blending with white background. */ +void Color::blend(float alpha) +{ + if (alpha < 0 || alpha > 1.) + return; + + auto lamBld = [alpha](int val) { + return val * alpha + (1 - alpha) * 255; + }; + + int r = lamBld(this->r()); + int g = lamBld(this->g()); + int b = lamBld(this->b()); + + set(r, g, b); +} + /** * @brief Create a Hash table of Rainbow colors. The sorted Pid values are * mapped to the palette of Rainbow colors.
@@ -182,6 +199,39 @@ ColorTable getCPUColorTable() return colors; } +/** + * @brief Create a Hash table of Rainbow colors. The Steam Ids are + * mapped to the palette of Rainbow colors. + * + * @returns ColorTable instance. + */ +ColorTable getStreamColorTable() +{ + kshark_context *kshark_ctx(nullptr); + ColorTable colors; + Color color; + float alpha(.35); + int *streamIds; + + if (!kshark_instance(&kshark_ctx)) + return colors; + + streamIds = kshark_all_streams(kshark_ctx); + for (int i = 0; i < kshark_ctx->n_streams; ++i) { + /* + * Starting from index 6 provides better functioning of the + * color scheme slider. + */ + color.setRainbowColor(i + 6); + color.blend(alpha); + colors[streamIds[i]] = color; + } + + free(streamIds); + + return colors; +} + /** * @brief Search the Hash table of Rainbow colors for a particular key (pid). *
src/KsPlotTools.hpp +4 -0
@@ -47,6 +47,8 @@ public: void setRainbowColor(int n); + void blend(float alpha); + /** * @brief Get the C struct defining the RGB color. */
@@ -78,6 +80,8 @@ ColorTable getTaskColorTable(); ColorTable getCPUColorTable(); +ColorTable getStreamColorTable(); + Color getColor(ColorTable *colors, int pid); /** Represents an abstract graphical element. */
Signature · 1 line
2.25.1
PATCH v8 37/44 kernel-shark: Redefine the args of KsPlot::getColor()
In reply to Yordan Karadzhov (VMware)The function was originally designed to return the color that correspond to a given PID. However we now have 3 different color maps (for PID, CPU Id and Stream Id) and the same method can be used with each of the 3 maps. We also want to prevent the method from modifying the map itself.
--- src/KsPlotTools.cpp | 10 +++++----- src/KsPlotTools.hpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
src/KsPlotTools.cpp +5 -5
@@ -233,17 +233,17 @@ ColorTable getStreamColorTable() } /** - * @brief Search the Hash table of Rainbow colors for a particular key (pid). + * @brief Search the Hash table of Rainbow colors for a particular key (Id). * * @param colors: Input location for the ColorTable instance. - * @param pid: the Process Id to search for. + * @param id: The Id to search for. * - * @returns The Rainbow color of the key "pid". If "pid" does not exist, the + * @returns The Rainbow color of the key "id". If "id" does not exist, the * returned color is Black. */ -Color getColor(ColorTable *colors, int pid) +Color getColor(const ColorTable *colors, int id) { - auto item = colors->find(pid); + auto item = colors->find(id); if (item != colors->end()) return item->second;
src/KsPlotTools.hpp +1 -1
@@ -82,7 +82,7 @@ ColorTable getCPUColorTable(); ColorTable getStreamColorTable(); -Color getColor(ColorTable *colors, int pid); +Color getColor(const ColorTable *colors, int id); /** Represents an abstract graphical element. */ class PlotObject {
Signature · 1 line
2.25.1
PATCH v8 38/44 kernel-shark: Add TextBox class to KsPlot namespace
In reply to Yordan Karadzhov (VMware)This class represents a text that is printed/drawn inside a colorful frame.
--- src/KsPlotTools.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++ src/KsPlotTools.hpp | 40 ++++++++++++++++++ 2 files changed, 139 insertions(+)
src/KsPlotTools.cpp +99 -0
@@ -524,6 +524,105 @@ void Polygon::_draw(const Color &col, float size) const col.color_c_ptr(), size); } +/** The created object will print/draw only the text without the frame. */ +TextBox::TextBox() +: _text(""), + _font(nullptr) +{ + setPos(Point(0, 0)); + _box._visible = false; +} + + +/** The created object will print/draw only the text without the frame. */ +TextBox::TextBox(ksplot_font *f) +: _text(""), + _font(f) +{ + setPos(Point(0, 0)); + _box._visible = false; +} + +/** The created object will print/draw only the text without the frame. */ +TextBox::TextBox(ksplot_font *f, const std::string &text, const Point &pos) +: _text(text), + _font(f) +{ + setPos(pos); + _box._visible = false; +} + +/** The created object will print/draw only the text without the frame. */ +TextBox::TextBox(ksplot_font *f, const std::string &text, const Color &col, + const Point &pos) +: _text(text), + _font(f) +{ + _color = col; + setPos(pos); + _box._visible = false; +} + +/** The created object will print/draw the text and the frame. */ +TextBox::TextBox(ksplot_font *f, const std::string &text, const Color &col, + const Point &pos, int l, int h) +: _text(text), + _font(f) +{ + setPos(pos); + setBoxAppearance(col, l, h); +} + +/** + * @brief Set the position of the bottom-left corner of the frame. + * + * @param p: The coordinates of the bottom-left corner. + */ +void TextBox::setPos(const Point &p) +{ + _box.setPoint(0, p); +} + +/** + * @brief Set the color and the dimensions of the frame. + * + * @param col: The color of the frame. + * @param l: The length of the frame. + * @param h: The height of the frame. + */ +void TextBox::setBoxAppearance(const Color &col, int l, int h) +{ + _box.setFill(true); + _box._color = col; + _box._visible = true; + + if (h <= 0 && _font) + h = _font->height; + + _box.setPoint(1, _box.getPointX(0), _box.getPointY(0) - h); + _box.setPoint(2, _box.getPointX(0) + l, _box.getPointY(0) - h); + _box.setPoint(3, _box.getPointX(0) + l, _box.getPointY(0)); +} + +void TextBox::_draw(const Color &col, float size) const +{ + _box.draw(); + if (!_font || _text.empty()) + return; + + if (_box._visible ) { + int bShift = (_box.getPointY(0) - _box.getPointY(1) - _font->height) / 2; + ksplot_print_text(_font, NULL, + _box.getPointX(0) + _font->height / 4, + _box.getPointY(0) - _font->base - bShift, + _text.c_str()); + } else { + ksplot_print_text(_font, col.color_c_ptr(), + _box.getPointX(0) + _font->height / 4, + _box.getPointY(0) - _font->base, + _text.c_str()); + } +} /** * @brief Create a default Mark.
src/KsPlotTools.hpp +40 -0
@@ -307,6 +307,46 @@ public: virtual ~Rectangle() {} }; +/** + * This class represents a text that is printed/drawn inside a colorful frame. + */ +class TextBox : public PlotObject { +public: + TextBox(); + + TextBox(ksplot_font *f); + + TextBox(ksplot_font *f, const std::string &text, const Point &pos); + + TextBox(ksplot_font *f, const std::string &text, const Color &col, + const Point &pos); + + TextBox(ksplot_font *f, const std::string &text, const Color &col, + const Point &pos, int l, int h = -1); + + /** Destroy the TextBox object. Keep this destructor virtual. */ + virtual ~TextBox() {} + + /** Set the font to be used. */ + void setFont(ksplot_font *f) {_font = f;} + + /** Set the text. */ + void setText(const std::string &t) {_text = t;} + + void setPos(const Point &p); + + void setBoxAppearance(const Color &col, int l, int h); + +private: + void _draw(const Color &, float size = 1.) const override; + + std::string _text; + + ksplot_font *_font; + + Rectangle _box; +}; + /** * This class represents the graphical element of the KernelShark GUI marker. */
Signature · 1 line
2.25.1
PATCH v8 39/44 kernel-shark: Consistent method naming in KsPlotTools
In reply to Yordan Karadzhov (VMware)Remove "get" from the name of the methods used to retrieve data fields in KsPlotTools. This makes the naming consistent with the style used by Qt.
--- src/KsPlotTools.cpp | 30 +++++++++++++++--------------- src/KsPlotTools.hpp | 34 +++++++++++++++++----------------- 2 files changed, 32 insertions(+), 32 deletions(-)
src/KsPlotTools.cpp +15 -15
@@ -120,7 +120,7 @@ void Color::blend(float alpha) * * @returns ColorTable instance. */ -ColorTable getTaskColorTable() +ColorTable taskColorTable() { struct kshark_context *kshark_ctx(nullptr); int nTasks(0), pid, *pids, i(0), *streamIds;
@@ -173,7 +173,7 @@ ColorTable getTaskColorTable() * * @returns ColorTable instance. */ -ColorTable getCPUColorTable() +ColorTable CPUColorTable() { kshark_context *kshark_ctx(nullptr); int nCPUs, nCPUMax(0), *streamIds;
@@ -205,7 +205,7 @@ ColorTable getCPUColorTable() * * @returns ColorTable instance. */ -ColorTable getStreamColorTable() +ColorTable streamColorTable() { kshark_context *kshark_ctx(nullptr); ColorTable colors;
@@ -360,7 +360,7 @@ void Shape::setPoint(size_t i, const Point &p) * @brief Get the point "i". If the point does not exist, the function returns * nullptr. */ -const ksplot_point *Shape::getPoint(size_t i) const +const ksplot_point *Shape::point(size_t i) const { if (i < _nPoints) return &_points[i];
@@ -394,7 +394,7 @@ void Shape::setPointY(size_t i, int y) { * @brief Get the horizontal coordinate of the point "i". If the point does * not exist, the function returns 0. */ -int Shape::getPointX(size_t i) const { +int Shape::pointX(size_t i) const { if (i < _nPoints) return _points[i].x;
@@ -405,7 +405,7 @@ int Shape::getPointX(size_t i) const { * @brief Get the vertical coordinate of the point "i". If the point does * not exist, the function returns 0. */ -int Shape::getPointY(size_t i) const { +int Shape::pointY(size_t i) const { if (i < _nPoints) return _points[i].y;
@@ -599,9 +599,9 @@ void TextBox::setBoxAppearance(const Color &col, int l, int h) if (h <= 0 && _font) h = _font->height; - _box.setPoint(1, _box.getPointX(0), _box.getPointY(0) - h); - _box.setPoint(2, _box.getPointX(0) + l, _box.getPointY(0) - h); - _box.setPoint(3, _box.getPointX(0) + l, _box.getPointY(0)); + _box.setPoint(1, _box.pointX(0), _box.pointY(0) - h); + _box.setPoint(2, _box.pointX(0) + l, _box.pointY(0) - h); + _box.setPoint(3, _box.pointX(0) + l, _box.pointY(0)); } void TextBox::_draw(const Color &col, float size) const
@@ -611,15 +611,15 @@ void TextBox::_draw(const Color &col, float size) const return; if (_box._visible ) { - int bShift = (_box.getPointY(0) - _box.getPointY(1) - _font->height) / 2; + int bShift = (_box.pointY(0) - _box.pointY(1) - _font->height) / 2; ksplot_print_text(_font, NULL, - _box.getPointX(0) + _font->height / 4, - _box.getPointY(0) - _font->base - bShift, + _box.pointX(0) + _font->height / 4, + _box.pointY(0) - _font->base - bShift, _text.c_str()); } else { ksplot_print_text(_font, col.color_c_ptr(), - _box.getPointX(0) + _font->height / 4, - _box.getPointY(0) - _font->base, + _box.pointX(0) + _font->height / 4, + _box.pointY(0) - _font->base, _text.c_str()); } }
@@ -808,7 +808,7 @@ void Graph::_initBins() /** * Get the number of bins. */ -int Graph::size() +int Graph::size() const { return _size; }
src/KsPlotTools.hpp +17 -17
@@ -64,7 +64,7 @@ public: * @brief Get the frequency value used to generate the Rainbow * palette. */ - static float getRainbowFrequency() {return _frequency;} + static float rainbowFrequency() {return _frequency;} private: ksplot_color _col_c;
@@ -76,11 +76,11 @@ private: /** Hash table of colors. */ typedef std::unordered_map<int, KsPlot::Color> ColorTable; -ColorTable getTaskColorTable(); +ColorTable taskColorTable(); -ColorTable getCPUColorTable(); +ColorTable CPUColorTable(); -ColorTable getStreamColorTable(); +ColorTable streamColorTable(); Color getColor(const ColorTable *colors, int id);
@@ -143,15 +143,15 @@ public: void setPoint(size_t i, const Point &p); - const ksplot_point *getPoint(size_t i) const; + const ksplot_point *point(size_t i) const; void setPointX(size_t i, int x); void setPointY(size_t i, int y); - int getPointX(size_t i) const; + int pointX(size_t i) const; - int getPointY(size_t i) const; + int pointY(size_t i) const; /** * @brief Get the number of point used to define the polygon.
@@ -179,10 +179,10 @@ public: virtual ~Point() {} /** @brief Get the horizontal coordinate of the point. */ - int x() const {return getPointX(0);} + int x() const {return pointX(0);} /** @brief Get the vertical coordinate of the point. */ - int y() const {return getPointY(0);} + int y() const {return pointY(0);} /** @brief Set the horizontal coordinate of the point. */ void setX(int x) {setPointX(0, x);}
@@ -201,7 +201,7 @@ public: /** * @brief Get the C struct defining the point. */ - const ksplot_point *point_c_ptr() const {return getPoint(0);} + const ksplot_point *point_c_ptr() const {return point(0);} private: void _draw(const Color &col, float size = 1.) const override;
@@ -235,7 +235,7 @@ public: void setA(int x, int y) { setPoint(0, x, y);} /** @brief Get the first finishing point of the line. */ - const ksplot_point *getA() const {return getPoint(0);} + const ksplot_point *a() const {return point(0);} /** * @brief Set the coordinats of the second finishing point of the
@@ -247,7 +247,7 @@ public: void setB(int x, int y) {setPoint(1, x, y);} /** @brief Get the second finishing point of the line. */ - const ksplot_point *getB() const {return getPoint(1);} + const ksplot_point *b() const {return point(1);} private: void _draw(const Color &col, float size = 1.) const override;
@@ -408,7 +408,7 @@ public: void drawVal(float size = 2.); /** Get the height (module) of the line, representing the Bin. */ - int mod() {return _val.y() - _base.y();} + int mod() const {return _val.y() - _base.y();} /** @brief Set the vertical coordinate of the "val" Point. */ void setVal(int v) {_val.setY(_base.y() - v); }
@@ -458,7 +458,7 @@ public: /* Keep this destructor virtual. */ virtual ~Graph(); - int size(); + int size() const; void setModelPtr(kshark_trace_histo *histo);
@@ -485,12 +485,12 @@ public: void setBase(int b); /** @brief Get the vertical coordinate of the Graph's base. */ - int getBase() const {return _bins[0]._base.y();} + int base() const {return _bins[0]._base.y();} void setHeight(int h); /** @brief Get the vertical size (height) of the Graph. */ - int getHeight() const {return _height;} + int height() const {return _height;} void setBinValue(int bin, int val);
@@ -504,7 +504,7 @@ public: const Color &col, uint8_t m); /** @brief Get a particular bin. */ - const Bin &getBin(int bin) const {return _bins[bin];} + const Bin &bin(int bin) const {return _bins[bin];} void setHMargin(int hMargin);
Signature · 1 line
2.25.1
PATCH v8 40/44 kernel-shark: Make the label part of the graph
In reply to Yordan Karadzhov (VMware)The capability to draw text with OpenGL is used. With this functionality we will no longer need to create special Qt widgets containing the text of the labels and carefully align those widgets next to the OpenGL plotting area. This will greatly simplify the internel structure of the TraceGraph widget.
--- src/KsPlotTools.cpp | 34 +++++++++++++++++++++++++--------- src/KsPlotTools.hpp | 18 +++++++++++++++--- 2 files changed, 40 insertions(+), 12 deletions(-)
src/KsPlotTools.cpp +25 -9
@@ -759,6 +759,7 @@ Graph::Graph() _collectionPtr(nullptr), _binColors(nullptr), _ensembleColors(nullptr), + _label(), _zeroSuppress(false) {}
@@ -777,6 +778,7 @@ Graph::Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct, KsPlot::ColorTa _collectionPtr(nullptr), _binColors(bct), _ensembleColors(ect), + _label(), _zeroSuppress(false) { if (!_bins) {
@@ -795,10 +797,15 @@ Graph::~Graph() delete[] _bins; } +int Graph::_firstBinOffset() +{ + return _labelSize + 2 * _hMargin; +} + void Graph::_initBins() { for (int i = 0; i < _size; ++i) { - _bins[i]._base.setX(i + _hMargin); + _bins[i]._base.setX(i + _firstBinOffset()); _bins[i]._base.setY(0); _bins[i]._val.setX(_bins[i]._base.x()); _bins[i]._val.setY(_bins[i]._base.y());
@@ -852,6 +859,8 @@ void Graph::setBase(int b) if (b == _bins[0]._base.y()) // Nothing to do. return; + _label.setBoxAppearance(_label._color, _labelSize, height()); + for (int i = 0; i < _size; ++i) { mod = _bins[i].mod(); _bins[i]._base.setY(b);
@@ -870,24 +879,29 @@ void Graph::setHeight(int h) } /** - * @brief Set the size of the white space added on both sides of the Graph. + * @brief Set the color and the dimensions of the graph's label. * - * @param hMargin: the size of the white space in pixels. + * @param f: The font to be used to draw the labels. + * @param col: The color of the ComboGraph's label. + * @param lSize: the size of the graph's label in pixels. + * @param hMargin: the size of the white margine space in pixels. */ -void Graph::setHMargin(int hMargin) +void Graph::setLabelAppearance(ksplot_font *f, Color col, int lSize, int hMargin) { if (!_size) return; - if (hMargin == _bins[0]._base.x()) // Nothing to do. - return; + _labelSize = lSize; + _hMargin = hMargin; + + _label.setPos({_hMargin, base()}); + _label.setFont(f); + _label.setBoxAppearance(col, lSize, height()); for (int i = 0; i < _size; ++i) { - _bins[i]._base.setX(i + hMargin); + _bins[i]._base.setX(i + _firstBinOffset()); _bins[i]._val.setX(_bins[i]._base.x()); } - - _hMargin = hMargin; } /**
@@ -1312,6 +1326,8 @@ void Graph::draw(float size) int lastPid(-1), b(0), boxH(_height * .3); Rectangle taskBox; + _label.draw(); + /* * Start by drawing a line between the base points of the first and * the last bin.
src/KsPlotTools.hpp +15 -3
@@ -506,7 +506,11 @@ public: /** @brief Get a particular bin. */ const Bin &bin(int bin) const {return _bins[bin];} - void setHMargin(int hMargin); + /** Set the text of the graph's label. */ + void setLabelText(std::string text) {_label.setText(text);} + + void setLabelAppearance(ksplot_font *f, Color col, + int lSize, int hMargin); /** * Check if this graph is Zero Suppressed. Zero Suppressed means that
@@ -521,7 +525,7 @@ public: */ void setZeroSuppressed(bool zs) {_zeroSuppress = zs;} -private: +protected: /** Pointer to the model descriptor object. */ kshark_trace_histo *_histoPtr;
@@ -537,6 +541,9 @@ private: */ int _hMargin; + /** The horizontal size of the Graph's label. */ + int _labelSize; + /** The vertical size (height) of the Graph. */ int _height;
@@ -549,9 +556,14 @@ private: /** Hash table of ensemble's colors. */ ColorTable *_ensembleColors; +private: + TextBox _label; + bool _zeroSuppress; - void _initBins(); + void _initBins(); + + int _firstBinOffset(); }; }; // KsPlot
Signature · 1 line
2.25.1
PATCH v8 41/44 kernel-shark: Remove the hard-coded Idle PID
In reply to Yordan Karadzhov (VMware)KernelShark plots differently all events coming from Idle tasks. This is done in order to provide more intuitive visualization of the Idleness of the system. So far the process Id of the Idle task was assumed to be Zero. However this is true only for Linux systems. In this patch we make the PID of the Idle task configurable.
--- src/KsPlotTools.cpp | 48 +++++++++++++++++++++++++++++++++------------ src/KsPlotTools.hpp | 22 +++++++++------------ 2 files changed, 44 insertions(+), 26 deletions(-)
src/KsPlotTools.cpp +35 -13
@@ -755,12 +755,13 @@ Graph::Graph() : _histoPtr(nullptr), _bins(nullptr), _size(0), - _hMargin(30), _collectionPtr(nullptr), _binColors(nullptr), _ensembleColors(nullptr), _label(), - _zeroSuppress(false) + _idleSuppress(false), + _idlePid(0), + _drawBase(true) {} /**
@@ -774,12 +775,13 @@ Graph::Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct, KsPlot::ColorTa : _histoPtr(histo), _bins(new(std::nothrow) Bin[histo->n_bins]), _size(histo->n_bins), - _hMargin(30), _collectionPtr(nullptr), _binColors(bct), _ensembleColors(ect), _label(), - _zeroSuppress(false) + _idleSuppress(false), + _idlePid(0), + _drawBase(true) { if (!_bins) { _size = 0;
@@ -904,6 +906,20 @@ void Graph::setLabelAppearance(ksplot_font *f, Color col, int lSize, int hMargin } } +/** + * @brief Set Idle Suppression. If True, the bins containing Idle task records + * are not grouped together. + * + * @param is: If True, Idle is suppressed. + * @param ip: The process Id of the Idle task. If Idle is not suppressed, this + * value has no effect. + */ +void Graph::setIdleSuppressed(bool is, int ip) +{ + _idleSuppress = is; + _idlePid = ip; +} + /** * @brief Set the value of a given bin. *
@@ -916,7 +932,7 @@ void Graph::setBinValue(int bin, int val) } /** - * @brief Set the Process Id (Front and Back) a given bin. + * @brief Set the Process Id (Front and Back) of a given bin. * * @param bin: Bin Id. * @param pidF: The Process Id detected at the from (first in time) edge of
@@ -1328,22 +1344,28 @@ void Graph::draw(float size) _label.draw(); - /* - * Start by drawing a line between the base points of the first and - * the last bin. - */ - drawLine(_bins[0]._base, _bins[_size - 1]._base, {}, size); + if (_drawBase) { + /* + * Start by drawing a line between the base points of the first and + * the last bin. + */ + drawLine(_bins[0]._base, _bins[_size - 1]._base, {}, size); + } /* Draw as vartical lines all bins containing data. */ for (int i = 0; i < _size; ++i) - if (_bins[i]._idFront >= 0 || _bins[i]._idBack >= 0) + if (_bins[i]._idFront >= 0 || _bins[i]._idBack >= 0 || + _bins[i]._idFront == _idlePid || _bins[i]._idBack ==_idlePid) if (_bins[i]._visMask & KS_EVENT_VIEW_FILTER_MASK) { _bins[i]._size = size; _bins[i].draw(); } auto lamCheckEnsblVal = [this] (int v) { - return v > 0 || (v == 0 && !this->_zeroSuppress); + if (_idleSuppress && v == _idlePid) + return false; + + return v >= 0; }; /*
@@ -1424,4 +1446,4 @@ void Graph::draw(float size) } } -}; // KsPlot +} // KsPlot
src/KsPlotTools.hpp +9 -13
@@ -449,7 +449,7 @@ public: */ Graph(const Graph &) = delete; - /* Disable moving. Same as copying.*/ + /* Disable moving. Same as copying. */ Graph(Graph &&) = delete; Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct,
@@ -512,18 +512,10 @@ public: void setLabelAppearance(ksplot_font *f, Color col, int lSize, int hMargin); - /** - * Check if this graph is Zero Suppressed. Zero Suppressed means that - * bins having Id value = 0 (Idle task records) are not grouped - * together. - */ - bool zeroSuppressed(bool zs) {return _zeroSuppress;} + void setIdleSuppressed(bool is, int ip = 0); - /** - * Set Zero Suppression. If True, the bins having Id value = 0 (Idle - * task records) are not grouped together. - */ - void setZeroSuppressed(bool zs) {_zeroSuppress = zs;} + /** Draw the base line of the graph or not. */ + void setDrawBase(bool b) {_drawBase = b;} protected: /** Pointer to the model descriptor object. */
@@ -559,7 +551,11 @@ protected: private: TextBox _label; - bool _zeroSuppress; + bool _idleSuppress; + + int _idlePid; + + bool _drawBase; void _initBins();
Signature · 1 line
2.25.1
PATCH v8 42/44 kernel-shark: Add class Polyline to KsPlot namespace
In reply to Yordan Karadzhov (VMware)This is a simple plotting class that represents a poly-line.
--- src/KsPlotTools.cpp | 14 ++++++++++++++ src/KsPlotTools.hpp | 16 ++++++++++++++++ 2 files changed, 30 insertions(+)
src/KsPlotTools.cpp +14 -0
@@ -503,6 +503,20 @@ void Line::_draw(const Color &col, float size) const col.color_c_ptr(), size); } +/** + * @brief Create a default polyline. All points are initialized at (0, 0). + * + * @param n: The number of points connected by the polyline. + */ +Polyline::Polyline(size_t n) +: Shape(n) +{} + +void Polyline::_draw(const Color &col, float size) const +{ + ksplot_draw_polyline(_points, _nPoints, col.color_c_ptr(), size); +} + /** * @brief Create a default polygon. All points are initialized at (0, 0). *
src/KsPlotTools.hpp +16 -0
@@ -253,6 +253,22 @@ private: void _draw(const Color &col, float size = 1.) const override; }; +/** This class represents a polyline. */ +class Polyline : public Shape { +public: + Polyline(size_t n); + + /** + * @brief Destroy the polyline object. Keep this destructor virtual. + */ + virtual ~Polyline() {} + +private: + Polyline() = delete; + + void _draw(const Color &, float size = 1.) const override; +}; + /** This class represents a polygon. */ class Polygon : public Shape { public:
Signature · 1 line
2.25.1
PATCH v8 43/44 kernel-shark: Add VirtBridge and VirtGap classes
In reply to Yordan Karadzhov (VMware)The two simple plotting classes will be used to visualise the guest->host data correlations.
--- src/KsPlotTools.cpp | 22 +++++++++++++++++++++ src/KsPlotTools.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
src/KsPlotTools.cpp +22 -0
@@ -1460,4 +1460,26 @@ void Graph::draw(float size) } } +void VirtGap::_draw(const Color &col, float size) const +{ + if (_entryPoint.x() - _exitPoint.x() < 4) + return; + + Point p0(_exitPoint.x() + _size, _exitPoint.y()); + Point p1(_exitPoint.x() + _size, _exitPoint.y() - _height); + Point p2(_entryPoint.x() - _size , _entryPoint.y()); + Point p3(_entryPoint.x() - _size , _entryPoint.y() - _height); + + Rectangle g; + + g.setPoint(0, p0); + g.setPoint(1, p1); + g.setPoint(2, p2); + g.setPoint(3, p3); + + g._color = {255, 255, 255}; // The virt. gap is always white. + g.setFill(false); + g.draw(); +} + } // KsPlot
src/KsPlotTools.hpp +47 -0
53 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 44/44 kernel-shark: Add double click interface to PlotObject
In reply to Yordan Karadzhov (VMware)The interface consists of two virtual methods that have to be implemented by the inheriting classes. The first implements the double-click action of the object while the second one calculates the distance between the object and the exact position of the mouse click. The second method is used by the GUI to decide if the double-click action has to be executed or not. The patch contains a simple method for retrieving the geometrical center of a Shape. This helper method can be useful when implementing the calculation of the distance in the inheriting classes.
--- src/KsPlotTools.cpp | 31 +++++++++++++++++++++++++++++++ src/KsPlotTools.hpp | 14 ++++++++++++++ 2 files changed, 45 insertions(+)
src/KsPlotTools.cpp +31 -0
@@ -251,6 +251,21 @@ Color getColor(const ColorTable *colors, int id) return {}; } +/** + * @brief A method to be implemented in the inheriting class. It calculates + * the distance between the position of the click and the shape. This + * distance is used by the GUI to decide if the corresponding + * "Double click" action of the shape must be executed. The default + * implementation returns infinity. + * + * @param x: The X coordinate of the click. + * @param y: The Y coordinate of the click. + */ +double PlotObject::distance(int x, int y) const +{ + return std::numeric_limits<double>::max(); +} + /** * @brief Create a default Shape. */
@@ -298,6 +313,22 @@ Shape::~Shape() { delete[] _points; } +/** @brief Get the coordinates of the geometrical center of this shape. */ +ksplot_point Shape::center() const +{ + ksplot_point c = {0, 0}; + + for (size_t i = 0; i < _nPoints; ++i) { + c.x += _points[i].x; + c.y += _points[i].y; + } + + c.x /= _nPoints; + c.y /= _nPoints; + + return c; +} + /** Assignment operator. */ void Shape::operator=(const Shape &s) {
src/KsPlotTools.hpp +14 -0
@@ -103,6 +103,16 @@ public: _draw(_color, _size); } + /** + * Generic action to be executed when the objects is double clicked. + */ + void doubleClick() const { + if (_visible) + _doubleClick(); + } + + virtual double distance(int x, int y) const; + /** Is this object visible. */ bool _visible;
@@ -114,6 +124,8 @@ public: private: virtual void _draw(const Color &col, float s) const = 0; + + virtual void _doubleClick() const {} }; /** List of graphical element. */
@@ -135,6 +147,8 @@ public: /* Keep this destructor virtual. */ virtual ~Shape(); + ksplot_point center() const; + void operator=(const Shape &s); void setPoint(size_t i, int x, int y);
Signature · 1 line
2.25.1
Quoted 9 lines · On Mon, 4 Jan 2021 19:46:40 +0200 "Yordan Karadzhov (VMware)"…
In this patch-set we are starting the introduction of the changes in the C API of libkshark. The goal of this transformation is to turn KernelShark into a general purpose toolkit for analysis of tracing data that is no longer strongly coupled to the Ftrace/trace-cmd data format. At the end of the transformation KernelShark will be able to merge and simultaneously visualize data from different tracers, recorded in different data formats. It will also significantly extend the possibilities for user customization.
Quoted 4 lines
This patch-set transforms the way KernelShark processes the raw tracing data. Later, in a consecutive patch-sets we will introduce the changes in the visualization instruments and in the KernelShark GUI itself.
Hi Yordan,
I don't think you noticed that I applied your last series, with tweaks (commenting in the change log what I tweaked).
Can you rebase this series against mainline?
git://git.kernel.org/pub/scm/utils/trace-cmd/kernel-shark.git
Thanks!
-- Steve