The method is already defined and used as a static function in libkshark.c and libkshark-configio.c (basically having two identical copies). Now we are making this method part of the API. We will later use this method in the GUI (following patch). Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- kernel-shark/src/libkshark-configio.c | 17 ++++++----------- kernel-shark/src/libkshark.c | 21 ++++++++++++++------- kernel-shark/src/libkshark.h | 2 ++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/kernel-shark/src/libkshark-configio.c b/kernel-shark/src/libkshark-configio.c index 5d7323f..f01a39b 100644 --- a/kernel-shark/src/libkshark-configio.c +++ b/kernel-shark/src/libkshark-configio.c @@ -1306,11 +1306,6 @@ bool kshark_import_user_mask(struct kshark_context *kshark_ctx, } } -static bool filter_is_set(struct tracecmd_filter_id *filter) -{ - return filter && filter->count; -} - /** * @brief Record the current configuration of "show task" and "hide task" * filters into a Json document. @@ -1335,13 +1330,13 @@ bool kshark_export_all_event_filters(struct kshark_context *kshark_ctx, return false; /* Save a filter only if it contains Id values. */ - if (filter_is_set(kshark_ctx->show_event_filter)) + if (kshark_this_filter_is_set(kshark_ctx->show_event_filter)) ret &= kshark_export_event_filter(kshark_ctx->pevent, kshark_ctx->show_event_filter, KS_SHOW_EVENT_FILTER_NAME, *conf); - if (filter_is_set(kshark_ctx->hide_event_filter)) + if (kshark_this_filter_is_set(kshark_ctx->hide_event_filter)) ret &= kshark_export_event_filter(kshark_ctx->pevent, kshark_ctx->hide_event_filter, KS_HIDE_EVENT_FILTER_NAME, @@ -1374,12 +1369,12 @@ bool kshark_export_all_task_filters(struct kshark_context *kshark_ctx, return false; /* Save a filter only if it contains Id values. */ - if (filter_is_set(kshark_ctx->show_task_filter)) + if (kshark_this_filter_is_set(kshark_ctx->show_task_filter)) ret &= kshark_export_filter_array(kshark_ctx->show_task_filter, KS_SHOW_TASK_FILTER_NAME, *conf); - if (filter_is_set(kshark_ctx->hide_task_filter)) + if (kshark_this_filter_is_set(kshark_ctx->hide_task_filter)) ret &= kshark_export_filter_array(kshark_ctx->hide_task_filter, KS_HIDE_TASK_FILTER_NAME, *conf); @@ -1412,12 +1407,12 @@ bool kshark_export_all_cpu_filters(struct kshark_context *kshark_ctx, return false; /* Save a filter only if it contains Id values. */ - if (filter_is_set(kshark_ctx->show_task_filter)) + if (kshark_this_filter_is_set(kshark_ctx->show_task_filter)) ret &= kshark_export_filter_array(kshark_ctx->show_cpu_filter, KS_SHOW_CPU_FILTER_NAME, *conf); - if (filter_is_set(kshark_ctx->hide_task_filter)) + if (kshark_this_filter_is_set(kshark_ctx->hide_task_filter)) ret &= kshark_export_filter_array(kshark_ctx->hide_cpu_filter, KS_HIDE_CPU_FILTER_NAME, *conf); diff --git a/kernel-shark/src/libkshark.c b/kernel-shark/src/libkshark.c index a361578..0905359 100644 --- a/kernel-shark/src/libkshark.c +++ b/kernel-shark/src/libkshark.c @@ -445,7 +445,14 @@ void kshark_filter_clear(struct kshark_context *kshark_ctx, int filter_id) tracecmd_filter_id_clear(filter); } -static bool filter_is_set(struct tracecmd_filter_id *filter) +/** + * @brief Check if a given Id filter is set. + * + * @param filter: Input location for the Id filster. + * + * @returns True if the Id filter is set, otherwise False. + */ +bool kshark_this_filter_is_set(struct tracecmd_filter_id *filter) { return filter && filter->count; } @@ -459,12 +466,12 @@ static bool filter_is_set(struct tracecmd_filter_id *filter) */ 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) || - filter_is_set(kshark_ctx->show_cpu_filter) || - filter_is_set(kshark_ctx->hide_cpu_filter) || - filter_is_set(kshark_ctx->show_event_filter) || - filter_is_set(kshark_ctx->hide_event_filter); + return kshark_this_filter_is_set(kshark_ctx->show_task_filter) || +- kshark_this_filter_is_set(kshark_ctx->hide_task_filter) || +- kshark_this_filter_is_set(kshark_ctx->show_cpu_filter) || +- kshark_this_filter_is_set(kshark_ctx->hide_cpu_filter) || +- kshark_this_filter_is_set(kshark_ctx->show_event_filter) || +- kshark_this_filter_is_set(kshark_ctx->hide_event_filter); } static inline void unset_event_filter_flag(struct kshark_context *kshark_ctx, diff --git a/kernel-shark/src/libkshark.h b/kernel-shark/src/libkshark.h index e795ed4..0d6c50d 100644 --- a/kernel-shark/src/libkshark.h +++ b/kernel-shark/src/libkshark.h @@ -261,6 +261,8 @@ void kshark_filter_add_id(struct kshark_context *kshark_ctx, void kshark_filter_clear(struct kshark_context *kshark_ctx, int filter_id); +bool kshark_this_filter_is_set(struct tracecmd_filter_id *filter); + bool kshark_filter_is_set(struct kshark_context *kshark_ctx); void kshark_filter_entries(struct kshark_context *kshark_ctx, -- 2.20.1