On Wed, 18 Nov 2020 16:49:57 +0200 "Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote: > The C API provides loading of the trace data in two different forms. > The firs one is an array of kshark_entries and is being used by the "first one" > 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. > > Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> > --- > examples/CMakeLists.txt | 4 + > examples/multibufferload.c | 60 +++++++++ > src/libkshark.c | 255 +++++++++++++++++++++++++++++++++++++ > src/libkshark.h | 47 +++++++ > 4 files changed, 366 insertions(+) > create mode 100644 examples/multibufferload.c > > diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt > index 8d40e42c..831eee24 100644 > --- a/examples/CMakeLists.txt > +++ b/examples/CMakeLists.txt > @@ -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) > diff --git a/examples/multibufferload.c b/examples/multibufferload.c > new file mode 100644 > index 00000000..70b2733a > --- /dev/null > +++ b/examples/multibufferload.c > @@ -0,0 +1,60 @@ > +#include <stdio.h> > +#include <stdlib.h> > + > +#include "libkshark.h" > +#include "libkshark-tepdata.h" > + > +const char *default_file = "trace.dat"; > + > +void put_entry(struct kshark_entry *e) > +{ > + char *entry_str = kshark_dump_entry(e); > + puts(entry_str); > + free(entry_str); > +} > + > +int main(int argc, char **argv) > +{ > + struct kshark_context *kshark_ctx; > + struct kshark_entry **data = NULL; > + ssize_t r, n_rows; > + int sd; > + > + /* Create a new kshark session. */ > + kshark_ctx = NULL; > + if (!kshark_instance(&kshark_ctx)) > + return 1; > + > + /* Open a trace data file produced by trace-cmd. */ > + if (argc > 1) > + sd = kshark_open(kshark_ctx, argv[1]); > + else > + sd = kshark_open(kshark_ctx, default_file); I'm confused. It doesn't look like this merges more than one stream. -- Steve > + > + if (sd < 0) { > + kshark_free(kshark_ctx); > + return 1; > + } > + > + /* Initialize data streams for all buffers in this file. */ > + kshark_tep_init_all_buffers(kshark_ctx, sd); > + > + /* Load all buffers. */ > + n_rows = kshark_load_all_entries(kshark_ctx, &data); > + > + /* Print to the screen the first 20 entries. */ > + for (r = 0; r < 20; ++r) > + put_entry(data[r]); > + > + /* Free the memory. */ > + for (r = 0; r < n_rows; ++r) > + free(data[r]); > + free(data); > + > + kshark_close_all(kshark_ctx); > + > + /* Close the session. */ > + kshark_free(kshark_ctx); > + > + return 0; > +}