Start KernelShark v2 transformation
v7 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 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) (31):
kernel-shark: Add license information
kernel-shark: Change the CMake minimum version required
kernel-shark: Use libtraceevent and libtracefs
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: Do not use the ARRAY_SIZE macro
kernel-shark: Add basic infrastructure for testing
.github/workflows/main.yml | 61 + CMakeLists.txt | 25 +- Documentation/doxygen/dox_config | 1 + LICENSES/GPL-2.0 | 359 +++ LICENSES/LGPL-2.1 | 503 +++ README | 129 +- build/FindJSONC.cmake | 70 +- build/FindTraceCmd.cmake | 53 +- build/FindTraceEvent.cmake | 75 + build/FindTraceFS.cmake | 75 + build/cmake_clean.sh | 4 + build/deff.h.cmake | 15 +- 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 | 18 +- 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/stb_truetype.h | 5011 ++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 14 + tests/libkshark-tests.cpp | 48 + 35 files changed, 13177 insertions(+), 1992 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 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 v7 1/32 kernel-shark: Add license information
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 v7 2/32 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 v7 3/32 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.
--- CMakeLists.txt | 8 +++- build/FindTraceCmd.cmake | 53 ++------------------------- build/FindTraceEvent.cmake | 75 ++++++++++++++++++++++++++++++++++++++ build/FindTraceFS.cmake | 75 ++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 4 +- src/libkshark.c | 10 ++--- 6 files changed, 166 insertions(+), 59 deletions(-) create mode 100644 build/FindTraceEvent.cmake create mode 100644 build/FindTraceFS.cmake
CMakeLists.txt +6 -2
@@ -22,6 +22,11 @@ if (NOT _LIBDIR) endif (NOT _LIBDIR) include(${KS_DIR}/build/FindTraceCmd.cmake) + +set(CMAKE_MODULE_PATH "${KS_DIR}/build") +find_package(TraceEvent REQUIRED) +find_package(TraceFS REQUIRED) + include(${KS_DIR}/build/FindJSONC.cmake) find_package(Doxygen)
@@ -80,8 +85,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 +3 -50
68 lines not on this page · raw message
build/FindTraceEvent.cmake new file +75 -0
75 lines not on this page · raw message
build/FindTraceFS.cmake new file +75 -0
75 lines not on this page · raw message
src/CMakeLists.txt +2 -2
@@ -8,8 +8,8 @@ add_library(kshark SHARED libkshark.c libkshark-collection.c) target_link_libraries(kshark ${TRACECMD_LIBRARY} - ${TRACEFS_LIBRARY} - ${TRACEEVENT_LIBRARY} + 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,
Signature · 1 line
2.25.1
Re: [PATCH v7 03/32] kernel-shark: Use libtraceevent and libtracefs
Quoted 6 lines · On Fri, 11 Dec 2020 16:44:42 +0200 "Yordan Karadzhov (VMware)"…
libtraceevent and libtracefs are now stand-alone libraries, independent form trace-cmd. Start building and linking KernelShark against those independent libraries.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>---
We need to do the same thing for libtracecmd, as it's going to be installed in a different place as well, depending on pkg-config.
Thanks!
-- Steve
PATCH v7 4/32 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 v7 5/32 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 | 4 +-- build/FindJSONC.cmake | 70 +++++++++++++++++++++++++++++++++---------- src/CMakeLists.txt | 2 +- 3 files changed, 57 insertions(+), 19 deletions(-)
CMakeLists.txt +1 -3
@@ -26,8 +26,7 @@ include(${KS_DIR}/build/FindTraceCmd.cmake) set(CMAKE_MODULE_PATH "${KS_DIR}/build") find_package(TraceEvent REQUIRED) find_package(TraceFS REQUIRED) - -include(${KS_DIR}/build/FindJSONC.cmake) +find_package(JSONC REQUIRED) find_package(Doxygen)
@@ -84,7 +83,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
@@ -10,7 +10,7 @@ add_library(kshark SHARED libkshark.c target_link_libraries(kshark ${TRACECMD_LIBRARY} trace::fs trace::event - ${JSONC_LIBRARY} + jsonc::jsonc ${CMAKE_DL_LIBS}) set_target_properties(kshark PROPERTIES SUFFIX ".so.${KS_VERSION_STRING}")
Signature · 1 line
2.25.1
PATCH v7 6/32 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 v7 7/32 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 v7 8/32 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
@@ -2,6 +2,7 @@ message("\n src ...") 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 v7 9/32 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 v7 10/32 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);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);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 v7 11/32 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