Add visualization model for the Qt-based KernelShark
v2 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 the second version of this series of patches. Major changes from v1 are:
[1/7] New patch. Changes the type of the fields of struct kshark_entry.
[2/7], [3/7] and [5/7 ] This version of the patchs contains a number of improvements suggested by Steven Rostedt in his review. Thanks Steven!
Yordan Karadzhov (VMware) (7):
kernel-shark-qt: Change the type of the fields in struct kshark_entry
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 | 828 ++++++++++++++ kernel-shark-qt/src/libkshark-model.c | 1174 ++++++++++++++++++++ kernel-shark-qt/src/libkshark-model.h | 152 +++ kernel-shark-qt/src/libkshark.c | 250 ++++- kernel-shark-qt/src/libkshark.h | 173 ++- 9 files changed, 2738 insertions(+), 8 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 v2 1/7 kernel-shark-qt: Change the type of the fields in struct kshark_entry
This patch aims to increase the max value limits of the "pid" and "cpu" fields of struct kshark_entry. The type of the "visible" is changed as well, but this is done just to provide optimal packing.
--- kernel-shark-qt/src/libkshark.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel-shark-qt/src/libkshark.h +4 -4
@@ -42,16 +42,16 @@ struct kshark_entry {* kshark_filter_masks to check the level of visibility/invisibility * of the entry. */ -uint8_t visible; +uint16_t visible;/** The CPU core of the record. */ -uint8_t cpu; +int16_t cpu;/** The PID of the task the record was generated. */ -int16_t pid; +int32_t pid;/** Unique Id ot the trace event type. */ -int event_id; +int32_t event_id;/** The offset into the trace file, used to find the record. */ uint64_t offset;
Signature · 1 line
2.17.1
PATCH v2 2/7 kernel-shark-qt: Add generic instruments for searching inside the trace data
In reply to Yordan Karadzhov (VMware)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 | 233 +++++++++++++++++++++++++++++++- kernel-shark-qt/src/libkshark.h | 86 +++++++++++- 2 files changed, 317 insertions(+), 2 deletions(-)
kernel-shark-qt/src/libkshark.c +232 -1
@@ -861,7 +861,7 @@ static const char *kshark_get_info(struct pevent *pe,* @returns The returned string contains a semicolon-separated list of data * fields. */ -char *kshark_dump_entry (struct kshark_entry *entry) +char *kshark_dump_entry (const struct kshark_entry *entry) {const char *event_name, *task, *lat, *info;struct kshark_context *kshark_ctx;
@@ -908,3 +908,234 @@ char* kshark_dump_entry(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". In the case when no +kshark_entry has been found inside the range, the function will +return the value of "l" or "h". +*/ +size_t kshark_find_entry_by_time (uint64_t time, +struct kshark_entry **data, +size_t l,size_t h) +{ +if (data[l]->ts >= time) +return l; + +if (data[h]->ts < time) +return h; + +size_t mid; +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". In the case when no +pevent_record has been found inside the range, the function will +return the value of "l" or "h". +*/ +size_t kshark_find_record_by_time (uint64_t time, +struct pevent_record **data, +size_t l,size_t h) +{ +if (data[l]->ts >= time) +return l; + +if (data[h]->ts < time) +return h; + +size_t mid; +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 +85 -1
98 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 2/7] kernel-shark-qt: Add generic instruments for searching inside the trace data
Quoted 34 lines · On Tue, 31 Jul 2018 16:52:43 +0300 "Yordan Karadzhov (VMware)"…
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_entriesortrace_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.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 233 +++++++++++++++++++++++++++++++- kernel-shark-qt/src/libkshark.h | 86 +++++++++++- 2 files changed, 317 insertions(+), 2 deletions(-)kernel-shark-qt/src/libkshark.c +0
-0
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct pevent *pe, · line 864
Quoted 5 lines
kernel-shark-qt/src/libkshark.c +1
-1@@ -861,7 +861,7 @@ static const char *kshark_get_info(struct pevent *pe,* @returns The returned string contains a semicolon-separated list of data * fields. */ -char *kshark_dump_entry (struct kshark_entry *entry) +char *kshark_dump_entry (const struct kshark_entry *entry)
Hmm, is this a separate change? It looks like it should be a separate patch.
kernel-shark-qt/src/libkshark.c char* kshark_dump_entry(struct kshark_entry *entry) · line 913
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +3
-0{const char *event_name, *task, *lat, *info;struct kshark_context *kshark_ctx;@@ -908,3 +908,234 @@ char* kshark_dump_entry(struct kshark_entry *entry)return NULL ; } + +/** +* @brief Binary search inside a time-sorted array of kshark_entries.
Yeah having a space here would be nice.
kernel-shark-qt/src/libkshark.c char* kshark_dump_entry(struct kshark_entry *entry) · line 917
Quoted 4 lines
kernel-shark-qt/src/libkshark.c +4
-0+* @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.
And here (and for others)
kernel-shark-qt/src/libkshark.c char* kshark_dump_entry(struct kshark_entry *entry) · line 921
Quoted 4 lines
kernel-shark-qt/src/libkshark.c +4
-0+ * @returns On success, the first kshark_entry inside the range, having a + timestamp equal or bigger than "time". In the case when no + kshark_entry has been found inside the range, the function will + return the value of "l" or "h".
Looks like 'l' or 'h' have a different meaning when it is returned. Please comment it here as for what it means if it returns 'l' or 'h'.
Also, it looks like there's no difference if it found an entry at time 'l' or 'h' or if it found no entry at all.
Quoted 16 lines
kernel-shark-qt/src/libkshark.c +16
-0+*/ +size_t kshark_find_entry_by_time (uint64_t time, +struct kshark_entry **data, +size_t l,size_t h) +{ +if (data[l]->ts >= time) +return l; + +if (data[h]->ts < time) +return h; + +size_t mid; +BSEARCH (h, l, data[mid]->ts < time); +return h; +} +
kernel-shark-qt/src/libkshark.c char* kshark_dump_entry(struct kshark_entry *entry) · line 947
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+/** +* @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". In the case when no +pevent_record has been found inside the range, the function will +return the value of "l" or "h".
Same here.
Quoted 155 lines
kernel-shark-qt/src/libkshark.c +155
-0+*/ +size_t kshark_find_record_by_time (uint64_t time, +struct pevent_record **data, +size_t l,size_t h) +{ +if (data[l]->ts >= time) +return l; + +if (data[h]->ts < time) +return h; + +size_t mid; +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
kernel-shark-qt/src/libkshark.c char* kshark_dump_entry(struct kshark_entry *entry) · line 1112
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* "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 );
You don't need the "+" in the +1 ;-)
Quoted 34 lines
kernel-shark-qt/src/libkshark.c +29
-0+} + +/** +* @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 +0
-0
kernel-shark-qt/src/libkshark.h void kshark_close(struct kshark_context *kshark_ctx); · line 136
Quoted 5 lines
kernel-shark-qt/src/libkshark.h +1
-1@@ -133,7 +133,7 @@ void kshark_close(struct kshark_context *kshark_ctx);void kshark_free (struct kshark_context *kshark_ctx); -char *kshark_dump_entry (struct kshark_entry *entry); +char *kshark_dump_entry (const struct kshark_entry *entry);
Again, shouldn't this be in its own patch?
-- Steve
Quoted 94 lines
kernel-shark-qt/src/libkshark.h +84
-0/** Bit masks used to control the visibility of the entry after filtering. */ enum kshark_filter_masks {@@ -190,6 +190,90 @@ void kshark_filter_entries(struct kshark_context *kshark_ctx,struct kshark_entry **data, size_t n_entries); +/** General purpose Binary search macro. */ +#define BSEARCH (h, l, cond) \ + ({ \ + while (h - l > 1) { \ + mid = (l + h) / 2; \ + if (cond) \ + l = mid; \ + else \ + h = mid; \ + } \ + }) + +size_t kshark_find_entry_by_time (uint64_t time, +struct kshark_entry **data_rows, +size_t l,size_t h); + +size_t kshark_find_record_by_time (uint64_t time, +struct pevent_record **data_rows, +size_t l,size_t h); + +bool kshark_match_pid (struct kshark_context *kshark_ctx, +struct kshark_entry *e,int pid); + +bool kshark_match_cpu (struct kshark_context *kshark_ctx, +struct kshark_entry *e,int cpu); + +/** Empty bin identifier. */ +#define KS_EMPTY_BIN -1 + +/** Filtered bin identifier. */ +#define KS_FILTERED_BIN -2 + +/** Matching condition function type. To be user for data requests */ +typedef bool (matching_condition_func )(struct kshark_context *, +struct kshark_entry *, +int ); + +/** +* Data request structure, defining the properties of the required +* kshark_entry. +*/ +struct kshark_entry_request { +/** +* Array index specifying the position inside the array from where +* the search starts. +*/ +size_t first; + +/** Number of array elements to search in. */ +size_t n; + +/** Matching condition function. */ +matching_condition_func *cond; + +/** +* Matching condition value, used by the Matching condition function. +*/ +int val; + +/** If true, a visible entry is requested. */ +bool vis_only; + +/** +* If "vis_only" is true, use this mask to specify the level of +* visibility of the requested entry. +*/ +uint8_t vis_mask; +}; + +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); + +const struct kshark_entry * +kshark_get_entry_front (const struct kshark_entry_request *req, +struct kshark_entry **data, +ssize_t *index); + +const struct kshark_entry * +kshark_get_entry_back (const struct kshark_entry_request *req, +struct kshark_entry **data, +ssize_t *index); + #ifdef __cplusplus }#endif
PATCH v2 3/7 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 | 1135 +++++++++++++++++++++++++ kernel-shark-qt/src/libkshark-model.h | 142 ++++ 3 files changed, 1279 insertions(+), 1 deletion(-) 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 +1135 -0
1,135 lines not on this page · raw message
kernel-shark-qt/src/libkshark-model.h new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 27 lines · On Tue, 31 Jul 2018 16:52:44 +0300 "Yordan Karadzhov (VMware)"…
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 +7
-0@@ -0,0 +1,1135 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* +* Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> +*/ + +/**
kernel-shark-qt/src/libkshark-model.c line 17
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* @file libkshark.c +* @brief Visualization model for FTRACE (trace-cmd) data. +*/ + +// C +#include <stdlib.h> + +// KernelShark +#include "libkshark-model.h" +
Needs comment here explaining what these are.
kernel-shark-qt/src/libkshark-model.c line 19
Quoted 2 lines
kernel-shark-qt/src/libkshark-model.c new file +2
-0+#define UOB (histo) (histo->n_bins) +#define LOB (histo) (histo->n_bins + 1)
Perhaps add:
/* For all bins */
# define ALLB(histo) LOB(histo)
Quoted 28 lines
kernel-shark-qt/src/libkshark-model.c new file +28
-0+ +/** +* @brief Initialize the Visualization model. +* @param histo: Input location for the model descriptor. +*/ +void ksmodel_init (struct kshark_trace_histo *histo) +{ +/* +* Initialize an empty histo. The histo will have no bins and will +* contain no data. +*/ + histo->bin_size =0 ; + histo->min =0 ; + histo->max =0 ; + histo->n_bins =0 ; + + histo->bin_count =NULL ; + histo->map =NULL ; +} + +/** +* @brief Clear (reset) the Visualization model. +* @param histo: Input location for the model descriptor. +*/ +void ksmodel_clear (struct kshark_trace_histo *histo) +{ +/* Reset the histo. It will have no bins and will contain no data. */ +free (histo->map);
kernel-shark-qt/src/libkshark-model.c line 57
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+free (histo->bin_count); +ksmodel_init (histo); +} + +static void ksmodel_reset_bins (struct kshark_trace_histo *histo, +size_t first,size_t last) +{ +/* Reset the content of the bins. */ +memset (&histo->map[first],KS_EMPTY_BIN , + (last - first +1 ) *sizeof (histo->map[0 ]));
This patch should add a comment here and by KS_EMPTY_BIN stating that KS_EMPTY_BIN is expected to be -1, as it is used to reset the entire array with memset(). As memset() only updates an array to a single byte, that byte must be the same throughout. Which works for zero and -1.
Quoted 39 lines
kernel-shark-qt/src/libkshark-model.c new file +39
-0+ +memset (&histo->bin_count[first],0 , + (last - first +1 ) *sizeof (histo->bin_count[0 ])); +} + +static bool ksmodel_histo_alloc (struct kshark_trace_histo *histo,size_t n) +{ +free (histo->bin_count); +free (histo->map); + +/* Create bins. Two overflow bins are added. */ + histo->map =calloc (n +2 ,sizeof (*histo->map)); + histo->bin_count =calloc (n +2 ,sizeof (*histo->bin_count)); + +if (!histo->map || !histo->bin_count) { +ksmodel_clear (histo); +fprintf (stderr,"Failed to allocate memory for a histo.\n" ); +return false; + } + + histo->n_bins = n; + +return true; +} + +static void ksmodel_set_in_range_bining (struct kshark_trace_histo *histo, +size_t n,uint64_t min,uint64_t max, +bool force_in_range) +{ +uint64_t corrected_range, delta_range, range = max - min; +struct kshark_entry *last; + +/* The size of the bin must be >= 1, hence the range must be >= n. */ +if (n ==0 || range < n) +return ; + +/* +* If the number of bins changes, allocate memory for the descriptor +* of the model.
kernel-shark-qt/src/libkshark-model.c line 106
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+*/ +if (n != histo->n_bins) { +if (!ksmodel_histo_alloc (histo, n)) { +ksmodel_clear (histo); +return ; + } + } + +/* Reset the content of all bins (including overflow bins) to zero. */ +ksmodel_reset_bins (histo,0 , histo->n_bins +1 );
Here we could then have:
ksmodel_reset_bins(histo, 0, ALLB(histo));
Quoted 25 lines
kernel-shark-qt/src/libkshark-model.c new file +25
-0+ +if (range % n ==0 ) { +/* +* The range is multiple of the number of bin and needs no +* adjustment. This is very unlikely to happen but still ... +*/ + histo->min = min; + histo->max = max; + histo->bin_size = range / n; + }else { +/* +* The range needs adjustment. The new range will be slightly +* bigger, compared to the requested one. +*/ + histo->bin_size = range / n +1 ; + corrected_range = histo->bin_size * n; + delta_range = corrected_range - range; + histo->min = min - delta_range /2 ; + histo->max = histo->min + corrected_range; + +if (!force_in_range) +return ; + +/* +* Make sure that the new range doesn't go outside of the time
kernel-shark-qt/src/libkshark-model.c line 141
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* interval of the dataset. +*/ + last = histo->data[histo->data_size -1 ]; +if (histo->min < histo->data[0 ]->ts) { + histo->min = histo->data[0 ]->ts; + histo->max = histo->min + corrected_range; + }else if (histo->max > last->ts) { + histo->max = last->ts; + histo->min = histo->max - corrected_range; + }
Hmm, Let's say the range of the data is 0..1,000,001 and we picked a range of 999,999 starting at 0. And there's 1024 buckets. This would have:
min = 0; max = 999999; n = 1024; range = 999999;
bin_size = 999999 / 1024 + 1 = 977;correct_range = 977 * 1024 = 1000448;delta_rang = 1000448 - 999999 = 449;histo->min = 0 - 449 / 2 = -224;histo->max = -224 + 1000448 = 1000224;
Now histo->min (-224) < histo->data[0]->ts (0) so
histo->min = 0;histo->max = 0 + 1000448 = 1000448;
Thus we get max greater than the data set.
Actually, we would always get a range greater than the data set, if the data set itself is not divisible by the bin size. This that a problem?
-- Steve
Quoted 17 lines
kernel-shark-qt/src/libkshark-model.c new file +16
-0+ } +} + +/** +* @brief Prepare the bining of the Visualization model. +* @param histo: Input location for the model descriptor. +* @param n: Number of bins. +* @param min: Lower edge of the time-window to be visualized. +* @param max: Upper edge of the time-window to be visualized. +*/ +void ksmodel_set_bining (struct kshark_trace_histo *histo, +size_t n,uint64_t min,uint64_t max) +{ +ksmodel_set_in_range_bining (histo, n, min, max, false); +} +
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 77 lines · Steven Rostedt
Quoted 14 lines
kernel-shark-qt/src/libkshark-model.c new file +14
-0+static void ksmodel_set_in_range_bining (struct kshark_trace_histo *histo, +size_t n,uint64_t min,uint64_t max, +bool force_in_range) +{ +uint64_t corrected_range, delta_range, range = max - min; +struct kshark_entry *last; + +/* The size of the bin must be >= 1, hence the range must be >= n. */ +if (n ==0 || range < n) +return ; + +/* +* If the number of bins changes, allocate memory for the descriptor +* of the model. kernel-shark-qt/src/libkshark-model.c line 106
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+*/ +if (n != histo->n_bins) { +if (!ksmodel_histo_alloc (histo, n)) { +ksmodel_clear (histo); +return ; + } + } + +/* Reset the content of all bins (including overflow bins) to zero. */ +ksmodel_reset_bins (histo,0 , histo->n_bins +1 );Here we could then have:
ksmodel_reset_bins(histo, 0, ALLB(histo));Quoted 25 lines
kernel-shark-qt/src/libkshark-model.c new file +25
-0+ +if (range % n ==0 ) { +/* +* The range is multiple of the number of bin and needs no +* adjustment. This is very unlikely to happen but still ... +*/ + histo->min = min; + histo->max = max; + histo->bin_size = range / n; + }else { +/* +* The range needs adjustment. The new range will be slightly +* bigger, compared to the requested one. +*/ + histo->bin_size = range / n +1 ; + corrected_range = histo->bin_size * n; + delta_range = corrected_range - range; + histo->min = min - delta_range /2 ; + histo->max = histo->min + corrected_range; + +if (!force_in_range) +return ; + +/* +* Make sure that the new range doesn't go outside of the time kernel-shark-qt/src/libkshark-model.c line 141
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* interval of the dataset. +*/ + last = histo->data[histo->data_size -1 ]; +if (histo->min < histo->data[0 ]->ts) { + histo->min = histo->data[0 ]->ts; + histo->max = histo->min + corrected_range; + }else if (histo->max > last->ts) { + histo->max = last->ts; + histo->min = histo->max - corrected_range; + }Hmm, Let's say the range of the data is 0..1,000,001 and we picked a range of 999,999 starting at 0. And there's 1024 buckets. This would have:
min = 0; max = 999999; n = 1024; range = 999999;
bin_size= 999999 / 1024 + 1 = 977;correct_range= 977 * 1024 = 1000448;delta_rang= 1000448 - 999999 = 449;histo->min= 0 - 449 / 2 = -224;histo->max= -224 + 1000448 = 1000224;Now
histo->min(-224) < histo->data[0]->ts (0) so
Quoted 7 lines
histo->min= 0;histo->max= 0 + 1000448 = 1000448;Thus we get max greater than the data set.
Actually, we would always get a range greater than the data set, if the data set itself is not divisible by the bin size. This that a problem?
Hi Steven,
In your example you consider the case when we want to visualize the entire data-set. Indeed in this case the true range of the histo will be slightly bigger. This is not a problem.
The "force_in_range" part of the logic in this function deals with another case.
Let's stick to your example but say that the current range is from 0 to 10,000.
Now if the user hits the "Zoom Out" for a second, this function will be called several hundred times and each call of the function will add its own small negative correction to the value of histo->min (initially 0). At the end we will have a significant part of the graph outside of the data-set.
Thanks!
Yordan
Quoted 20 lines
-- Steve
Quoted 17 lines
kernel-shark-qt/src/libkshark-model.c new file +16
-0+ } +} + +/** +* @brief Prepare the bining of the Visualization model. +* @param histo: Input location for the model descriptor. +* @param n: Number of bins. +* @param min: Lower edge of the time-window to be visualized. +* @param max: Upper edge of the time-window to be visualized. +*/ +void ksmodel_set_bining (struct kshark_trace_histo *histo, +size_t n,uint64_t min,uint64_t max) +{ +ksmodel_set_in_range_bining (histo, n, min, max, false); +} +
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Steven RostedtQuoted 4 lines · On Tue, 31 Jul 2018 20:51:13 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines
(quoted diff) +4
-0+static void ksmodel_reset_bins(struct kshark_trace_histo *histo, + size_t first, size_t last) +{ + /* Reset the content of the bins. */
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ memset(&histo->map[first], KS_EMPTY_BIN, + (last - first + 1) * sizeof(histo->map[0]));This patch should add a comment here and by
KS_EMPTY_BINstating thatKS_EMPTY_BINis expected to be -1, as it is used to reset the entire array withmemset(). Asmemset()only updates an array to a single byte, that byte must be the same throughout. Which works for zero and -1.
Note, I added this too.
-- Steve
kernel-shark-qt/src/libkshark.h +4 -1
@@ -225,7 +225,10 @@ 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. */
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Yordan Karadzhov (VMware)Quoted 4 lines · On Tue, 31 Jul 2018 16:52:44 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark-qt/src/libkshark-model.c new file +4
-0+static void ksmodel_set_next_bin_edge (struct kshark_trace_histo *histo, +size_t bin) +{ +size_t time, row, next_bin = bin +1 ;
kernel-shark-qt/src/libkshark-model.c line 250
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ +/* Calculate the beginning of the next bin. */ + time = histo->min + next_bin * histo->bin_size; + +/* +* Find the index of the first entry inside +* the next bin (timestamp > time). +*/ + row =kshark_find_entry_by_time (time, histo->data,0 , + histo->data_size -1 );
Hmm, I see this used as this:
for (bin = 0; bin < histo->n_bins; ++bin)
ksmodel_set_next_bin_edge(histo, bin);A lot. Thus we should be able to optimize this with:
static void ksmodel_set_next_bin_edge(struct kshark_trace_histo *histo,
size_t bin, size_t *last_row)
{
row = kshark_find_entry_by_time(time, histo->data, *last_row, histo->data_size - 1); *last_row = row;
And the caller can be:
last_row = 0; for (bin = 0; bin < histo->n_bins; ++bin) ksmodel_set_next_bin_edge(histo, bin, &last_row);
Then we wont be doing the search from 0 each time. It should help speed it up a little.
Quoted 21 lines
kernel-shark-qt/src/libkshark-model.c new file +21
-0+ +/* +* The timestamp of the very last entry of the dataset can be exactly +* equal to the value of the upper edge of the range. This is very +* likely to happen when we use ksmodel_set_in_range_bining(). In this +* case we have to increase the size of the very last bin in order to +* make sure that the last entry of the dataset will fall into it. +*/ +if (next_bin == histo->n_bins -1 ) + ++time; + +if (histo->data[row]->ts >= time + histo->bin_size) { +/* The bin is empty. */ + histo->map[next_bin] =KS_EMPTY_BIN ; +return ; + } + +/* Set the index of the first entry. */ + histo->map[next_bin] = row; +} +
[..]
Quoted 28 lines
kernel-shark-qt/src/libkshark-model.c new file +28
-0+/** +* @brief Provide the Visualization model with data. Calculate the current +* state of the model. +* @param histo: Input location for the model descriptor. +* @param data: Input location for the trace data. +* @param n: Number of bins. +*/ +void ksmodel_fill (struct kshark_trace_histo *histo, +struct kshark_entry **data,size_t n) +{ +int bin; + + histo->data_size = n; + histo->data = data; + +if (histo->n_bins ==0 || + histo->bin_size ==0 || + histo->data_size ==0 ) { +/* +* Something is wrong with this histo. +* Most likely the binning is not set. +*/ +ksmodel_clear (histo); +fprintf (stderr, +"Unable to fill the model with data.\n" ); +fprintf (stderr, +"Try to set the bining of the model first.\n" ); +
kernel-shark-qt/src/libkshark-model.c line 368
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+return ; + } + +/* Set the Lower Overflow bin */ +ksmodel_set_lower_edge (histo); + +/* +* Loop over the dataset and set the beginning of all individual bins. +*/ + bin =0 ;
Superfluous bin assignment above.
Quoted 70 lines
kernel-shark-qt/src/libkshark-model.c new file +70
-0+for (bin =0 ; bin < histo->n_bins; ++bin) +ksmodel_set_next_bin_edge (histo, bin); + +/* Set the Upper Overflow bin. */ +ksmodel_set_upper_edge (histo); + +/* Calculate the number of entries in each bin. */ +ksmodel_set_bin_counts (histo); +} + +/** +* @brief Get the total number of entries in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @returns The number of entries in this bin. +*/ +size_t ksmodel_bin_count (struct kshark_trace_histo *histo,int bin) +{ +if (bin >=0 && bin < histo->n_bins) +return histo->bin_count[bin]; + +if (bin ==UPPER_OVERFLOW_BIN ) +return histo->bin_count[UOB (histo)]; + +if (bin ==LOWER_OVERFLOW_BIN ) +return histo->bin_count[LOB (histo)]; + +return 0 ; +} + +/** +* @brief Shift the time-window of the model forward. Recalculate the current +* state of the model. +* @param histo: Input location for the model descriptor. +* @param n: Number of bins to shift. +*/ +void ksmodel_shift_forward (struct kshark_trace_histo *histo,size_t n) +{ +int bin; + +if (!histo->data_size) +return ; + +if (histo->bin_count[UOB (histo)] ==0 ) { +/* +* The Upper Overflow bin is empty. This means that we are at +* the upper edge of the dataset already. Do nothing in this +* case. +*/ +return ; + } + + histo->min += n * histo->bin_size; + histo->max += n * histo->bin_size; + +if (n >= histo->n_bins) { +/* +* No overlap between the new and the old ranges. Recalculate +* all bins from scratch. First calculate the new range. +*/ +ksmodel_set_bining (histo, histo->n_bins, histo->min, + histo->max); + +ksmodel_fill (histo, histo->data, histo->data_size); +return ; + } + +/* Set the new Lower Overflow bin. */ +ksmodel_set_lower_edge (histo); +
kernel-shark-qt/src/libkshark-model.c line 448
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+/* +* Copy the the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. +*/ +memmove (&histo->map[0 ], &histo->map[n], +sizeof (histo->map[0 ]) * (histo->n_bins - n)); + +/* +* The the mapping index pf the old Upper Overflow bin is now index
"The the" and "pf"?
Quoted 58 lines
kernel-shark-qt/src/libkshark-model.c new file +58
-0+* of the first new bin. +*/ + bin =UOB (histo) - n; + histo->map[bin] = histo->map[UOB (histo)]; + +/* Calculate only the content of the new (non-overlapping) bins. */ +for (; bin < histo->n_bins; ++bin) +ksmodel_set_next_bin_edge (histo, bin); + +/* +* Set the new Upper Overflow bin and calculate the number of entries +* in each bin. +*/ +ksmodel_set_upper_edge (histo); +ksmodel_set_bin_counts (histo); +} + +/** +* @brief Shift the time-window of the model backward. Recalculate the current +* state of the model. +* @param histo: Input location for the model descriptor. +* @param n: Number of bins to shift. +*/ +void ksmodel_shift_backward (struct kshark_trace_histo *histo,size_t n) +{ +int bin; + +if (!histo->data_size) +return ; + +if (histo->bin_count[LOB (histo)] ==0 ) { +/* +* The Lower Overflow bin is empty. This means that we are at +* the Lower edge of the dataset already. Do nothing in this +* case. +*/ +return ; + } + + histo->min -= n * histo->bin_size; + histo->max -= n * histo->bin_size; + +if (n >= histo->n_bins) { +/* +* No overlap between the new and the old range. Recalculate +* all bins from scratch. First calculate the new range. +*/ +ksmodel_set_bining (histo, histo->n_bins, histo->min, + histo->max); + +ksmodel_fill (histo, histo->data, histo->data_size); +return ; + } + +/* +* Copy the the mapping indexes of all overlaping bins starting from +* bin "0" of the old histo. Note that the number of overlaping bins +* is histo->n_bins - n.
kernel-shark-qt/src/libkshark-model.c line 516
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+*/ +memmove (&histo->map[n], &histo->map[0 ], +sizeof (histo->map[0 ]) * (histo->n_bins - n)); + +/* Set the new Lower Overflow bin. */ +ksmodel_set_lower_edge (histo); + +/* Calculate only the content of the new (non-overlapping) bins. */ + bin =0 ; +while (bin < n) {
Convert this to a for loop please.
-- Steve
Quoted 12 lines
kernel-shark-qt/src/libkshark-model.c new file +11
-0+ksmodel_set_next_bin_edge (histo, bin); + ++bin; + } + +/* +* Set the new Upper Overflow bin and calculate the number of entries +* in each bin. +*/ +ksmodel_set_upper_edge (histo); +ksmodel_set_bin_counts (histo); +}
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Yordan Karadzhov (VMware)On Tue, 31 Jul 2018 16:52:44 +0300
"Yordan Karadzhov (VMware)" <[email protected]> wrote:
I'd add a comment above this function (yes static functions may have header comments, just doesn't need to be doxygen like).
/*
* Fill in the bin_count array, which maps the number of data rows that
* exist within each bin.
*/
Or something like that.
kernel-shark-qt/src/libkshark-model.c line 282
Quoted 11 lines
kernel-shark-qt/src/libkshark-model.c new file +11
-0+static void ksmodel_set_bin_counts (struct kshark_trace_histo *histo) +{ +int i =0 , prev_not_empty; + +memset (&histo->bin_count[0 ],0 , + (histo->n_bins) *sizeof (histo->bin_count[0 ])); +/* +* Find the first bin which contains data. Start by checking the +* Lower Overflow bin. +*/ +if (histo->map[histo->n_bins +1 ] !=KS_EMPTY_BIN ) {
Hmm, shouldn't that be:
if (histo->map[LOB(histo)] != KS_EMPTY_BIN) ?
Review
Quoted 2 lines
(quoted diff) +2
-0+ prev_not_empty = LOB(histo); + } else {
Add a comment here:
/* Find the first non-empty bin */
kernel-shark-qt/src/libkshark-model.c line 285
Quoted 1 line
kernel-shark-qt/src/libkshark-model.c new file +1
-0+while (histo->map[i] <0 ) {
Can map[i] be a negative other than KS_EMPTY_BIN?
kernel-shark-qt/src/libkshark-model.c line 296
Quoted 11 lines
kernel-shark-qt/src/libkshark-model.c new file +11
-0+ ++i; + } + + prev_not_empty = i++; + } + +/* +* Starting from the first not empty bin, loop over all bins and fill +* in the bin_count array to hold the number of entries in each bin. +*/ +while (i < histo->n_bins) {
The above should be a for loop:
for (; i < histo->n_bins; i++) {kernel-shark-qt/src/libkshark-model.c line 300
Quoted 4 lines
kernel-shark-qt/src/libkshark-model.c new file +4
-0+if (histo->map[i] !=KS_EMPTY_BIN ) { +/* +* Here we set the number of entries in +* "prev_not_empty" bin.
The above comment needs to be changed:
/*
* The current bin is not empty, take its data
* row and subtract it from the data row of the
* previous not empty bin, which will give us
* the number of data rows in that bin.
Or something like that.
Quoted 58 lines
kernel-shark-qt/src/libkshark-model.c new file +58
-0+*/ + histo->bin_count[prev_not_empty] = + histo->map[i] - histo->map[prev_not_empty]; + + prev_not_empty = i; + } + + ++i; + } + +/* Check if the Upper Overflow bin contains data. */ +if (histo->map[UOB (histo)] ==KS_EMPTY_BIN ) { +/* +* The Upper Overflow bin is empty. Use the size of the +* dataset to calculate the content of the previouse not +* empty bin. +*/ + histo->bin_count[prev_not_empty] = histo->data_size - + histo->map[prev_not_empty]; + }else { +/* +* Use the index of the first entry inside the Upper Overflow +* bin to calculate the content of the previouse not empty +* bin. +*/ + histo->bin_count[prev_not_empty] = histo->map[UOB (histo)] - + histo->map[prev_not_empty]; + } +} + +/** +* @brief Provide the Visualization model with data. Calculate the current +* state of the model. +* @param histo: Input location for the model descriptor. +* @param data: Input location for the trace data. +* @param n: Number of bins. +*/ +void ksmodel_fill (struct kshark_trace_histo *histo, +struct kshark_entry **data,size_t n) +{ +int bin; + + histo->data_size = n; + histo->data = data; + +if (histo->n_bins ==0 || + histo->bin_size ==0 || + histo->data_size ==0 ) { +/* +* Something is wrong with this histo. +* Most likely the binning is not set. +*/ +ksmodel_clear (histo); +fprintf (stderr, +"Unable to fill the model with data.\n" ); +fprintf (stderr, +"Try to set the bining of the model first.\n" ); +
kernel-shark-qt/src/libkshark-model.c line 368
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+return ; + } + +/* Set the Lower Overflow bin */ +ksmodel_set_lower_edge (histo); + +/* +* Loop over the dataset and set the beginning of all individual bins. +*/ + bin =0 ;
As stated before, superfluous bin.
Quoted 34 lines
kernel-shark-qt/src/libkshark-model.c new file +34
-0+for (bin =0 ; bin < histo->n_bins; ++bin) +ksmodel_set_next_bin_edge (histo, bin); + +/* Set the Upper Overflow bin. */ +ksmodel_set_upper_edge (histo); + +/* Calculate the number of entries in each bin. */ +ksmodel_set_bin_counts (histo); +} + +/** +* @brief Get the total number of entries in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @returns The number of entries in this bin. +*/ +size_t ksmodel_bin_count (struct kshark_trace_histo *histo,int bin) +{ +if (bin >=0 && bin < histo->n_bins) +return histo->bin_count[bin]; + +if (bin ==UPPER_OVERFLOW_BIN ) +return histo->bin_count[UOB (histo)]; + +if (bin ==LOWER_OVERFLOW_BIN ) +return histo->bin_count[LOB (histo)]; + +return 0 ; +} + +/** +* @brief Shift the time-window of the model forward. Recalculate the current +* state of the model. +* @param histo: Input location for the model descriptor.
kernel-shark-qt/src/libkshark-model.c line 412
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* @param n: Number of bins to shift. +*/ +void ksmodel_shift_forward (struct kshark_trace_histo *histo,size_t n) +{ +int bin; + +if (!histo->data_size) +return ; + +if (histo->bin_count[UOB (histo)] ==0 ) {
Or should this be:
if (histo->map[UOB(histo)] == KS_EMPTY_BIN) ?
I know it should mean the same, but we use map below, and I like to be more consistent.
Quoted 16 lines
kernel-shark-qt/src/libkshark-model.c new file +16
-0+/* +* The Upper Overflow bin is empty. This means that we are at +* the upper edge of the dataset already. Do nothing in this +* case. +*/ +return ; + } + + histo->min += n * histo->bin_size; + histo->max += n * histo->bin_size; + +if (n >= histo->n_bins) { +/* +* No overlap between the new and the old ranges. Recalculate +* all bins from scratch. First calculate the new range. +*/
kernel-shark-qt/src/libkshark-model.c line 438
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ksmodel_set_bining (histo, histo->n_bins, histo->min, + histo->max); + +ksmodel_fill (histo, histo->data, histo->data_size); +return ; + } + +/* Set the new Lower Overflow bin. */ +ksmodel_set_lower_edge (histo); +
Hmm, the above also sets histo->map[0]. This should then equal histo->map[n] right? I wonder if we should have a sanity check here making sure that's the case.
Quoted 31 lines
kernel-shark-qt/src/libkshark-model.c new file +31
-0+/* +* Copy the the mapping indexes of all overlaping bins starting from +* bin "0" of the new histo. Note that the number of overlaping bins +* is histo->n_bins - n. +*/ +memmove (&histo->map[0 ], &histo->map[n], +sizeof (histo->map[0 ]) * (histo->n_bins - n)); + +/* +* The the mapping index pf the old Upper Overflow bin is now index +* of the first new bin. +*/ + bin =UOB (histo) - n; + histo->map[bin] = histo->map[UOB (histo)]; + +/* Calculate only the content of the new (non-overlapping) bins. */ +for (; bin < histo->n_bins; ++bin) +ksmodel_set_next_bin_edge (histo, bin); + +/* +* Set the new Upper Overflow bin and calculate the number of entries +* in each bin. +*/ +ksmodel_set_upper_edge (histo); +ksmodel_set_bin_counts (histo); +} + +/** +* @brief Shift the time-window of the model backward. Recalculate the current +* state of the model. +* @param histo: Input location for the model descriptor.
kernel-shark-qt/src/libkshark-model.c line 479
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* @param n: Number of bins to shift. +*/ +void ksmodel_shift_backward (struct kshark_trace_histo *histo,size_t n) +{ +int bin; + +if (!histo->data_size) +return ; + +if (histo->bin_count[LOB (histo)] ==0 ) {
Again, this probably should be:
if (histo->map[LOB(histo)] == KS_EMPTY_BIN) {Quoted 27 lines
kernel-shark-qt/src/libkshark-model.c new file +27
-0+/* +* The Lower Overflow bin is empty. This means that we are at +* the Lower edge of the dataset already. Do nothing in this +* case. +*/ +return ; + } + + histo->min -= n * histo->bin_size; + histo->max -= n * histo->bin_size; + +if (n >= histo->n_bins) { +/* +* No overlap between the new and the old range. Recalculate +* all bins from scratch. First calculate the new range. +*/ +ksmodel_set_bining (histo, histo->n_bins, histo->min, + histo->max); + +ksmodel_fill (histo, histo->data, histo->data_size); +return ; + } + +/* +* Copy the the mapping indexes of all overlaping bins starting from +* bin "0" of the old histo. Note that the number of overlaping bins +* is histo->n_bins - n.
kernel-shark-qt/src/libkshark-model.c line 516
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+*/ +memmove (&histo->map[n], &histo->map[0 ], +sizeof (histo->map[0 ]) * (histo->n_bins - n)); + +/* Set the new Lower Overflow bin. */ +ksmodel_set_lower_edge (histo); + +/* Calculate only the content of the new (non-overlapping) bins. */ + bin =0 ; +while (bin < n) {
This needs to be a for loop.
Quoted 30 lines
kernel-shark-qt/src/libkshark-model.c new file +30
-0+ksmodel_set_next_bin_edge (histo, bin); + ++bin; + } + +/* +* Set the new Upper Overflow bin and calculate the number of entries +* in each bin. +*/ +ksmodel_set_upper_edge (histo); +ksmodel_set_bin_counts (histo); +} + +/** +* @brief Move the time-window of the model to a given location. Recalculate +* the current state of the model. +* @param histo: Input location for the model descriptor. +* @param ts: position in time to be visualized. +*/ +void ksmodel_jump_to (struct kshark_trace_histo *histo,size_t ts) +{ +size_t min, max, range_min; + +if (ts > histo->min && ts < histo->max) { +/* +* The new position is already inside the range. +* Do nothing in this case. +*/ +return ; + } +
kernel-shark-qt/src/libkshark-model.c line 556
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+/* +* Calculate the new range without changing the size and the number +* of bins. +*/ + min = ts - histo->n_bins * histo->bin_size /2 ; + +/* Make sure that the range does not go outside of the dataset. */ +if (min < histo->data[0 ]->ts) + min = histo->data[0 ]->ts; +
I wonder if we should make this an else
else {kernel-shark-qt/src/libkshark-model.c line 561
Quoted 5 lines
kernel-shark-qt/src/libkshark-model.c new file +5
-0+ range_min = histo->data[histo->data_size -1 ]->ts - + histo->n_bins * histo->bin_size; + +if (min > range_min) + min = range_min;
}
Making sure min isn't less than the data set?
Quoted 32 lines
kernel-shark-qt/src/libkshark-model.c new file +32
-0+ + max = min + histo->n_bins * histo->bin_size; + +/* Use the new range to recalculate all bins from scratch. */ +ksmodel_set_bining (histo, histo->n_bins, min, max); +ksmodel_fill (histo, histo->data, histo->data_size); +} + +/** +* @brief Extend the time-window of the model. Recalculate the current state +* of the model. +* @param histo: Input location for the model descriptor. +* @param r: Scale factor of the zoom-out. +* @param mark: Focus point of the zoom-out. +*/ +void ksmodel_zoom_out (struct kshark_trace_histo *histo, +double r,int mark) +{ +size_t range, min, max, delta_min; +double delta_tot; + +if (!histo->data_size) +return ; + +/* +* If the marker is not set, assume that the focal point of the zoom +* is the center of the range. +*/ +if (mark <0 ) + mark = histo->n_bins /2 ; + +/*
kernel-shark-qt/src/libkshark-model.c line 603
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* Calculate the new range of the histo. Use the bin of the marker +* as a focal point for the zoomout. With this the maker will stay +* inside the same bin in the new histo. +*/ + range = histo->max - histo->min; + delta_tot = range * r; + delta_min = delta_tot * mark / histo->n_bins; + + min = histo->min - delta_min; + max = histo->max + (size_t ) delta_tot - delta_min;
Took me a bit to figure out what exactly the above is doing. Let me explain what I think it is doing and you can correct me if I'm wrong.
We set delta_tot to increase by the percentage requested (easy).
Now we make delta_min equal to a percentage of delta_tot based on where mark is in the original bins. If mark is zero, then mark was at 0% of the original bins, if it was at histo->n_bins - 1, it was at (almost) 100%. If it is half way, then we place delta_min at %50 of delta_tot.
Then we subtract the original min by the delta_tot * mark/n_bins percentage, and add the max by delta_tot * (1 - mark/n_bins).
Sound right? Maybe we can add a comment saying such?
Quoted 51 lines
kernel-shark-qt/src/libkshark-model.c new file +51
-0+ +/* Make sure the new range doesn't go outside of the dataset. */ +if (min < histo->data[0 ]->ts) + min = histo->data[0 ]->ts; + +if (max > histo->data[histo->data_size -1 ]->ts) + max = histo->data[histo->data_size -1 ]->ts; + +/* +* Use the new range to recalculate all bins from scratch. Enforce +* "In Range" adjustment of the range of the model, in order to avoid +* slowly drifting outside of the data-set in the case when the very +* first or the very last entry is used as a focal point. +*/ +ksmodel_set_in_range_bining (histo, histo->n_bins, min, max, true); +ksmodel_fill (histo, histo->data, histo->data_size); +} + +/** +* @brief Shrink the time-window of the model. Recalculate the current state +* of the model. +* @param histo: Input location for the model descriptor. +* @param r: Scale factor of the zoom-in. +* @param mark: Focus point of the zoom-in. +*/ +void ksmodel_zoom_in (struct kshark_trace_histo *histo, +double r,int mark) +{ +size_t range, min, max, delta_min; +double delta_tot; + +if (!histo->data_size) +return ; + +/* +* If the marker is not set, assume that the focal point of the zoom +* is the center of the range. +*/ +if (mark <0 ) + mark = histo->n_bins /2 ; + + range = histo->max - histo->min; + +/* Avoid overzooming. */ +if (range < histo->n_bins *4 ) +return ; + +/* +* Calculate the new range of the histo. Use the bin of the marker +* as a focal point for the zoomin. With this the maker will stay +* inside the same bin in the new histo.
kernel-shark-qt/src/libkshark-model.c line 662
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +8
-0+*/ + delta_tot = range * r; +if (mark == (int )histo->n_bins -1 ) + delta_min = delta_tot; +else if (mark ==0 ) + delta_min =0 ; +else + delta_min = delta_tot * mark / histo->n_bins;
The above two are equivalent:
if (mark == 0) Then delta_min = delta_tot * mark / histo->n_bins = 0
kernel-shark-qt/src/libkshark-model.c line 675
Quoted 13 lines
kernel-shark-qt/src/libkshark-model.c new file +13
-0+ + min = histo->min + delta_min; + max = histo->max - (size_t ) delta_tot + delta_min; + +/* +* Use the new range to recalculate all bins from scratch. Enforce +* "In Range" adjustment of the range of the model, in order to avoid +* slowly drifting outside of the data-set in the case when the very +* first or the very last entry is used as a focal point. +*/ +ksmodel_set_in_range_bining (histo, histo->n_bins, min, max, true); +ksmodel_fill (histo, histo->data, histo->data_size); +}
Hmm, I think zoom_out and zoom_in could be combined:
static void ksmodel_zoom(struct kshark_trace_histo *histo,
double r, int mark, bool zoom_in)
{
size_t range, min, max, delta_min;
double delta_tot;
if (!histo->data_size)
return;
/*
* If the marker is not set, assume that the focal point of the zoom
* is the center of the range.
*/
if (mark < 0)
mark = histo->n_bins / 2;
range = histo->max - histo->min;
/* Avoid overzooming. */
if (range < histo->n_bins * 4)
return;
/*
* Calculate the new range of the histo. Use the bin of the marker
* as a focal point for the zoomout. With this the maker will stay
* inside the same bin in the new histo.
*/
delta_tot = range * r;
if (mark == (int)histo->n_bins - 1)
delta_min = delta_tot;
else
delta_min = delta_tot * mark / histo->n_bins;
min = zoom_in ? histo->min + delta_min : histo->min - delta_min;
max = zoom_in ? histo->max - (size_t) delta_tot + delta_min :
histo->max + (size_t) delta_tot - delta_min;
/* Make sure the new range doesn't go outside of the dataset. */
if (min < histo->data[0]->ts)
min = histo->data[0]->ts;
if (max > histo->data[histo->data_size - 1]->ts)
max = histo->data[histo->data_size - 1]->ts;
/*
* Use the new range to recalculate all bins from scratch. Enforce
* "In Range" adjustment of the range of the model, in order to avoid
* slowly drifting outside of the data-set in the case when the very
* first or the very last entry is used as a focal point.
*/
ksmodel_set_in_range_bining(histo, histo->n_bins, min, max, true);
ksmodel_fill(histo, histo->data, histo->data_size);
}void ksmodel_zoom_out(struct kshark_trace_histo *histo,
double r, int mark)
{
ksmodel_zoom(histo, r, mark, false);
}void ksmodel_zoom_in(struct kshark_trace_histo *histo,
double r, int mark)
{
ksmodel_zoom(histo, r, mark, true);
}-- Steve
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 21 lines · Steven Rostedt
kernel-shark-qt/src/libkshark-model.c line 603
Quoted 11 lines
kernel-shark-qt/src/libkshark-model.c new file +11
-0+/* +* Calculate the new range of the histo. Use the bin of the marker +* as a focal point for the zoomout. With this the maker will stay +* inside the same bin in the new histo. +*/ + range = histo->max - histo->min; + delta_tot = range * r; + delta_min = delta_tot * mark / histo->n_bins; + + min = histo->min - delta_min; + max = histo->max + (size_t ) delta_tot - delta_min;Took me a bit to figure out what exactly the above is doing. Let me explain what I think it is doing and you can correct me if I'm wrong.
We set
delta_totto increase by the percentage requested (easy).Now we make
delta_minequal to a percentage ofdelta_totbased on where mark is in the original bins. If mark is zero, then mark was at 0% of the original bins, if it was athisto->n_bins- 1, it was at (almost) 100%. If it is half way, then we placedelta_minat %50 ofdelta_tot.
Quoted 5 lines
Then we subtract the original min by the
delta_tot* mark/n_bins percentage, and add the max bydelta_tot* (1 - mark/n_bins).Sound right? Maybe we can add a comment saying such?
Yes, this is a correct explanation. I will use it as a comment in the code.
Thanks!
Yordan
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Yordan Karadzhov (VMware)Quoted 4 lines · On Tue, 31 Jul 2018 16:52:44 +0300 "Yordan Karadzhov (VMware)"…
kernel-shark-qt/src/libkshark-model.c new file +4
-0+/** +* @brief Get the index of the first entry in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id.
kernel-shark-qt/src/libkshark-model.c line 690
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+* @returns Index of the first entry in this bin. If the bin is empty the +* function returns negative error identifier (KS_EMPTY_BIN). +*/ +ssize_t ksmodel_first_index_at_bin (struct kshark_trace_histo *histo,int bin) +{ +if (bin >=0 && bin < (int ) histo->n_bins) +return histo->map[bin]; + +if (bin ==UPPER_OVERFLOW_BIN ) +return histo->map[histo->n_bins];
return histo->map[UOB(histo)];
kernel-shark-qt/src/libkshark-model.c line 693
Quoted 3 lines
kernel-shark-qt/src/libkshark-model.c new file +3
-0+ +if (bin ==LOWER_OVERFLOW_BIN ) +return histo->map[histo->n_bins +1 ];
return histo->map[LOB(histo)];
Quoted 39 lines
kernel-shark-qt/src/libkshark-model.c new file +39
-0+ +return KS_EMPTY_BIN ; +} + +/** +* @brief Get the index of the last entry in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @returns Index of the last entry in this bin. If the bin is empty the +* function returns negative error identifier (KS_EMPTY_BIN). +*/ +ssize_t ksmodel_last_index_at_bin (struct kshark_trace_histo *histo,int bin) +{ +ssize_t index =ksmodel_first_index_at_bin (histo, bin); +size_t count =ksmodel_bin_count (histo, bin); + +if (index >=0 && count) + index += count -1 ; + +return index; +} + +static bool ksmodel_is_visible (struct kshark_entry *e) +{ +if ((e->visible &KS_GRAPH_VIEW_FILTER_MASK ) && + (e->visible &KS_EVENT_VIEW_FILTER_MASK )) +return true; + +return false; +} + +static struct kshark_entry_request * +ksmodel_entry_front_request_alloc (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val) +{ +struct kshark_entry_request *req; +size_t first, n; +
kernel-shark-qt/src/libkshark-model.c line 742
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+/* Get the number of entries in this bin. */ + n =ksmodel_bin_count (histo, bin); +if (!n) +return NULL ; + + first =ksmodel_first_index_at_bin (histo, bin); + + req =kshark_entry_request_alloc (first, n, + func, val, + vis_only,KS_GRAPH_VIEW_FILTER_MASK );
No need for req; just return the function:
return kshark_entry_request_alloc(...);
Quoted 12 lines
kernel-shark-qt/src/libkshark-model.c new file +12
-0+ +return req; +} + +static struct kshark_entry_request * +ksmodel_entry_back_request_alloc (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val) +{ +struct kshark_entry_request *req; +size_t first, n; +
kernel-shark-qt/src/libkshark-model.c line 764
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+/* Get the number of entries in this bin. */ + n =ksmodel_bin_count (histo, bin); +if (!n) +return NULL ; + + first =ksmodel_last_index_at_bin (histo, bin); + + req =kshark_entry_request_alloc (first, n, + func, val, + vis_only,KS_GRAPH_VIEW_FILTER_MASK );
Same here.
Quoted 11 lines
kernel-shark-qt/src/libkshark-model.c new file +11
-0+ +return req; +} + +/** +* @brief Get the index of the first entry from a given Cpu in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param cpu: Cpu Id. +* @returns Index of the first entry from a given Cpu in this bin. +*/
kernel-shark-qt/src/libkshark-model.c line 785
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ssize_t ksmodel_first_index_at_cpu (struct kshark_trace_histo *histo, +int bin,int cpu) +{ +size_t i, n, first, not_found =KS_EMPTY_BIN ; + + n =ksmodel_bin_count (histo, bin); +if (!n) +return not_found; + + first =ksmodel_first_index_at_bin (histo, bin);
I wonder what this is used for. Don't we have per cpu arrays or link lists?
Quoted 70 lines
kernel-shark-qt/src/libkshark-model.c new file +70
-0+ +for (i = first; i < first + n; ++i) { +if (histo->data[i]->cpu == cpu) { +if (ksmodel_is_visible (histo->data[i])) +return i; +else + not_found =KS_FILTERED_BIN ; + } + } + +return not_found; +} + +/** +* @brief Get the index of the first entry from a given Task in a given bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param pid: Process Id of a task. +* @returns Index of the first entry from a given Task in this bin. +*/ +ssize_t ksmodel_first_index_at_pid (struct kshark_trace_histo *histo, +int bin,int pid) +{ +size_t i, n, first, not_found =KS_EMPTY_BIN ; + + n =ksmodel_bin_count (histo, bin); +if (!n) +return not_found; + + first =ksmodel_first_index_at_bin (histo, bin); + +for (i = first; i < first + n; ++i) { +if (histo->data[i]->pid == pid) { +if (ksmodel_is_visible (histo->data[i])) +return i; +else + not_found =KS_FILTERED_BIN ; + } + } + +return not_found; +} + +/** +* @brief In a given bin, start from the front end of the bin and go towards +* the back end, searching for an entry satisfying the Matching +* condition defined by a Matching condition function. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param vis_only: If true, a visible entry is requested. +* @param func: Matching condition function. +* @param val: Matching condition value, used by the Matching condition +* function. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Pointer ot a kshark_entry, if an entry has been found. Else NULL. +*/ +const struct kshark_entry * +ksmodel_get_entry_front (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val, +ssize_t *index) +{ +struct kshark_entry_request *req; +const struct kshark_entry *entry; + +if (index) + *index =KS_EMPTY_BIN ; + +/* Set the position at the beginning of the bin and go forward. */
kernel-shark-qt/src/libkshark-model.c line 865
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ req =ksmodel_entry_front_request_alloc (histo, bin, vis_only, + func, val); +if (!req) +return NULL ; + + entry =kshark_get_entry_front (req, histo->data, index); +free (req); + +return entry; +}
We could save on the allocation if we were to create the following:
void
kshark_entry_request_set(struct kshark_entry_request *req,
size_t first, size_t n, matching_condition_func cond, int val, bool vis_only, int vis_mask)
{
req->first = first;
req->n = n;
req->cond = cond;
req->val = val;
req->vis_only = vis_only;
req->vis_mask = vis_mask;
}bool
ksmodel_entry_front_request_set(struct kshark_trace_histo *histo,
struct kshark_entry_request *req, int bin, bool vis_only, matching_condition_func func, int val)
{
size_t first, n;
/* Get the number of entries in this bin. */
n = ksmodel_bin_count(histo, bin);
if (!n)
return false;
first = ksmodel_first_index_at_bin(histo, bin);
kshark_entry_request_set(first, n,
func, val,
vis_only, KS_GRAPH_VIEW_FILTER_MASK);
return true;
}const struct kshark_entry * ksmodel_get_entry_front(struct kshark_trace_histo *histo,
int bin, bool vis_only, matching_condition_func func, int val, ssize_t *index)
{
struct kshark_entry_request req;
const struct kshark_entry *entry;
bool ret;
if (index)
*index = KS_EMPTY_BIN;
/* Set the position at the beginning of the bin and go forward. */
ret = ksmodel_entry_front_request_set(histo, bin, vis_only,
func, val);
if (!ret)
return NULL;
entry = kshark_get_entry_front(req, histo->data, index);
return entry;
}Quoted 25 lines
kernel-shark-qt/src/libkshark-model.c new file +25
-0+ +/** +* @brief In a given bin, start from the back end of the bin and go towards +* the front end, searching for an entry satisfying the Matching +* condition defined by a Matching condition function. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param vis_only: If true, a visible entry is requested. +* @param func: Matching condition function. +* @param val: Matching condition value, used by the Matching condition +* function. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Pointer ot a kshark_entry, if an entry has been found. Else NULL. +*/ +const struct kshark_entry * +ksmodel_get_entry_back (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val, +ssize_t *index) +{ +struct kshark_entry_request *req; +const struct kshark_entry *entry; + +if (index)
kernel-shark-qt/src/libkshark-model.c line 900
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ *index =KS_EMPTY_BIN ; + +/* Set the position at the end of the bin and go backwards. */ + req =ksmodel_entry_back_request_alloc (histo, bin, vis_only, + func, val); +if (!req) +return NULL ; + + entry =kshark_get_entry_back (req, histo->data, index); +free (req);
Ditto.
Quoted 162 lines
kernel-shark-qt/src/libkshark-model.c new file +162
-0+ +return entry; +} + +static int ksmodel_get_entry_pid (const struct kshark_entry *entry) +{ +if (!entry) { +/* No data has been found. */ +return KS_EMPTY_BIN ; + } + +/* +* Note that if some data has been found, but this data is +* filtered-outa, the Dummy entry is returned. The PID of the Dummy +* entry is KS_FILTERED_BIN. +*/ + +return entry->pid; +} + +/** +* @brief In a given bin, start from the front end of the bin and go towards +* the back end, searching for an entry from a given CPU. Return +* the Process Id of the task of the entry found. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param cpu: CPU Id. +* @param vis_only: If true, a visible entry is requested. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Process Id of the task if an entry has been found. Else a negative +* Identifier (KS_EMPTY_BIN or KS_FILTERED_BIN). +*/ +int ksmodel_get_pid_front (struct kshark_trace_histo *histo, +int bin,int cpu,bool vis_only, +ssize_t *index) +{ +const struct kshark_entry *entry; + +if (cpu <0 ) +return KS_EMPTY_BIN ; + + entry =ksmodel_get_entry_front (histo, bin, vis_only, + kshark_match_cpu, cpu, + index); +return ksmodel_get_entry_pid (entry); +} + +/** +* @brief In a given bin, start from the back end of the bin and go towards +* the front end, searching for an entry from a given CPU. Return +* the Process Id of the task of the entry found. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param cpu: CPU Id. +* @param vis_only: If true, a visible entry is requested. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Process Id of the task if an entry has been found. Else a negative +* Identifier (KS_EMPTY_BIN or KS_FILTERED_BIN). +*/ +int ksmodel_get_pid_back (struct kshark_trace_histo *histo, +int bin,int cpu,bool vis_only, +ssize_t *index) +{ +const struct kshark_entry *entry; + +if (cpu <0 ) +return KS_EMPTY_BIN ; + + entry =ksmodel_get_entry_back (histo, bin, vis_only, + kshark_match_cpu, cpu, + index); + +return ksmodel_get_entry_pid (entry); +} + +static int ksmodel_get_entry_cpu (const struct kshark_entry *entry) +{ +if (!entry) { +/* No data has been found. */ +return KS_EMPTY_BIN ; + } + +/* +* Note that if some data has been found, but this data is +* filtered-outa, the Dummy entry is returned. The CPU Id of the Dummy +* entry is KS_FILTERED_BIN. +*/ + +return entry->cpu; +} + +/** +* @brief In a given bin, start from the front end of the bin and go towards +* the back end, searching for an entry from a given PID. Return +* the CPU Id of the entry found. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param pid: Process Id. +* @param vis_only: If true, a visible entry is requested. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Process Id of the task if an entry has been found. Else a negative +* Identifier (KS_EMPTY_BIN or KS_FILTERED_BIN). +*/ +int ksmodel_get_cpu_front (struct kshark_trace_histo *histo, +int bin,int pid,bool vis_only, +ssize_t *index) +{ +const struct kshark_entry *entry; + +if (pid <0 ) +return KS_EMPTY_BIN ; + + entry =ksmodel_get_entry_front (histo, bin, vis_only, + kshark_match_pid, pid, + index); +return ksmodel_get_entry_cpu (entry); +} + +/** +* @brief In a given bin, start from the back end of the bin and go towards +* the front end, searching for an entry from a given PID. Return +* the CPU Id of the entry found. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param pid: Process Id. +* @param vis_only: If true, a visible entry is requested. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Process Id of the task if an entry has been found. Else a negative +* Identifier (KS_EMPTY_BIN or KS_FILTERED_BIN). +*/ +int ksmodel_get_cpu_back (struct kshark_trace_histo *histo, +int bin,int pid,bool vis_only, +ssize_t *index) +{ +const struct kshark_entry *entry; + +if (pid <0 ) +return KS_EMPTY_BIN ; + + entry =ksmodel_get_entry_back (histo, bin, vis_only, + kshark_match_pid, pid, + index); + +return ksmodel_get_entry_cpu (entry); +} + +/** +* @brief Check if a visible trace event from a given Cpu exists in this bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param cpu: Cpu Id. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns True, if a visible entry exists in this bin. Else false. +*/ +bool ksmodel_cpu_visible_event_exist (struct kshark_trace_histo *histo, +int bin,int cpu,ssize_t *index) +{
kernel-shark-qt/src/libkshark-model.c line 1072
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+struct kshark_entry_request *req; +const struct kshark_entry *entry; + +if (index) + *index =KS_EMPTY_BIN ; + +/* Set the position at the beginning of the bin and go forward. */ + req =ksmodel_entry_front_request_alloc (histo, + bin, true, + kshark_match_cpu, cpu);
And would save an allocation here too.
Quoted 45 lines
kernel-shark-qt/src/libkshark-model.c new file +45
-0+if (!req) +return false; + +/* +* The default visibility mask of the Model Data request is +* KS_GRAPH_VIEW_FILTER_MASK. Change the mask to +* KS_EVENT_VIEW_FILTER_MASK because we want to find a visible event. +*/ + req->vis_mask =KS_EVENT_VIEW_FILTER_MASK ; + + entry =kshark_get_entry_front (req, histo->data, index); +free (req); + +if (!entry || !entry->visible) { +/* No visible entry has been found. */ +return false; + } + +return true; +} + +/** +* @brief Check if a visible trace event from a given Task exists in this bin. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param pid: Process Id of the task. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns True, if a visible entry exists in this bin. Else false. +*/ +bool ksmodel_task_visible_event_exist (struct kshark_trace_histo *histo, +int bin,int pid,ssize_t *index) +{ +struct kshark_entry_request *req; +const struct kshark_entry *entry; + +if (index) + *index =KS_EMPTY_BIN ; + +/* Set the position at the beginning of the bin and go forward. */ + req =ksmodel_entry_front_request_alloc (histo, + bin, true, + kshark_match_pid, pid); +if (!req) +return false;
kernel-shark-qt/src/libkshark-model.c line 1127
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ +/* +* The default visibility mask of the Model Data request is +* KS_GRAPH_VIEW_FILTER_MASK. Change the mask to +* KS_EVENT_VIEW_FILTER_MASK because we want to find a visible event. +*/ + req->vis_mask =KS_EVENT_VIEW_FILTER_MASK ; + + entry =kshark_get_entry_front (req, histo->data, index); +free (req);
And here.
-- Steve
Quoted 8 lines
kernel-shark-qt/src/libkshark-model.c new file +8
-0+ +if (!entry || !entry->visible) { +/* No visible entry has been found. */ +return false; + } + +return true; +}
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 91 lines · Steven Rostedt
Quoted 28 lines
kernel-shark-qt/src/libkshark-model.c new file +28
-0+ +/** +* @brief In a given bin, start from the front end of the bin and go towards +* the back end, searching for an entry satisfying the Matching +* condition defined by a Matching condition function. +* @param histo: Input location for the model descriptor. +* @param bin: Bin id. +* @param vis_only: If true, a visible entry is requested. +* @param func: Matching condition function. +* @param val: Matching condition value, used by the Matching condition +* function. +* @param index: Optional output location for the index of the requested +* entry inside the array. +* @returns Pointer ot a kshark_entry, if an entry has been found. Else NULL. +*/ +const struct kshark_entry * +ksmodel_get_entry_front (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val, +ssize_t *index) +{ +struct kshark_entry_request *req; +const struct kshark_entry *entry; + +if (index) + *index =KS_EMPTY_BIN ; + +/* Set the position at the beginning of the bin and go forward. */ kernel-shark-qt/src/libkshark-model.c line 865
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.c new file +10
-0+ req =ksmodel_entry_front_request_alloc (histo, bin, vis_only, + func, val); +if (!req) +return NULL ; + + entry =kshark_get_entry_front (req, histo->data, index); +free (req); + +return entry; +}We could save on the allocation if we were to create the following:
void
kshark_entry_request_set(structkshark_entry_request*req,
size_tfirst,size_tn,matching_condition_funccond, int val, boolvis_only, intvis_mask){ req->first = first; req->n = n; req->cond = cond; req->val = val; req->vis_only = vis_only; req->vis_mask = vis_mask; }bool
ksmodel_entry_front_request_set(structkshark_trace_histo*histo,
structkshark_entry_request*req, int bin, boolvis_only,matching_condition_funcfunc, int val){ size_t first, n; /* Get the number of entries in this bin. */ n = ksmodel_bin_count(histo, bin); if (!n) return false; first = ksmodel_first_index_at_bin(histo, bin); kshark_entry_request_set(first, n, func, val, vis_only, KS_GRAPH_VIEW_FILTER_MASK); return true; }const struct
kshark_entry* ksmodel_get_entry_front(structkshark_trace_histo*histo,
int bin, boolvis_only,matching_condition_funcfunc, int val,ssize_t*index){ struct kshark_entry_request req; const struct kshark_entry *entry; bool ret; if (index) *index = KS_EMPTY_BIN; /* Set the position at the beginning of the bin and go forward. */ ret = ksmodel_entry_front_request_set(histo, bin, vis_only,
Quoted 9 lines
func, val); if (!ret) return NULL; entry = kshark_get_entry_front(req, histo->data, index); return entry; }
Hi Steven,
I have tried implementing this, but it becomes a bit ugly in the following patches where the single request is transformed into a linked list of requests.
Thanks!
Yordan
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 4 lines · On Fri, 3 Aug 2018 17:01:45 +0300 "Yordan Karadzhov (VMware)"…
Hi Steven,
I have tried implementing this, but it becomes a bit ugly in the following patches where the single request is transformed into a linked list of requests.
OK. Then let's not implement it, and see if we can clean it up later after most of the changes have been made. I was hoping that it would make the later patches better, but if that's not the case, then let's ditch the idea.
-- Steve
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
In reply to Yordan Karadzhov (VMware)Quoted 16 lines · On Tue, 31 Jul 2018 16:52:44 +0300 "Yordan Karadzhov (VMware)"…
index 0000000..15391a9
kernel-shark-qt/src/libkshark-model.h new file +12
-0@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ + +/* +* Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> +*/ + +/** +* @file libkshark-model.h +* @brief Visualization model for FTRACE (trace-cmd) data. +*/ + +#ifndef _LIB_KSHARK_MODEL_H
kernel-shark-qt/src/libkshark-model.h line 22
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.h new file +10
-0+#define _LIB_KSHARK_MODEL_H + +// KernelShark +#include "libkshark.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/** Overflow Bin identifiers. */
Should add what an "Overflow Bin" is.
Quoted 4 lines
kernel-shark-qt/src/libkshark-model.h new file +4
-0+enum OverflowBin { +/** Identifier of the Upper Overflow Bin. */ +UPPER_OVERFLOW_BIN =-1 , +
kernel-shark-qt/src/libkshark-model.h line 36
Quoted 10 lines
kernel-shark-qt/src/libkshark-model.h new file +10
-0+/** Identifier of the Lower Overflow Bin. */ + LOWER_OVERFLOW_BIN = -2, +}; + +/** Structure describing the current state of the visualization model. */ +struct kshark_trace_histo { +/** Trace data. */ +struct kshark_entry **data; + +/** The size of the data. */
/** The size of the above data array */
kernel-shark-qt/src/libkshark-model.h line 39
Quoted 3 lines
kernel-shark-qt/src/libkshark-model.h new file +3
-0+size_t data_size; + +/** The index of the first entry in each bin. */
/** The first entry (index of data array) in each bin */
kernel-shark-qt/src/libkshark-model.h line 51
Quoted 12 lines
kernel-shark-qt/src/libkshark-model.h new file +12
-0+ssize_t *map; + +/** Number of entries in each bin. */ +size_t *bin_count; + +/** Lower edge of the time-window to be visualized. */ +uint64_t min; + +/** Upper edge of the time-window to be visualized. */ +uint64_t max; + +/** The size of the bins. */
/** The size in time for each bin */
kernel-shark-qt/src/libkshark-model.h line 56
Quoted 5 lines
kernel-shark-qt/src/libkshark-model.h new file +5
-0+uint64_t bin_size; + +/** Number of bins. */ +int n_bins; +};
The rest looks good. Ug that was a big patch to review! ;-)
-- Steve
Quoted 86 lines
kernel-shark-qt/src/libkshark-model.h new file +86
-0+ +void ksmodel_init (struct kshark_trace_histo *histo); + +void ksmodel_clear (struct kshark_trace_histo *histo); + +void ksmodel_set_bining (struct kshark_trace_histo *histo, +size_t n,uint64_t min,uint64_t max); + +void ksmodel_fill (struct kshark_trace_histo *histo, +struct kshark_entry **data,size_t n); + +size_t ksmodel_bin_count (struct kshark_trace_histo *histo,int bin); + +void ksmodel_shift_forward (struct kshark_trace_histo *histo,size_t n); + +void ksmodel_shift_backward (struct kshark_trace_histo *histo,size_t n); + +void ksmodel_jump_to (struct kshark_trace_histo *histo,size_t ts); + +void ksmodel_zoom_out (struct kshark_trace_histo *histo, +double r,int mark); + +void ksmodel_zoom_in (struct kshark_trace_histo *histo, +double r,int mark); + +ssize_t ksmodel_first_index_at_bin (struct kshark_trace_histo *histo,int bin); + +ssize_t ksmodel_last_index_at_bin (struct kshark_trace_histo *histo,int bin); + +ssize_t ksmodel_first_index_at_cpu (struct kshark_trace_histo *histo, +int bin,int cpu); + +ssize_t ksmodel_first_index_at_pid (struct kshark_trace_histo *histo, +int bin,int pid); + +const struct kshark_entry * +ksmodel_get_entry_front (struct kshark_trace_histo *histo, +int bin,bool vis_only, +matching_condition_func func,int val, +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, +ssize_t *index); + +int ksmodel_get_pid_front (struct kshark_trace_histo *histo, +int bin,int cpu,bool vis_only, +ssize_t *index); + +int ksmodel_get_pid_back (struct kshark_trace_histo *histo, +int bin,int cpu,bool vis_only, +ssize_t *index); + +int ksmodel_get_cpu_front (struct kshark_trace_histo *histo, +int bin,int pid,bool vis_only, +ssize_t *index); + +int ksmodel_get_cpu_back (struct kshark_trace_histo *histo, +int bin,int pid,bool vis_only, +ssize_t *index); + +bool ksmodel_cpu_visible_event_exist (struct kshark_trace_histo *histo, +int bin,int cpu,ssize_t *index); + +bool ksmodel_task_visible_event_exist (struct kshark_trace_histo *histo, +int bin,int pid,ssize_t *index); + +static inline double ksmodel_bin_time (struct kshark_trace_histo *histo, +int bin) +{ +return (histo->min + bin*histo->bin_size) *1e-9 ; +} + +static inline uint64_t ksmodel_bin_ts (struct kshark_trace_histo *histo, +int bin) +{ +return (histo->min + bin*histo->bin_size); +} + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 2 lines · Steven Rostedt
Quoted 1 line
+};
The rest looks good. Ug that was a big patch to review!;-)
It was a big patch indeed. Thank you very much!!!
Please hold on the review of [4/7], because I found couple of bugs in this patch. I will send v3 tomorrow.
Yordan
Quoted 3 lines
-- Steve
Re: [PATCH v2 3/7] kernel-shark-qt: Introduce the visualization model used by the Qt-based KS
Quoted 7 lines · On Wed, 1 Aug 2018 22:06:44 +0300 Yordan Karadzhov <[email protected]> wrote:
Quoted 2 lines · Steven Rostedt
Quoted 1 line
+};
The rest looks good. Ug that was a big patch to review!;-)
It was a big patch indeed. Thank you very much!!!
Please hold on the review of [4/7], because I found couple of bugs in this patch. I will send v3 tomorrow.
Thanks for letting me know!
-- Steve
PATCH v2 4/7 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 v2 5/7 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. Once defined, the Data collection can be used when searching for an entry having the same abstract property. The collection allows to ignore the irrelevant data, thus it eliminates the linear worst-case time complexity of the search.
--- kernel-shark-qt/src/CMakeLists.txt | 3 +- kernel-shark-qt/src/libkshark-collection.c | 827 +++++++++++++++++++++ kernel-shark-qt/src/libkshark.c | 16 + kernel-shark-qt/src/libkshark.h | 79 ++ 4 files changed, 924 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 +827 -0
827 lines not on this page · raw message
kernel-shark-qt/src/libkshark.c +16 -0
@@ -1024,6 +1024,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;
@@ -1034,6 +1035,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 +79 -0
103 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 6/7 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
199 lines not on this page · raw message
kernel-shark-qt/src/libkshark-model.h +12 -2
@@ -93,35 +93,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 v2 7/7 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