Final preparation before adding the KernelShark GUI
v2 cover Final preparation before adding the KernelShark GUI
Five small patches needed as a final preparation before introducing the first components of the Qt-based KernelShark GUI.
This is the second version of this series of patches. Major changes from v1 are:
[1/5] int kshark_get_event_id_easy(struct kshark_entry *entry) has been added.
[5/5] This is a new patch. It fixes a bug in kshark_data_collection_alloc()
Yordan Karadzhov (1):
kernel-shark-qt: Fix a bug in kshark_data_collection_alloc()
Yordan Karadzhov (VMware) (4):
kernel-shark-qt: Add kshark_get_X_easy() functions.
kernel-shark-qt: Add kshark_convert_nano() function
kernel-shark-qt: Add functions for fast clearing of the filters.
kernel-shark-qt: Rename the Cmake-generated header file.
kernel-shark-qt/build/cmake_clean.sh | 2 +- kernel-shark-qt/build/deff.h.cmake | 2 +- kernel-shark-qt/src/CMakeLists.txt | 2 +- kernel-shark-qt/src/libkshark-collection.c | 26 ++- kernel-shark-qt/src/libkshark.c | 227 ++++++++++++++++++++- kernel-shark-qt/src/libkshark.h | 20 ++ 6 files changed, 267 insertions(+), 12 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/5 kernel-shark-qt: Add kshark_get_X_easy() functions.
From: "Yordan Karadzhov (VMware)" <[email protected]>
The kshark_get_X_easy() functions allow for an easy access to the tep_record's fields. Using these functions can be inefficient if you need access to more than one of the fields of the record.
--- kernel-shark-qt/src/libkshark.c | 185 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 12 +++ 2 files changed, 197 insertions(+)
kernel-shark-qt/src/libkshark.c +185 -0
@@ -888,6 +888,191 @@ static const char *kshark_get_info(struct tep_handle *pe,return seq.buffer; } +/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the +* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ; + +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) { + pid = entry->pid; + }else { + data =kshark_read_at (kshark_ctx, entry->offset); + pid =tep_data_pid (kshark_ctx->pevent, data); +free_record (data); + } + +return pid; +} + +/** +* @brief This function allows for an easy access to the original value of the +* Task name as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original name of the task, retrieved from the Process Id +* recorded in the tep_record object on success, otherwise NULL. +*/ +const char *kshark_get_task_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +int pid =kshark_get_pid_easy (entry); + +if (pid <0 || !kshark_instance (&kshark_ctx)) +return NULL ; + +return tep_data_comm_from_pid (kshark_ctx->pevent, pid); +} + +/** +* @brief This function allows for an easy access to the latency information +* recorded in the tep_record object. The record is read from the file +* using the offset field of kshark_entry. Be aware that using the +* kshark_get_X_easy functions can be inefficient if you need an access +* to more than one of the data fields of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns On success the function returns a string showing the latency +* information, coded into 5 fields: +* interrupts disabled, need rescheduling, hard/soft interrupt, +* preempt count and lock depth. On failure it returns NULL. +*/ +const char *kshark_get_latency_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +const char *lat; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + data =kshark_read_at (kshark_ctx, entry->offset); + lat =kshark_get_latency (kshark_ctx->pevent, data); +free_record (data); + +return lat; +} + +/** +* @brief This function allows for an easy access to the original value of the +* Event Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Event Id as recorded in the +* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_event_id_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int event_id; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ; + +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) { + event_id = entry->event_id; + }else { + data =kshark_read_at (kshark_ctx, entry->offset); + event_id =tep_data_type (kshark_ctx->pevent, data); +free_record (data); + } + +return event_id; +} + +/** +* @brief This function allows for an easy access to the original name of the +* trace event as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The mane of the trace event recorded in the tep_record object on +* success, otherwise "[UNKNOWN EVENT]" or NULL. +*/ +const char *kshark_get_event_name_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct event_format *event; + +int event_id =kshark_get_event_id_easy (entry); + +if (event_id <0 || !kshark_instance (&kshark_ctx)) +return NULL ; + + event =tep_data_event_from_type (kshark_ctx->pevent, event_id); +if (event) +return event->name; + +return "[UNKNOWN EVENT]" ; +} + +/** +* @brief This function allows for an easy access to the tep_record's info +* streang. The record is read from the file using the offset field of +* kshark_entry. Be aware that using the kshark_get_X_easy functions can +* be inefficient if you need an access to more than one of the data +* fields of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns A string showing the data output of the trace event on success, +* otherwise NULL. +*/ +const char *kshark_get_info_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct event_format *event; +struct tep_record *data; +const char *info =NULL ; +int event_id; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + data =kshark_read_at (kshark_ctx, entry->offset); + + event_id =tep_data_type (kshark_ctx->pevent, data); + event =tep_data_event_from_type (kshark_ctx->pevent, event_id); +if (event) + info =kshark_get_info (kshark_ctx->pevent, data, event); + +free_record (data); + +return info; +} +/** * @brief Dump into a string the content of one entry. The function allocates * a null terminated string and returns a pointer to this string. The
kernel-shark-qt/src/libkshark.h +12 -0
@@ -148,6 +148,18 @@ void kshark_close(struct kshark_context *kshark_ctx);void kshark_free (struct kshark_context *kshark_ctx); +int kshark_get_pid_easy (struct kshark_entry *entry); + +const char *kshark_get_task_easy (struct kshark_entry *entry); + +const char *kshark_get_latency_easy (struct kshark_entry *entry); + +int kshark_get_event_id_easy (struct kshark_entry *entry); + +const char *kshark_get_event_name_easy (struct kshark_entry *entry); + +const char *kshark_get_info_easy (struct kshark_entry *entry); +char *kshark_dump_entry (const struct kshark_entry *entry); struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx,
Signature · 1 line
2.17.1
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Quoted 31 lines · On Mon, 1 Oct 2018 16:59:17 +0300 Yordan Karadzhov <[email protected]>…
From: "Yordan Karadzhov (VMware)" <[email protected]>
The
kshark_get_X_easy()functions allow for an easy access to the tep_record's fields. Using these functions can be inefficient if you need access to more than one of the fields of the record.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 185 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 12 +++ 2 files changed, 197 insertions(+)kernel-shark-qt/src/libkshark.c +11
-0@@ -888,6 +888,191 @@ static const char *kshark_get_info(struct tep_handle *pe,return seq.buffer; } +/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 911
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ;
Perhaps this should return -ENODEV;
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 913
Quoted 2 lines
kernel-shark-qt/src/libkshark.c +2
-0+ +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) {
What's the "UNTOUCHED_MASK" mean?
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 918
Quoted 5 lines
kernel-shark-qt/src/libkshark.c +5
-0+ pid = entry->pid; + }else { + data =kshark_read_at (kshark_ctx, entry->offset); + pid =tep_data_pid (kshark_ctx->pevent, data); +free_record (data);
Would it be possible to do:
entry->visible |= KS_PLUGIN_UNTOUCHED_MASK; entry->pid = pid;
?
Of course this depends on what that mask means.
Quoted 14 lines
kernel-shark-qt/src/libkshark.c +14
-0+ } + +return pid; +} + +/** +* @brief This function allows for an easy access to the original value of the +* Task name as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry.
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 942
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* +* @returns The original name of the task, retrieved from the Process Id +* recorded in the tep_record object on success, otherwise NULL. +*/ +const char *kshark_get_task_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +int pid =kshark_get_pid_easy (entry); + +if (pid <0 || !kshark_instance (&kshark_ctx))
The second part is redundant, as kshark_get_pid_easy() will return pid < 0 if that was true.
Quoted 53 lines
kernel-shark-qt/src/libkshark.c +53
-0+return NULL ; + +return tep_data_comm_from_pid (kshark_ctx->pevent, pid); +} + +/** +* @brief This function allows for an easy access to the latency information +* recorded in the tep_record object. The record is read from the file +* using the offset field of kshark_entry. Be aware that using the +* kshark_get_X_easy functions can be inefficient if you need an access +* to more than one of the data fields of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns On success the function returns a string showing the latency +* information, coded into 5 fields: +* interrupts disabled, need rescheduling, hard/soft interrupt, +* preempt count and lock depth. On failure it returns NULL. +*/ +const char *kshark_get_latency_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +const char *lat; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + data =kshark_read_at (kshark_ctx, entry->offset); + lat =kshark_get_latency (kshark_ctx->pevent, data); +free_record (data); + +return lat; +} + +/** +* @brief This function allows for an easy access to the original value of the +* Event Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Event Id as recorded in the +* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_event_id_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int event_id;
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 1005
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+ +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ; + +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) { + event_id = entry->event_id; + }else { + data =kshark_read_at (kshark_ctx, entry->offset); + event_id =tep_data_type (kshark_ctx->pevent, data); +free_record (data);
If the above can update "easy" untouch flag, then this too.
Quoted 16 lines
kernel-shark-qt/src/libkshark.c +16
-0+ } + +return event_id; +} + +/** +* @brief This function allows for an easy access to the original name of the +* trace event as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The mane of the trace event recorded in the tep_record object on
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 1031
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* success, otherwise "[UNKNOWN EVENT]" or NULL. +*/ +const char *kshark_get_event_name_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct event_format *event; + +int event_id =kshark_get_event_id_easy (entry); + +if (event_id <0 || !kshark_instance (&kshark_ctx))
Again this is redundant.
-- Steve
Quoted 70 lines
kernel-shark-qt/src/libkshark.c +44
-0+return NULL ; + + event =tep_data_event_from_type (kshark_ctx->pevent, event_id); +if (event) +return event->name; + +return "[UNKNOWN EVENT]" ; +} + +/** +* @brief This function allows for an easy access to the tep_record's info +* streang. The record is read from the file using the offset field of +* kshark_entry. Be aware that using the kshark_get_X_easy functions can +* be inefficient if you need an access to more than one of the data +* fields of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns A string showing the data output of the trace event on success, +* otherwise NULL. +*/ +const char *kshark_get_info_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct event_format *event; +struct tep_record *data; +const char *info =NULL ; +int event_id; + +if (!kshark_instance (&kshark_ctx)) +return NULL ; + + data =kshark_read_at (kshark_ctx, entry->offset); + + event_id =tep_data_type (kshark_ctx->pevent, data); + event =tep_data_event_from_type (kshark_ctx->pevent, event_id); +if (event) + info =kshark_get_info (kshark_ctx->pevent, data, event); + +free_record (data); + +return info; +} +/** * @brief Dump into a string the content of one entry. The function allocates * a null terminated string and returns a pointer to this string. The kernel-shark-qt/src/libkshark.h +12
-0@@ -148,6 +148,18 @@ void kshark_close(struct kshark_context *kshark_ctx);void kshark_free (struct kshark_context *kshark_ctx); +int kshark_get_pid_easy (struct kshark_entry *entry); + +const char *kshark_get_task_easy (struct kshark_entry *entry); + +const char *kshark_get_latency_easy (struct kshark_entry *entry); + +int kshark_get_event_id_easy (struct kshark_entry *entry); + +const char *kshark_get_event_name_easy (struct kshark_entry *entry); + +const char *kshark_get_info_easy (struct kshark_entry *entry); +char *kshark_dump_entry (const struct kshark_entry *entry); struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx,
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Quoted 47 lines · Steven Rostedt
Quoted 31 lines · On Mon, 1 Oct 2018 16:59:17 +0300 Yordan Karadzhov <[email protected]>…
From: "Yordan Karadzhov (VMware)" <[email protected]>
The
kshark_get_X_easy()functions allow for an easy access to the tep_record's fields. Using these functions can be inefficient if you need access to more than one of the fields of the record.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 185 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 12 +++ 2 files changed, 197 insertions(+)kernel-shark-qt/src/libkshark.c +11
-0@@ -888,6 +888,191 @@ static const char *kshark_get_info(struct tep_handle *pe,return seq.buffer; } +/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 911
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ;Perhaps this should return
-ENODEV;
Quoted 4 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 913
Quoted 2 lines
kernel-shark-qt/src/libkshark.c +2
-0+ +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) {What's the "
UNTOUCHED_MASK" mean?
We use the KS_PLUGIN_UNTOUCHED_MASK to check the flag (bit) which indicates if the entry has been touched and potential modified by a plugin callback function. If the bit is set this means untouched.
This flag (bit) gets set when we load the data ( libkshark.c / get_records())
entry->visible = 0xFF;
...
/* Execute all plugin-provided actions (if any). */
evt_handler = kshark_ctx->event_handlers;
while ((evt_handler = kshark_find_event_handler(evt_handler,
entry->event_id))) {
evt_handler->event_func(kshark_ctx, rec, entry);
evt_handler = evt_handler->next;
if (!evt_handler)
entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK;
}Quoted 3 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 915
Quoted 3 lines
kernel-shark-qt/src/libkshark.c +2
-0+ pid = entry->pid; + }else {
In this case the entry has been touched by a plugin. Because of this we do not trust the value of "entry->pid".
Quoted 18 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 918
Quoted 3 lines
kernel-shark-qt/src/libkshark.c +3
-0+ data =kshark_read_at (kshark_ctx, entry->offset); + pid =tep_data_pid (kshark_ctx->pevent, data); +free_record (data);Would it be possible to do:
entry->visible |= KS_PLUGIN_UNTOUCHED_MASK; entry->pid = pid;?
Of course this depends on what that mask means.
Quoted 5 lines
kernel-shark-qt/src/libkshark.c +5
-0+ } + +return pid; +} +
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Hi Steven,
I guess this email thread was lost on your side.
Is my explanation of the "UNTOUCHED_MASK" OK?
Should I send you v3 of the patches with the other fixes you asked for?
Quoted 101 lines · Yordan Karadzhov
Quoted 47 lines · Steven Rostedt
Quoted 31 lines · On Mon, 1 Oct 2018 16:59:17 +0300 Yordan Karadzhov <[email protected]>…
From: "Yordan Karadzhov (VMware)" <[email protected]>
The
kshark_get_X_easy()functions allow for an easy access to the tep_record's fields. Using these functions can be inefficient if you need access to more than one of the fields of the record.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 185 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 12 +++ 2 files changed, 197 insertions(+)kernel-shark-qt/src/libkshark.c +11
-0@@ -888,6 +888,191 @@ static const char *kshark_get_info(struct tep_handle *pe,return seq.buffer; } +/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 911
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ;Perhaps this should return
-ENODEV;Quoted 4 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 913
Quoted 2 lines
kernel-shark-qt/src/libkshark.c +2
-0+ +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) {What's the "
UNTOUCHED_MASK" mean?We use the
KS_PLUGIN_UNTOUCHED_MASKto check the flag (bit) which indicates if the entry has been touched and potential modified by a plugin callback function. If the bit is set this means untouched.This flag (bit) gets set when we load the data (
libkshark.c/get_records())entry->visible = 0xFF;...
/* Execute all plugin-provided actions (if any). */ evt_handler = kshark_ctx->event_handlers; while ((evt_handler = kshark_find_event_handler(evt_handler, entry->event_id))) { evt_handler->event_func(kshark_ctx, rec, entry); evt_handler = evt_handler->next; if (!evt_handler) entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK; }Quoted 3 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 915
Quoted 3 lines
kernel-shark-qt/src/libkshark.c +2
-0+ pid = entry->pid; + }else {In this case the entry has been touched by a plugin. Because of this we do not trust the value of "
entry->pid".Quoted 18 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 918
Quoted 3 lines
kernel-shark-qt/src/libkshark.c +3
-0+ data =kshark_read_at (kshark_ctx, entry->offset); + pid =tep_data_pid (kshark_ctx->pevent, data); +free_record (data);Would it be possible to do:
entry->visible |= KS_PLUGIN_UNTOUCHED_MASK; entry->pid = pid;?
Of course this depends on what that mask means.
Quoted 5 lines
kernel-shark-qt/src/libkshark.c +5
-0+ } + +return pid; +} +
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Quoted 3 lines · On Fri, 5 Oct 2018 17:30:17 +0300 "Yordan Karadzhov (VMware)"…
Hi Steven,
I guess this email thread was lost on your side.
Not lost, just forgotten about ;-)
Quoted 87 lines
Is my explanation of the "
UNTOUCHED_MASK" OK?
Should I send you v3 of the patches with the other fixes you asked for?Quoted 82 lines · Yordan Karadzhov
Quoted 47 lines · Steven Rostedt
Quoted 31 lines · On Mon, 1 Oct 2018 16:59:17 +0300 Yordan Karadzhov <[email protected]>…
From: "Yordan Karadzhov (VMware)" <[email protected]>
The
kshark_get_X_easy()functions allow for an easy access to the tep_record's fields. Using these functions can be inefficient if you need access to more than one of the fields of the record.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 185 ++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 12 +++ 2 files changed, 197 insertions(+)kernel-shark-qt/src/libkshark.c +11
-0@@ -888,6 +888,191 @@ static const char *kshark_get_info(struct tep_handle *pe,return seq.buffer; } +/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 911
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ;Perhaps this should return
-ENODEV;Quoted 4 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 913
Quoted 2 lines
kernel-shark-qt/src/libkshark.c +2
-0+ +if (entry->visible &KS_PLUGIN_UNTOUCHED_MASK ) {What's the "
UNTOUCHED_MASK" mean?We use the
KS_PLUGIN_UNTOUCHED_MASKto check the flag (bit) which indicates if the entry has been touched and potential modified by a plugin callback function. If the bit is set this means untouched.This flag (bit) gets set when we load the data (
libkshark.c/get_records())entry->visible = 0xFF;...
/* Execute all plugin-provided actions (if any). */ evt_handler = kshark_ctx->event_handlers; while ((evt_handler = kshark_find_event_handler(evt_handler, entry->event_id))) { evt_handler->event_func(kshark_ctx, rec, entry); evt_handler = evt_handler->next; if (!evt_handler) entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK; }Quoted 3 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 915
Quoted 3 lines
kernel-shark-qt/src/libkshark.c +2
-0+ pid = entry->pid; + }else {In this case the entry has been touched by a plugin. Because of this we do not trust the value of "
entry->pid".
I guess my question is, can we reset the entry->pid back to something we do trust, and clear the flag?
Or do we not want to modify it, because the plugin now owns the value?
-- Steve
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 918
Quoted 4 lines
kernel-shark-qt/src/libkshark.c +3
-0+ data =kshark_read_at (kshark_ctx, entry->offset); + pid =tep_data_pid (kshark_ctx->pevent, data); +free_record (data);Would it be possible to do:
entry->visible |= KS_PLUGIN_UNTOUCHED_MASK; entry->pid = pid;?
Of course this depends on what that mask means.
Quoted 5 lines
kernel-shark-qt/src/libkshark.c +5
-0+ } + +return pid; +} +
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Quoted 48 lines · Steven Rostedt
Quoted 48 lines
Quoted 48 lines
Quoted 23 lines
Quoted 11 lines
kernel-shark-qt/src/libkshark.c +11
-0+/** +* @brief This function allows for an easy access to the original value of the +* Process Id as recorded in the tep_record object. The record is read +* from the file only in the case of an entry being touched by a plugin. +* Be aware that using the kshark_get_X_easy functions can be +* inefficient if you need an access to more than one of the data fields +* of the record. +* +* @param entry: Input location for the KernelShark entry. +* +* @returns The original value of the Process Id as recorded in the kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 911
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* tep_record object on success, otherwise negative error code. +*/ +int kshark_get_pid_easy (struct kshark_entry *entry) +{ +struct kshark_context *kshark_ctx =NULL ; +struct tep_record *data; +int pid; + +if (!kshark_instance (&kshark_ctx)) +return -EFAULT ;Perhaps this should return
-ENODEV;Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (entry->visible & KS_PLUGIN_UNTOUCHED_MASK) {What's the "
UNTOUCHED_MASK" mean?We use the
KS_PLUGIN_UNTOUCHED_MASKto check the flag (bit) which indicates if the entry has been touched and potential modified by a plugin callback function. If the bit is set this means untouched.This flag (bit) gets set when we load the data (
libkshark.c/get_records())entry->visible = 0xFF;...
/* Execute all plugin-provided actions (if any). */ evt_handler = kshark_ctx->event_handlers; while ((evt_handler = kshark_find_event_handler(evt_handler, entry->event_id))) { evt_handler->event_func(kshark_ctx, rec, entry); evt_handler = evt_handler->next; if (!evt_handler) entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK; }Quoted 1 line
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
kernel-shark-qt/src/libkshark.c static const char *kshark_get_info(struct tep_handle *pe, · line 915
Quoted 2 lines
kernel-shark-qt/src/libkshark.c +2
-0+ pid = entry->pid; + }else {In this case the entry has been touched by a plugin. Because of this we do not trust the value of "
entry->pid".I guess my question is, can we reset the
entry->pidback to something we do trust, and clear the flag?Or do we not want to modify it, because the plugin now owns the value?
If the value of "entry->pid" has been changed then the new value will be used when plotting graphs and we do not want to change this. However, we still want to be able to retrieve the original value. The description of the function explains that it will return the original value.
Thanks!
Yordan
Quoted 2 lines
-- Steve
Re: [PATCH v2 1/5] kernel-shark-qt: Add kshark_get_X_easy() functions.
Quoted 4 lines · On Fri, 5 Oct 2018 18:27:20 +0300 "Yordan Karadzhov (VMware)"…
If the value of "
entry->pid" has been changed then the new value will be used when plotting graphs and we do not want to change this. However, we still want to be able to retrieve the original value. The description of the function explains that it will return the original value.
Right. I wanted to figure out why we have two values for pid?
OK, just clarifying what was the intent.
Please send v3 with the other updates.
Thanks!
-- Steve
PATCH v2 2/5 kernel-shark-qt: Add kshark_convert_nano() function
In reply to Yordan KaradzhovFrom: "Yordan Karadzhov (VMware)" <[email protected]>
kshark_convert_nano() is used to convert the original value of the timestamp of the trace records (having nanosecond precision) into two values representing the time in seconds and milliseconds.
--- kernel-shark-qt/src/libkshark.c | 14 ++++++++++++++ kernel-shark-qt/src/libkshark.h | 2 ++ 2 files changed, 16 insertions(+)
kernel-shark-qt/src/libkshark.c +14 -0
@@ -1073,6 +1073,20 @@ const char *kshark_get_info_easy(struct kshark_entry *entry)return info; } +/** +* @brief Convert the timestamp of the trace record (nanosecond precision) into +* seconds and microseconds. +* +* @param time: Input location for the timestamp. +* @param sec: Output location for the value of the seconds. +* @param usec: Output location for the value of the microseconds. +*/ +void kshark_convert_nano (uint64_t time,uint64_t *sec,uint64_t *usec) +{ + *sec = time /1000000000ULL ; + *usec = (time /1000 ) %1000000 ; +} +/** * @brief Dump into a string the content of one entry. The function allocates * a null terminated string and returns a pointer to this string. The
kernel-shark-qt/src/libkshark.h +2 -0
@@ -160,6 +160,8 @@ const char *kshark_get_event_name_easy(struct kshark_entry *entry);const char *kshark_get_info_easy (struct kshark_entry *entry); +void kshark_convert_nano (uint64_t time,uint64_t *sec,uint64_t *usec); +char *kshark_dump_entry (const struct kshark_entry *entry); struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx,
Signature · 1 line
2.17.1
Re: [PATCH v2 2/5] kernel-shark-qt: Add kshark_convert_nano() function
Quoted 22 lines · On Mon, 1 Oct 2018 16:59:18 +0300 Yordan Karadzhov <[email protected]>…
From: "Yordan Karadzhov (VMware)" <[email protected]>
kshark_convert_nano()is used to convert the original value of the timestamp of the trace records (having nanosecond precision) into two values representing the time in seconds and milliseconds.Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 14 ++++++++++++++ kernel-shark-qt/src/libkshark.h | 2 ++ 2 files changed, 16 insertions(+)kernel-shark-qt/src/libkshark.c +2
-0@@ -1073,6 +1073,20 @@ const char *kshark_get_info_easy(struct kshark_entry *entry)return info; } +/** +* @brief Convert the timestamp of the trace record (nanosecond precision) into
kernel-shark-qt/src/libkshark.c const char *kshark_get_info_easy(struct kshark_entry *entry) · line 1087
Quoted 10 lines
kernel-shark-qt/src/libkshark.c +10
-0+* seconds and microseconds. +* +* @param time: Input location for the timestamp. +* @param sec: Output location for the value of the seconds. +* @param usec: Output location for the value of the microseconds. +*/ +void kshark_convert_nano (uint64_t time,uint64_t *sec,uint64_t *usec) +{ + *sec = time /1000000000ULL ; + *usec = (time /1000 ) %1000000 ;
BTW, just a little optimization, as '%' and '/' are very expensive operations, you can remove one by this:
{
uint64_t s;
s = time / 1000000000ULL;
*sec = s;
*usec = (time - s * 1000000000ULL) / 1000;As '-' and '*' are fast operations.
-- Steve
Quoted 18 lines
kernel-shark-qt/src/libkshark.c +2
-0+} +/** * @brief Dump into a string the content of one entry. The function allocates * a null terminated string and returns a pointer to this string. The kernel-shark-qt/src/libkshark.h +2
-0@@ -160,6 +160,8 @@ const char *kshark_get_event_name_easy(struct kshark_entry *entry);const char *kshark_get_info_easy (struct kshark_entry *entry); +void kshark_convert_nano (uint64_t time,uint64_t *sec,uint64_t *usec); +char *kshark_dump_entry (const struct kshark_entry *entry); struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx,
PATCH v2 3/5 kernel-shark-qt: Add functions for fast clearing of the filters.
In reply to Yordan KaradzhovFrom: "Yordan Karadzhov (VMware)" <[email protected]>
The first added function checks if any Id filter is set.
The second added function is used to reset the "visible" field of each entry to the default value of "0xFF" (visible everywhere).
--- kernel-shark-qt/src/libkshark.c | 28 +++++++++++++++++++++++++++- kernel-shark-qt/src/libkshark.h | 6 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-)
kernel-shark-qt/src/libkshark.c +27 -1
@@ -427,7 +427,14 @@ static bool filter_is_set(struct tracecmd_filter_id *filter)return filter && filter->count; } -static bool kshark_filter_is_set (struct kshark_context *kshark_ctx) +/** +* @brief Check if an Id filter is set. +* +* @param kshark_ctx: Input location for the session context pointer. +* +* @returns True if at least one Id filter is set, otherwise False. +*/ +bool kshark_filter_is_set (struct kshark_context *kshark_ctx) {return filter_is_set (kshark_ctx->show_task_filter) || filter_is_set(kshark_ctx->hide_task_filter) ||
@@ -499,6 +506,25 @@ void kshark_filter_entries(struct kshark_context *kshark_ctx, } } +/** +* @brief This function loops over the array of entries specified by "data" +* and "n_entries" and resets the "visible" fields of each entry to +* the default value of "0xFF" (visible everywhere). +* +* @param kshark_ctx: Input location for the session context pointer. +* @param data: Input location for the trace data to be unfiltered. +* @param n_entries: The size of the inputted data. +*/ +void kshark_clear_all_filters (struct kshark_context *kshark_ctx, +struct kshark_entry **data, +size_t n_entries) +{ +int i; + +for (i =0 ; i < n_entries; ++i) + data[i]->visible =0xFF ; +} +static void kshark_set_entry_values (struct kshark_context *kshark_ctx,struct tep_record *record,struct kshark_entry *entry)
kernel-shark-qt/src/libkshark.h +6 -0
@@ -226,10 +226,16 @@ void kshark_filter_add_id(struct kshark_context *kshark_ctx,void kshark_filter_clear (struct kshark_context *kshark_ctx,int filter_id); +bool kshark_filter_is_set (struct kshark_context *kshark_ctx); +void kshark_filter_entries (struct kshark_context *kshark_ctx,struct kshark_entry **data,size_t n_entries); +void kshark_clear_all_filters (struct kshark_context *kshark_ctx, +struct kshark_entry **data, +size_t n_entries); +/** Search failed identifiers. */ enum kshark_search_failed {/** All entries have timestamps greater timestamps. */
Signature · 1 line
2.17.1
PATCH v2 4/5 kernel-shark-qt: Rename the Cmake-generated header file.
In reply to Yordan KaradzhovFrom: "Yordan Karadzhov (VMware)" <[email protected]>
The name of the Cmake-generated header file is changed for "KsDeff.h" to "KsCmakeDef.hpp" in order to make it more explanatory. With the following patches the file will start contain C++ declarations.
--- kernel-shark-qt/build/cmake_clean.sh | 2 +- kernel-shark-qt/build/deff.h.cmake | 2 +- kernel-shark-qt/src/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
kernel-shark-qt/build/cmake_clean.sh +1 -1
@@ -6,6 +6,6 @@ rm -rf CMakeFiles/ rm -rf src/ rm -rf examples/ rm -f ../lib/* -rm -f ../src/KsDeff.h +rm -f ../src/KsCmakeDef.hpp rm -f CMakeDoxyfile.in rm -f CMakeDoxygenDefaults.cmake
kernel-shark-qt/build/deff.h.cmake +1 -1
@@ -1,5 +1,5 @@ /** - * \file KsDeff.h + * \file KsCmakeDef.hpp * \brief This File is generated by CMAKE */
kernel-shark-qt/src/CMakeLists.txt +1 -1
@@ -31,4 +31,4 @@ endif (OPENGL_FOUND AND GLUT_FOUND) add_subdirectory(plugins) configure_file( ${KS_DIR}/build/deff.h.cmake - ${KS_DIR}/src/KsDeff.h) + ${KS_DIR}/src/KsCmakeDef.hpp)
Signature · 1 line
2.17.1
PATCH v2 5/5 kernel-shark-qt: Fix a bug in kshark_data_collection_alloc()
In reply to Yordan KaradzhovThe margin data added at the end of the data interval of the collection may actually include the beginning of another interval. Because of this we have to iterate over the margin data and check for "good" entries. In the case of a "good" entry being found, we have to continue extending the last interval.
--- kernel-shark-qt/src/libkshark-collection.c | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-)
kernel-shark-qt/src/libkshark-collection.c +18 -8
@@ -157,14 +157,24 @@ kshark_data_collection_alloc(struct kshark_context *kshark_ctx,* number of margin entries requested, keep adding * until you fill the margin. */ -if (i + margin < j) - i = j; -else - i += margin; - - last_added = i; -collection_add_entry (&temp, i,COLLECTION_BREAK ); - ++break_count; +if (i + margin >= j) { +for (;j < i + margin; ++j) { +if (cond (kshark_ctx, data[j], val)) { +/* Good data has been found. +* Continue extending the +* previous data interval. +*/ + good_data = true; +break ; + } + } + } + + last_added = i = j; +if (!good_data) { +collection_add_entry (&temp, i,COLLECTION_BREAK ); + ++break_count; + } } }
Signature · 1 line
2.17.1
Re: [PATCH v2 5/5] kernel-shark-qt: Fix a bug in kshark_data_collection_alloc()
Quoted 21 lines · On Mon, 1 Oct 2018 16:59:21 +0300 Yordan Karadzhov <[email protected]>…
The margin data added at the end of the data interval of the collection may actually include the beginning of another interval. Because of this we have to iterate over the margin data and check for "good" entries. In the case of a "good" entry being found, we have to continue extending the last interval.
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark-qt/src/libkshark-collection.c | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-)kernel-shark-qt/src/libkshark-collection.c +0
-2@@ -157,14 +157,24 @@ kshark_data_collection_alloc(struct kshark_context *kshark_ctx,* number of margin entries requested, keep adding * until you fill the margin. */ -if (i + margin < j) - i = j;
kernel-shark-qt/src/libkshark-collection.c kshark_data_collection_alloc(struct kshark_context *kshark_ctx, · line 163
Quoted 10 lines
kernel-shark-qt/src/libkshark-collection.c +4
-6-else - i += margin; - - last_added = i; -collection_add_entry (&temp, i,COLLECTION_BREAK ); - ++break_count; +if (i + margin >= j) { +for (;j < i + margin; ++j) { +if (cond (kshark_ctx, data[j], val)) { +/* Good data has been found.
Nit, but have comments of the format:
/* * Good data has been found
kernel-shark-qt/src/libkshark-collection.c kshark_data_collection_alloc(struct kshark_context *kshark_ctx, · line 166
Quoted 3 lines
kernel-shark-qt/src/libkshark-collection.c +3
-0+* Continue extending the +* previous data interval. +*/
Note, the Networking folks like the way you did it here, but the rest of the Linux maintainers find it funny ;-)
-- Steve
Quoted 14 lines
kernel-shark-qt/src/libkshark-collection.c +11
-0+ good_data = true; +break ; + } + } + } + + last_added = i = j; +if (!good_data) { +collection_add_entry (&temp, i,COLLECTION_BREAK ); + ++break_count; + } } }