Add visualization model for the Qt-based KernelShark
v4 cover Add visualization model for the Qt-based KernelShark
This series of patches introduces the second part of the C API used by the Qt-based version of KernelShark. This part of the API is responsible for the visual navigation and browsing inside the trace data.
This is version 4 of this series of patches.
Major changes from v3 are:
[2/7] Corrections in the Doxygen documentation. Debugging in ksmodel_set_upper_edge().
[4/7] Corrections in the Doxygen documentation & Change log. Trying to eliminate the duplicated code in map_collection_back_request() and map_collection_front_request().
Yordan Karadzhov (VMware) (6):
kernel-shark-qt: Add generic instruments for searching inside the
trace data
kernel-shark-qt: Introduce the visualization model used by the
Qt-based KS
kernel-shark-qt: Add an example showing how to manipulate the Vis.
model.
kernel-shark-qt: Define Data collections
kernel-shark-qt: Make the Vis. model use Data collections.
kernel-shark-qt: Changed the KernelShark version identifier.
kernel-shark-qt/CMakeLists.txt | 2 +- kernel-shark-qt/examples/CMakeLists.txt | 4 + kernel-shark-qt/examples/datahisto.c | 159 +++ kernel-shark-qt/src/CMakeLists.txt | 4 +- kernel-shark-qt/src/libkshark-collection.c | 818 +++++++++++++ kernel-shark-qt/src/libkshark-model.c | 1224 ++++++++++++++++++++ kernel-shark-qt/src/libkshark-model.h | 167 +++ kernel-shark-qt/src/libkshark.c | 278 +++++ kernel-shark-qt/src/libkshark.h | 177 +++ 9 files changed, 2831 insertions(+), 2 deletions(-) create mode 100644 kernel-shark-qt/examples/datahisto.c create mode 100644 kernel-shark-qt/src/libkshark-collection.c create mode 100644 kernel-shark-qt/src/libkshark-model.c create mode 100644 kernel-shark-qt/src/libkshark-model.h
Signature · 1 line
2.17.1
PATCH v4 1/6 kernel-shark-qt: Add generic instruments for searching inside the trace data
This patch introduces the instrumentation for data extraction used by the visualization model of the Qt-based KernelShark. The effectiveness of these instruments for searching has a dominant effect over the performance of the model, so let's spend some time and explain this in detail.
The first type of instruments provide binary search inside a sorted in time arrays of kshark_entries or trace_records. The search returns the first element of the array, having timestamp bigger than a reference time value. The time complexity of these searches is log(n).
The second type of instruments provide searching for the first (in time) entry, satisfying an abstract Matching condition. Since the array is sorted in time, but we search for an abstract property, for this search the array is considered unsorted, thus we have to iterate and check all elements of the array one by one. If we search for a type of entries, which are well presented in the array, the time complexity of the search is constant, because no matter how big is the array the search only goes through small number of entries at the beginning of the array (or at the end, if we search backwards), before it finds the first match. However if we search for sparse, or even nonexistent entries, the time complexity becomes linear.
These explanations will start making more sense with the following patches.
--- kernel-shark-qt/src/libkshark.c | 262 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 93 ++++++++++++ 2 files changed, 355 insertions(+)
kernel-shark-qt/src/libkshark.c +262 -0
@@ -925,3 +925,265 @@ char* kshark_dump_entry(const struct kshark_entry *entry)return NULL ; } + +/** +* @brief Binary search inside a time-sorted array of kshark_entries. +* +* @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 kshark_entry 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_entry_by_time (uint64_t time, +struct kshark_entry **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 +* entry having timestamp < time and "h" will be the index of the first +* entry having timestamp >= time. +*/ +BSEARCH (h, l, data[mid]->ts < time); +return h; +} + +/** +* @brief Binary search inside a time-sorted array of pevent_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 pevent_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 pevent_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. +* +* @param kshark_ctx: Input location for the session context pointer. +* @param e: kshark_entry to be checked. +* @param pid: Matching condition value. +* +* @returns True if the Pid of the entry matches the value of "pid". +* Else false. +*/ +bool kshark_match_pid (struct kshark_context *kshark_ctx, +struct kshark_entry *e,int pid) +{ +if (e->pid == pid) +return true; + +return false; +} + +/** +* @brief Simple Cpu matching function to be user for data requests. +* +* @param kshark_ctx: Input location for the session context pointer. +* @param e: kshark_entry to be checked. +* @param cpu: Matching condition value. +* +* @returns True if the Cpu of the entry matches the value of "cpu". +* Else false. +*/ +bool kshark_match_cpu (struct kshark_context *kshark_ctx, +struct kshark_entry *e,int cpu) +{ +if (e->cpu == cpu) +return true; + +return false; +} + +/** +* @brief Create Data request. The request defines the properties of the +* requested kshark_entry. +* +* @param first: Array index specifying the position inside the array from +* where the search starts. +* @param n: Number of array elements to search in. +* @param cond: Matching condition function. +* @param val: Matching condition value, used by the Matching condition +* function. +* @param vis_only: If true, a visible entry is requested. +* @param vis_mask: If "vis_only" is true, use this mask to specify the level +* of visibility of the requested entry. +* +* @returns Pointer to kshark_entry_request on success, or NULL on failure. +* The user is responsible for freeing the returned +* kshark_entry_request. +*/ +struct kshark_entry_request * +kshark_entry_request_alloc (size_t first,size_t n, +matching_condition_func cond,int val, +bool vis_only,int vis_mask) +{ +struct kshark_entry_request *req =malloc (sizeof (*req)); + +if (!req) { +fprintf (stderr, +"Failed to allocate memory for entry request.\n" ); +return NULL ; + } + + req->first = first; + req->n = n; + req->cond = cond; + req->val = val; + req->vis_only = vis_only; + req->vis_mask = vis_mask; + +return req; +} + +/** Dummy entry, used to indicate the existence of filtered entries. */ +const struct kshark_entry dummy_entry = { + .next =NULL , + .visible =0x00 , + .cpu =KS_FILTERED_BIN , + .pid =KS_FILTERED_BIN , + .event_id =-1 , + .offset =0 , + .ts =0 +}; + +static const struct kshark_entry * +get_entry (const struct kshark_entry_request *req, +struct kshark_entry **data, +ssize_t *index,size_t start,ssize_t end,int inc) +{ +struct kshark_context *kshark_ctx =NULL ; +const struct kshark_entry *e =NULL ; +ssize_t i; + +if (index) + *index =KS_EMPTY_BIN ; + +if (!kshark_instance (&kshark_ctx)) +return e; + +for (i = start; i != end; i += inc) { +if (req->cond (kshark_ctx, data[i], req->val)) { +/* +* Data satisfying the condition has been found. +*/ +if (req->vis_only && + !(data[i]->visible & req->vis_mask)) { +/* This data entry has been filtered. */ + e = &dummy_entry; + }else { + e = data[i]; +break ; + } + } + } + +if (index) { +if (e) + *index = (e->event_id >=0 )? i :KS_FILTERED_BIN ; +else + *index =KS_EMPTY_BIN ; + } + +return e; +} + +/** +* @brief Search for an entry satisfying the requirements of a given Data +* request. Start from the position provided by the request and go +* searching in the direction of the increasing timestamps (front). +* +* @param req: Input location for Data request. +* @param data: Input location for the trace data. +* @param index: Optional output location for the index of the returned +* entry inside the array. +* +* @returns Pointer to the first entry satisfying the matching conditionon +* success, or NULL on failure. +* In the special case when some entries, satisfying the Matching +* condition function have been found, but all these entries have +* been discarded because of the visibility criteria (filtered +* entries), the function returns a pointer to a special +* "Dummy entry". +*/ +const struct kshark_entry * +kshark_get_entry_front (const struct kshark_entry_request *req, +struct kshark_entry **data, +ssize_t *index) +{ +ssize_t end = req->first + req->n; + +return get_entry (req, data, index, req->first, end,+1 ); +} + +/** +* @brief Search for an entry satisfying the requirements of a given Data +* request. Start from the position provided by the request and go +* searching in the direction of the decreasing timestamps (back). +* +* @param req: Input location for Data request. +* @param data: Input location for the trace data. +* @param index: Optional output location for the index of the returned +* entry inside the array. +* +* @returns Pointer to the first entry satisfying the matching conditionon +* success, or NULL on failure. +* In the special case when some entries, satisfying the Matching +* condition function have been found, but all these entries have +* been discarded because of the visibility criteria (filtered +* entries), the function returns a pointer to a special +* "Dummy entry". +*/ +const struct kshark_entry * +kshark_get_entry_back (const struct kshark_entry_request *req, +struct kshark_entry **data, +ssize_t *index) +{ +ssize_t end = req->first - req->n; + +if (end <0 ) + end =-1 ; + +return get_entry (req, data, index, req->first, end,-1 ); +}
kernel-shark-qt/src/libkshark.h +93 -0
99 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 2/6 kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Yordan Karadzhov (VMware)The model, used by the Qt-based KernelShark for visualization of trace data is build over the concept of "Data Bins". When visualizing a large data-set of trace records, we are limited by the number of screen pixels available for drawing. The model divides the data-set into data-units, also called Bins. The Bin has to be defined in such a way that the entire content of one Bin can be summarized and visualized by a single graphical element. This model uses the timestamp of the trace records, as a criteria for forming Bins. When the Model has to visualize all records inside a given time-window, it divides this time-window into N smaller, uniformly sized subintervals and then defines that one Bin contains all trace records, having timestamps falling into one of this subintervals. Because the model operates over an array of trace records, sorted in time, the content of each Bin can be retrieved by simply knowing the index of the first element inside this Bin and the index of the first element of the next Bin. This means that knowing the index of the first element in each Bin is enough to determine the State of the model.
The State of the model can be modified by its five basic operations: Zoon-In, Zoom-Out, Shift-Forward, Shift-Backward and Jump-To. After each of these operations, the new State of the model is retrieved, by using binary search to find the index of the first element in each Bin. This means that each one of the five basic operations of the model has log(n) time complexity (see previous change log).
In order to keep the visualization of the new state of the model as efficient as possible, the model needs a way to summarize and visualize the content of the Bins in constant time. This is achieved by limiting ourself to only checking the content of the records at the beginning and at the end of the Bin. As explaned in the previous change log, this approach has the very counter-intuitive effect of making the update of the sparse (or empty) Graphs much slower. The problem of the Sparse Graphs will be addressed in another patch, where "Data Collections" will be introduced.
--- kernel-shark-qt/src/CMakeLists.txt | 3 +- kernel-shark-qt/src/libkshark-model.c | 1183 +++++++++++++++++++++++++ kernel-shark-qt/src/libkshark-model.h | 157 ++++ kernel-shark-qt/src/libkshark.h | 6 +- 4 files changed, 1347 insertions(+), 2 deletions(-) create mode 100644 kernel-shark-qt/src/libkshark-model.c create mode 100644 kernel-shark-qt/src/libkshark-model.h
kernel-shark-qt/src/CMakeLists.txt +2 -1
@@ -1,7 +1,8 @@ message("\n src ...") message(STATUS "libkshark") -add_library(kshark SHARED libkshark.c) +add_library(kshark SHARED libkshark.c + libkshark-model.c) target_link_libraries(kshark ${CMAKE_DL_LIBS} ${TRACEEVENT_LIBRARY}
kernel-shark-qt/src/libkshark-model.c new file +1183 -0
1,183 lines not on this page · raw message
kernel-shark-qt/src/libkshark-model.h new file +157 -0
157 lines not on this page · raw message
kernel-shark-qt/src/libkshark.h +5 -1
@@ -225,7 +225,11 @@ bool kshark_match_pid(struct kshark_context *kshark_ctx,bool kshark_match_cpu (struct kshark_context *kshark_ctx,struct kshark_entry *e,int cpu); -/** Empty bin identifier. */ +/** +* Empty bin identifier. +* KS_EMPTY_BIN is used to reset entire arrays to empty with memset(), thus it +* must be -1 for that to work. +*/ #define KS_EMPTY_BIN -1/** Filtered bin identifier. */
Signature · 1 line
2.17.1
PATCH v4 3/6 kernel-shark-qt: Add an example showing how to manipulate the Vis. model.
In reply to Yordan Karadzhov (VMware)This patch introduces a basic example, showing how to initialize the Visualization model and to use the API to perform some of the basic operations.
--- kernel-shark-qt/examples/CMakeLists.txt | 4 + kernel-shark-qt/examples/datahisto.c | 155 ++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 kernel-shark-qt/examples/datahisto.c
kernel-shark-qt/examples/CMakeLists.txt +4 -0
@@ -7,3 +7,7 @@ target_link_libraries(dload 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)
kernel-shark-qt/examples/datahisto.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 4/6 kernel-shark-qt: Define Data collections
In reply to Yordan Karadzhov (VMware)Data collections are used to optimize the search for an entry having an abstract property, defined by a Matching condition function and a value.
When a collection is processed, the data which is relevant for the collection is enclosed in "Data intervals", defined by pairs of "Resume" and "Break" points. It is guaranteed that the data outside of the intervals contains no entries satisfying the abstract matching condition. In the same time the interval may (will) contain data that do not satisfy the matching condition. Keep in mind that the Collection is defined over an array of kshark_entries, sorted in time. Each interval will start (resume) at the index of the first appearance of an entry satisfying the matching condition. The definition of the Break point of the interval is a bit more complicated. The interval will be closed when we have an entry which still satisfies the condition, but the next entry on the same CPU no longer satisfies this condition.
Once defined, the Data collection can be used when searching for an entry having the same (ore related) abstract property. The collection allows to ignore the irrelevant data, thus it eliminates the linear worst-case time complexity of the search.
The user has the possibility to inflate each of the interval, by appending additional data which do not satisfy the matching condition (margin data). This data will be added to each interval at the beginning and at the end of the data which is relevant for the collection, as well as at the beginning and at the end of data-set. The margin data can be useful in the case when the user wants to be able to see what is happening before and after the appearance of his data of interest.
--- kernel-shark-qt/src/CMakeLists.txt | 3 +- kernel-shark-qt/src/libkshark-collection.c | 818 +++++++++++++++++++++ kernel-shark-qt/src/libkshark.c | 16 + kernel-shark-qt/src/libkshark.h | 80 ++ 4 files changed, 916 insertions(+), 1 deletion(-) create mode 100644 kernel-shark-qt/src/libkshark-collection.c
kernel-shark-qt/src/CMakeLists.txt +2 -1
@@ -2,7 +2,8 @@ message("\n src ...") message(STATUS "libkshark") add_library(kshark SHARED libkshark.c - libkshark-model.c) + libkshark-model.c + libkshark-collection.c) target_link_libraries(kshark ${CMAKE_DL_LIBS} ${TRACEEVENT_LIBRARY}
kernel-shark-qt/src/libkshark-collection.c new file +818 -0
818 lines not on this page · raw message
kernel-shark-qt/src/libkshark.c +16 -0
@@ -1067,6 +1067,7 @@ kshark_entry_request_alloc(size_t first, size_t n,return NULL ; } + req->next =NULL ; req->first = first; req->n = n; req->cond = cond;
@@ -1077,6 +1078,21 @@ kshark_entry_request_alloc(size_t first, size_t n,return req; } +/** +* @brief Free all Data requests in a given list. +* @param req: Intput location for the Data request list. +*/ +void kshark_free_entry_request (struct kshark_entry_request *req) +{ +struct kshark_entry_request *last; + +while (req) { + last = req; + req = req->next; +free (last); + } +} +/** Dummy entry, used to indicate the existence of filtered entries. */ const struct kshark_entry dummy_entry = { .next =NULL ,
kernel-shark-qt/src/libkshark.h +80 -0
104 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 4/6] kernel-shark-qt: Define Data collections
On Mon, 6 Aug 2018 19:19:25 +0300
"Yordan Karadzhov (VMware)" <[email protected]> wrote:
I like the combination of front and back.
Quoted 50 lines
kernel-shark-qt/src/libkshark-collection.c new file +50
-0+static ssize_t +map_collection_request_init (const struct kshark_entry_collection *col, +struct kshark_entry_request **req, +bool front,size_t *end) +{ +struct kshark_entry_request *req_tmp = *req; +int col_index_flag; +ssize_t col_index; +size_t req_end; + +if (req_tmp->next || col->size ==0 ) { +fprintf (stderr,"Unexpected input in " ); +fprintf (stderr,"map_collection_request_init()\n" ); + goto do_nothing; + } + + req_end = front ? req_tmp->first + req_tmp->n -1 : + req_tmp->first - req_tmp->n +1 ; + +/* +* Find the first Resume Point of the collection which is equal or +* greater than the first index of this request. +*/ + col_index =map_collection_index_from_source (col, + req_tmp->first, + &col_index_flag); + +/* +* The value of "col_index" is ambiguous. Use the "col_index_flag" to +* deal with all possible cases. +*/ +if (col_index ==KS_EMPTY_BIN ) { +/* Empty collection. */ + goto do_nothing; + } + +if (col_index_flag ==COLLECTION_AFTER ) { +/* +* This request starts after the end of interval "col_index". +*/ +if (front && (col_index == col->size -1 || + req_end < col->resume_points[col_index +1 ])) { +/* +* No overlap between the collection and this front +* request. Do nothing. +*/ + goto do_nothing; + }else if (!front && req_end > col->break_points[col_index]) { +/* +* No overlap between the collection and this back
kernel-shark-qt/src/libkshark-collection.c line 353
Quoted 10 lines
kernel-shark-qt/src/libkshark-collection.c new file +10
-0+* request. Do nothing. +*/ + goto do_nothing; + } + +if (front) + ++col_index; + + req_tmp->first = front ? col->resume_points[col_index] : + col->break_points[col_index];
Couple of things. First you could remove the if (front) and do:
req_tmp->first = front ? col->resume_points[++col_index] : col->break_points[col_index];
Quoted 17 lines
kernel-shark-qt/src/libkshark-collection.c new file +17
-0+ } + +if (col_index_flag ==COLLECTION_BEFORE ) { +/* +* This request starts before the beginning of interval +* "col_index". +*/ +if (!front && (col_index ==0 || + req_end > col->break_points[col_index -1 ])) { +/* +* No overlap between the collection and this back +* request. Do nothing. +*/ + goto do_nothing; + }else if (front && req_end < col->resume_points[col_index]) { +/* +* No overlap between the collection and this front
kernel-shark-qt/src/libkshark-collection.c line 380
Quoted 10 lines
kernel-shark-qt/src/libkshark-collection.c new file +10
-0+* request. Do nothing. +*/ + goto do_nothing; + } + +if (!front) + --col_index; + + req_tmp->first = front ? col->resume_points[col_index] : + col->break_points[col_index];
And here have:
req_tmp->first = front ? col->resume_points[col_index] : col->break_points[++col_index];
-- Steve
Quoted 584 lines
kernel-shark-qt/src/libkshark-collection.c new file +438
-0+ } + + *end = req_end; + +return col_index; + +do_nothing: +kshark_free_entry_request (*req); + *req =NULL ; + *end =KS_EMPTY_BIN ; + +return KS_EMPTY_BIN ; +} + +/* +* This function uses the intervals of the Data collection to transform the +* inputted single data request into a list of data requests. The new list of +* request will ignore the data outside of the intervals of the collection. +*/ +static int +map_collection_back_request (const struct kshark_entry_collection *col, +struct kshark_entry_request **req) +{ +struct kshark_entry_request *req_tmp; +size_t req_first, req_end; +ssize_t col_index; +int req_count; + + col_index =map_collection_request_init (col, req, false, &req_end); +if (col_index ==KS_EMPTY_BIN ) +return 0 ; + +/* +* Now loop over the intervals of the collection going backwords till +* the end of the inputted request and create a separate request for +* each of those interest. +*/ + req_tmp = *req; + req_count =1 ; +while (col_index >=0 && req_end <= col->break_points[col_index]) { +if (req_end >= col->resume_points[col_index]) { +/* +* The last entry of the original request is inside +* the "col_index" collection interval. Close the +* collection request here and return. +*/ + req_tmp->n = req_tmp->first - req_end +1 ; +break ; + } + +/* +* The last entry of the original request is outside of the +* "col_index" interval. Close the collection request at the +* end of this interval and move to the next one. Try to make +* another request there. +*/ + req_tmp->n = req_tmp->first - + col->resume_points[col_index] +1 ; + + --col_index; + +if (req_end > col->break_points[col_index]) { +/* +* The last entry of the original request comes before +* the end of the next collection interval. Stop here. +*/ +break ; + } + +if (col_index >0 ) { +/* Make a new request. */ + req_first = col->break_points[col_index]; + + req_tmp->next = +kshark_entry_request_alloc (req_first, +0 , + req_tmp->cond, + req_tmp->val, + req_tmp->vis_only, + req_tmp->vis_mask); + +if (!req_tmp->next) + goto fail; + + req_tmp = req_tmp->next; + ++req_count; + } + } + +return req_count; + +fail: +fprintf (stderr,"Failed to allocate memory for " ); +fprintf (stderr,"Collection data request.\n" ); +kshark_free_entry_request (*req); + *req =NULL ; +return -ENOMEM ; +} + +/* +* This function uses the intervals of the Data collection to transform the +* inputted single data request into a list of data requests. The new list of +* requests will ignore the data outside of the intervals of the collection. +*/ +static int +map_collection_front_request (const struct kshark_entry_collection *col, +struct kshark_entry_request **req) +{ +struct kshark_entry_request *req_tmp; +size_t req_first, req_end; +ssize_t col_index; +int req_count; + + col_index =map_collection_request_init (col, req, true, &req_end); +if (col_index ==KS_EMPTY_BIN ) +return 0 ; + +/* +* Now loop over the intervals of the collection going forwards till +* the end of the inputted request and create a separate request for +* each of those interest. +*/ + req_count =1 ; + req_tmp = *req; +while (col_index < col->size && + req_end >= col->resume_points[col_index]) { +if (req_end <= col->break_points[col_index]) { +/* +* The last entry of the original request is inside +* the "col_index" collection interval. +* Close the collection request here and return. +*/ + req_tmp->n = req_end - req_tmp->first +1 ; +break ; + } + +/* +* The last entry of the original request is outside this +* collection interval (col_index). Close the collection +* request at the end of the interval and move to the next +* interval. Try to make another request there. +*/ + req_tmp->n = col->break_points[col_index] - + req_tmp->first +1 ; + + ++col_index; + +if (req_end < col->resume_points[col_index]) { +/* +* The last entry of the original request comes before +* the beginning of next collection interval. +* Stop here. +*/ +break ; + } + +if (col_index < col->size) { +/* Make a new request. */ + req_first = col->resume_points[col_index]; + + req_tmp->next = +kshark_entry_request_alloc (req_first, +0 , + req_tmp->cond, + req_tmp->val, + req_tmp->vis_only, + req_tmp->vis_mask); + +if (!req_tmp->next) + goto fail; + + req_tmp = req_tmp->next; + ++req_count; + } + } + +return req_count; + +fail: +fprintf (stderr,"Failed to allocate memory for " ); +fprintf (stderr,"Collection data request.\n" ); +kshark_free_entry_request (*req); + *req =NULL ; +return -ENOMEM ; +} + +/** +* @brief Search for an entry satisfying the requirements of a given Data +* request. Start from the position provided by the request and go +* searching in the direction of the increasing timestamps (front). +* The search is performed only inside the intervals, defined by +* the data collection. +* +* @param req: Input location for a single Data request. The imputted request +* will be transformed into a list of requests. This new list of +* requests will ignore the data outside of the intervals of the +* collection. +* @param data: Input location for the trace data. +* @param col: Input location for the Data collection. +* @param index: Optional output location for the index of the returned +* entry inside the array. +* +* @returns Pointer to the first entry satisfying the matching condition on +* success, or NULL on failure. +* In the special case when some entries, satisfying the Matching +* condition function have been found, but all these entries have +* been discarded because of the visibility criteria (filtered +* entries), the function returns a pointer to a special +* "Dummy entry". +*/ +const struct kshark_entry * +kshark_get_collection_entry_front (struct kshark_entry_request **req, +struct kshark_entry **data, +const struct kshark_entry_collection *col, +ssize_t *index) +{ +const struct kshark_entry *entry =NULL ; +int req_count; + +/* +* Use the intervals of the Data collection to redefine the data +* request in a way which will ignore the data outside of the +* intervals of the collection. +*/ + req_count =map_collection_front_request (col, req); + +if (index && !req_count) + *index =KS_EMPTY_BIN ; + +/* +* Loop over the list of redefined requests and search until you find +* the first matching entry. +*/ +while (*req) { + entry =kshark_get_entry_front (*req, data, index); +if (entry) +break ; + + *req = (*req)->next; + } + +return entry; +} + +/** +* @brief Search for an entry satisfying the requirements of a given Data +* request. Start from the position provided by the request and go +* searching in the direction of the decreasing timestamps (back). +* The search is performed only inside the intervals, defined by +* the data collection. +* +* @param req: Input location for Data request. The imputed request +* will be transformed into a list of requests. This new list of +* requests will ignore the data outside of the intervals of the +* collection. +* @param data: Input location for the trace data. +* @param col: Input location for the Data collection. +* @param index: Optional output location for the index of the returned +* entry inside the array. +* +* @returns Pointer to the first entry satisfying the matching condition on +* success, or NULL on failure. +* In the special case when some entries, satisfying the Matching +* condition function have been found, but all these entries have +* been discarded because of the visibility criteria (filtered +* entries), the function returns a pointer to a special +* "Dummy entry". +*/ +const struct kshark_entry * +kshark_get_collection_entry_back (struct kshark_entry_request **req, +struct kshark_entry **data, +const struct kshark_entry_collection *col, +ssize_t *index) +{ +const struct kshark_entry *entry =NULL ; +int req_count; + +/* +* Use the intervals of the Data collection to redefine the data +* request in a way which will ignore the data outside of the +* intervals of the collection. +*/ + req_count =map_collection_back_request (col, req); +if (index && !req_count) + *index =KS_EMPTY_BIN ; + +/* +* Loop over the list of redefined requests and search until you find +* the first matching entry. +*/ +while (*req) { + entry =kshark_get_entry_back (*req, data, index); +if (entry) +break ; + + *req = (*req)->next; + } + +return entry; +} + +/** +* @brief Search the list of Data collections and find the collection defined +* with a given Matching condition function and value. +* +* @param col: Input location for the Data collection list. +* @param cond: Matching condition function. +* @param val: Matching condition value, used by the Matching condition +* function. +* +* @returns Pointer to a Data collections on success, or NULL on failure. +*/ +struct kshark_entry_collection * +kshark_find_data_collection (struct kshark_entry_collection *col, +matching_condition_func cond, +int val) +{ +while (col) { +if (col->cond == cond && col->val == val) +return col; + + col = col->next; + } + +return NULL ; +} + +/** +* @brief Clear all data intervals of the given Data collection. +* +* @param col: Input location for the Data collection. +*/ +void kshark_reset_data_collection (struct kshark_entry_collection *col) +{ +free (col->resume_points); + col->resume_points =NULL ; + +free (col->break_points); + col->break_points =NULL ; + + col->size =0 ; +} + +static void kshark_free_data_collection (struct kshark_entry_collection *col) +{ +free (col->resume_points); +free (col->break_points); +free (col); +} + +/** +* @brief Allocate and process data collection, defined with a given Matching +* condition function and value. Add this collection to the list of +* collections used by the session. +* +* @param kshark_ctx: Input location for the session context pointer. +* @param data: Input location for the trace data. +* @param n_rows: The size of the inputted data. +* @param cond: Matching condition function for the collection to be +* registered. +* @param val: Matching condition value of for collection to be registered. +* @param margin: The size of the additional (margin) data which do not +* satisfy the matching condition, but is added at the +* beginning and at the end of each interval of the collection +* as well as at the beginning and at the end of data-set. If +* "0", no margin data is added. +* +* @returns Pointer to the registered Data collections on success, or NULL +* on failure. +*/ +struct kshark_entry_collection * +kshark_register_data_collection (struct kshark_context *kshark_ctx, +struct kshark_entry **data, +size_t n_rows, +matching_condition_func cond, +int val, +size_t margin) +{ +struct kshark_entry_collection *col; + + col =kshark_data_collection_alloc (kshark_ctx, data, +0 , n_rows, + cond, val, + margin); + +if (col) { + col->next = kshark_ctx->collections; + kshark_ctx->collections = col; + } + +return col; +} + +/** +* @brief Search the list of Data collections for a collection defined +* with a given Matching condition function and value. If such a +* collection exists, unregister (remove and free) this collection +* from the list. +* +* @param col: Input location for the Data collection list. +* @param cond: Matching condition function of the collection to be +* unregistered. +* +* @param val: Matching condition value of the collection to be unregistered. +*/ +void kshark_unregister_data_collection (struct kshark_entry_collection **col, +matching_condition_func cond, +int val) +{ +struct kshark_entry_collection **last = col; +struct kshark_entry_collection *list; + +for (list = *col; list; list = list->next) { +if (list->cond == cond && list->val == val) { + *last = list->next; +kshark_free_data_collection (list); +return ; + } + + last = &list->next; + } +} + +/** +* @brief Free all Data collections in a given list. +* +* @param col: Input location for the Data collection list. +*/ +void kshark_free_collection_list (struct kshark_entry_collection *col) +{ +struct kshark_entry_collection *last; + +while (col) { + last = col; + col = col->next; +kshark_free_data_collection (last); + } +}kernel-shark-qt/src/libkshark.c +16
-0@@ -1067,6 +1067,7 @@ kshark_entry_request_alloc(size_t first, size_t n,return NULL ; } + req->next =NULL ; req->first = first; req->n = n; req->cond = cond;@@ -1077,6 +1078,21 @@ kshark_entry_request_alloc(size_t first, size_t n,return req; } +/** +* @brief Free all Data requests in a given list. +* @param req: Intput location for the Data request list. +*/ +void kshark_free_entry_request (struct kshark_entry_request *req) +{ +struct kshark_entry_request *last; + +while (req) { + last = req; + req = req->next; +free (last); + } +} +/** Dummy entry, used to indicate the existence of filtered entries. */ const struct kshark_entry dummy_entry = { .next =NULL ,kernel-shark-qt/src/libkshark.h +80
-0@@ -115,6 +115,9 @@ struct kshark_context {* the event. */ struct event_filter *advanced_event_filter; + +/** List of Data collections. */ +struct kshark_entry_collection *collections; };bool kshark_instance (struct kshark_context **kshark_ctx);@@ -245,6 +248,9 @@ typedef bool (matching_condition_func)(struct kshark_context*,* kshark_entry. */ struct kshark_entry_request { +/** Pointer to the next Data request. */ +struct kshark_entry_request *next; +/** * Array index specifying the position inside the array from where * the search starts. @@ -277,6 +283,8 @@ kshark_entry_request_alloc(size_t first, size_t n, matching_condition_func cond, int val, bool vis_only, int vis_mask); +void kshark_free_entry_request (struct kshark_entry_request *req); +const struct kshark_entry * kshark_get_entry_front(const struct kshark_entry_request *req, struct kshark_entry **data,@@ -287,6 +295,78 @@ kshark_get_entry_back(const struct kshark_entry_request *req,struct kshark_entry **data, ssize_t *index); +/** +* Data collections are used to optimize the search for an entry having an +* abstract property, defined by a Matching condition function and a value. +* When a collection is processed, the data which is relevant for the +* collection is enclosed in "Data intervals", defined by pairs of "Resume" and +* "Break" points. It is guaranteed that the data outside of the intervals +* contains no entries satisfying the abstract matching condition. However, the +* intervals may (will) contain data that do not satisfy the matching condition. +* Once defined, the Data collection can be used when searching for an entry +* having the same (ore related) abstract property. The collection allows to +* ignore the irrelevant data, thus it eliminates the linear worst-case time +* complexity of the search. +*/ +struct kshark_entry_collection { +/** Pointer to the next Data collection. */ +struct kshark_entry_collection *next; + +/** Matching condition function, used to define the collections. */ +matching_condition_func *cond; + +/** +* Matching condition value, used by the Matching condition finction +* to define the collections. +*/ +int val; + +/** +* Array of indexes defining the beginning of each individual data +* interval. +*/ +size_t *resume_points; + +/** +* Array of indexes defining the end of each individual data interval. +*/ +size_t *break_points; + +/** Number of data intervals in this collection. */ +size_t size; +}; + +struct kshark_entry_collection * +kshark_register_data_collection (struct kshark_context *kshark_ctx, +struct kshark_entry **data,size_t n_rows, +matching_condition_func cond,int val, +size_t margin); + +void kshark_unregister_data_collection (struct kshark_entry_collection **col, +matching_condition_func cond, +int val); + +struct kshark_entry_collection * +kshark_find_data_collection (struct kshark_entry_collection *col, +matching_condition_func cond, +int val); + +void kshark_reset_data_collection (struct kshark_entry_collection *col); + +void kshark_free_collection_list (struct kshark_entry_collection *col); + +const struct kshark_entry * +kshark_get_collection_entry_front (struct kshark_entry_request **req, +struct kshark_entry **data, +const struct kshark_entry_collection *col, +ssize_t *index); + +const struct kshark_entry * +kshark_get_collection_entry_back (struct kshark_entry_request **req, +struct kshark_entry **data, +const struct kshark_entry_collection *col, +ssize_t *index); + #ifdef __cplusplus }#endif
PATCH v4 5/6 kernel-shark-qt: Make the Vis. model use Data collections.
In reply to Yordan Karadzhov (VMware)This patch optimizes the search instruments of the model by adding the possibility of using Data collections.
--- kernel-shark-qt/examples/datahisto.c | 4 ++ kernel-shark-qt/src/libkshark-model.c | 57 +++++++++++++++++++++++---- kernel-shark-qt/src/libkshark-model.h | 14 ++++++- 3 files changed, 65 insertions(+), 10 deletions(-)
kernel-shark-qt/examples/datahisto.c +4 -0
@@ -27,18 +27,22 @@ void dump_bin(struct kshark_trace_histo *histo, int bin,if (strcmp (type,"cpu" ) ==0 ) { e_front =ksmodel_get_entry_front (histo, bin, true, kshark_match_cpu, val, +NULL , &i_front); e_back =ksmodel_get_entry_back (histo, bin, true, kshark_match_cpu, val, +NULL , &i_back); }else if (strcmp (type,"task" ) ==0 ) { e_front =ksmodel_get_entry_front (histo, bin, true, kshark_match_pid, val, +NULL , &i_front); e_back =ksmodel_get_entry_back (histo, bin, true, kshark_match_pid, val, +NULL , &i_back); }else { i_front =ksmodel_first_index_at_bin (histo, bin);
kernel-shark-qt/src/libkshark-model.c +49 -8
201 lines not on this page · raw message
kernel-shark-qt/src/libkshark-model.h +12 -2
@@ -108,35 +108,45 @@ const struct kshark_entry * ksmodel_get_entry_front(struct kshark_trace_histo *histo, int bin, bool vis_only, matching_condition_func func, int val, + 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, +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, +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, +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, +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, +struct kshark_entry_collection *col,ssize_t *index);bool ksmodel_cpu_visible_event_exist (struct kshark_trace_histo *histo, -int bin,int cpu,ssize_t *index); +int bin,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,ssize_t *index); +int bin,int pid, +struct kshark_entry_collection *col, +ssize_t *index);static inline double ksmodel_bin_time (struct kshark_trace_histo *histo,int bin)
Signature · 1 line
2.17.1
PATCH v4 6/6 kernel-shark-qt: Changed the KernelShark version identifier.
In reply to Yordan Karadzhov (VMware)(Patch Id) ++
--- kernel-shark-qt/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark-qt/CMakeLists.txt +1 -1
@@ -6,7 +6,7 @@ project(kernel-shark-qt) set(KS_VERSION_MAJOR 0) set(KS_VERSION_MINOR 7) -set(KS_VERSION_PATCH 0) +set(KS_VERSION_PATCH 1) set(KS_VERSION_STRING ${KS_VERSION_MAJOR}.${KS_VERSION_MINOR}.${KS_VERSION_PATCH}) message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n")
Signature · 1 line
2.17.1