From patchwork Wed Nov 28 15:16:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10760041 Return-Path: Received: from mail-eopbgr710075.outbound.protection.outlook.com ([40.107.71.75]:2944 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728732AbeK2CSe (ORCPT ); Wed, 28 Nov 2018 21:18:34 -0500 From: Yordan Karadzhov To: "rostedt@goodmis.org" CC: "linux-trace-devel@vger.kernel.org" Subject: [PATCH 12/17] kernel-shark-qt: Add CPU-based filtering to the C API Date: Wed, 28 Nov 2018 15:16:22 +0000 Message-ID: <20181128151530.21965-13-ykaradzhov@vmware.com> References: <20181128151530.21965-1-ykaradzhov@vmware.com> In-Reply-To: <20181128151530.21965-1-ykaradzhov@vmware.com> Content-Language: en-US MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org List-ID: Content-Length: 5612 This patch adds "Show CPU" and "Hide CPU" filters to the C API of KernelShark. The implementation of those filters follows the pattern used to implement the Task (pid) and Event filters. Signed-off-by: Yordan Karadzhov --- kernel-shark-qt/src/libkshark.c | 37 +++++++++++++++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 17 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/kernel-shark-qt/src/libkshark.c b/kernel-shark-qt/src/libkshark.c index b4b3d5b..86d3e58 100644 --- a/kernel-shark-qt/src/libkshark.c +++ b/kernel-shark-qt/src/libkshark.c @@ -41,6 +41,9 @@ static bool kshark_default_context(struct kshark_context **context) kshark_ctx->show_event_filter = tracecmd_filter_id_hash_alloc(); kshark_ctx->hide_event_filter = tracecmd_filter_id_hash_alloc(); + kshark_ctx->show_cpu_filter = tracecmd_filter_id_hash_alloc(); + kshark_ctx->hide_cpu_filter = tracecmd_filter_id_hash_alloc(); + kshark_ctx->filter_mask = 0x0; /* Will free kshark_context_handler. */ @@ -180,6 +183,8 @@ void kshark_close(struct kshark_context *kshark_ctx) tracecmd_filter_id_clear(kshark_ctx->hide_task_filter); tracecmd_filter_id_clear(kshark_ctx->show_event_filter); tracecmd_filter_id_clear(kshark_ctx->hide_event_filter); + tracecmd_filter_id_clear(kshark_ctx->show_cpu_filter); + tracecmd_filter_id_clear(kshark_ctx->hide_cpu_filter); if (kshark_ctx->advanced_event_filter) { tep_filter_reset(kshark_ctx->advanced_event_filter); @@ -226,6 +231,9 @@ void kshark_free(struct kshark_context *kshark_ctx) tracecmd_filter_id_hash_free(kshark_ctx->show_event_filter); tracecmd_filter_id_hash_free(kshark_ctx->hide_event_filter); + tracecmd_filter_id_hash_free(kshark_ctx->show_cpu_filter); + tracecmd_filter_id_hash_free(kshark_ctx->hide_cpu_filter); + if (kshark_ctx->plugins) { kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_CLOSE); kshark_free_plugin_list(kshark_ctx->plugins); @@ -366,6 +374,12 @@ static bool kshark_show_event(struct kshark_context *kshark_ctx, int pid) filter_find(kshark_ctx->hide_event_filter, pid, false); } +static bool kshark_show_cpu(struct kshark_context *kshark_ctx, int cpu) +{ + return filter_find(kshark_ctx->show_cpu_filter, cpu, true) && + filter_find(kshark_ctx->hide_cpu_filter, cpu, false); +} + /** * @brief Add an Id value to the filster specified by "filter_id". * @@ -379,6 +393,12 @@ void kshark_filter_add_id(struct kshark_context *kshark_ctx, struct tracecmd_filter_id *filter; switch (filter_id) { + case KS_SHOW_CPU_FILTER: + filter = kshark_ctx->show_cpu_filter; + break; + case KS_HIDE_CPU_FILTER: + filter = kshark_ctx->hide_cpu_filter; + break; case KS_SHOW_EVENT_FILTER: filter = kshark_ctx->show_event_filter; break; @@ -409,6 +429,12 @@ void kshark_filter_clear(struct kshark_context *kshark_ctx, int filter_id) struct tracecmd_filter_id *filter; switch (filter_id) { + case KS_SHOW_CPU_FILTER: + filter = kshark_ctx->show_cpu_filter; + break; + case KS_HIDE_CPU_FILTER: + filter = kshark_ctx->hide_cpu_filter; + break; case KS_SHOW_EVENT_FILTER: filter = kshark_ctx->show_event_filter; break; @@ -444,6 +470,8 @@ 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); } @@ -505,6 +533,10 @@ void kshark_filter_entries(struct kshark_context *kshark_ctx, if (!kshark_show_event(kshark_ctx, data[i]->event_id)) unset_event_filter_flag(kshark_ctx, data[i]); + /* Apply CPU filtering. */ + if (!kshark_show_cpu(kshark_ctx, data[i]->cpu)) + data[i]->visible &= ~kshark_ctx->filter_mask; + /* Apply task filtering. */ if (!kshark_show_task(kshark_ctx, data[i]->pid)) data[i]->visible &= ~kshark_ctx->filter_mask; @@ -732,6 +764,11 @@ static size_t get_records(struct kshark_context *kshark_ctx, unset_event_filter_flag(kshark_ctx, entry); } + /* Apply CPU filtering. */ + if (!kshark_show_cpu(kshark_ctx, entry->pid)) { + entry->visible &= ~kshark_ctx->filter_mask; + } + /* Apply task filtering. */ if (!kshark_show_task(kshark_ctx, entry->pid)) { entry->visible &= ~kshark_ctx->filter_mask; diff --git a/kernel-shark-qt/src/libkshark.h b/kernel-shark-qt/src/libkshark.h index b94bdc3..eb8c261 100644 --- a/kernel-shark-qt/src/libkshark.h +++ b/kernel-shark-qt/src/libkshark.h @@ -110,6 +110,12 @@ struct kshark_context { /** Hash of events to not display. */ struct tracecmd_filter_id *hide_event_filter; + /** Hash of CPUs to filter on. */ + struct tracecmd_filter_id *show_cpu_filter; + + /** Hash of CPUs to not display. */ + struct tracecmd_filter_id *hide_cpu_filter; + /** * Bit mask, controlling the visibility of the entries after filtering. * If given bit is set here, all entries which are filtered-out will @@ -232,6 +238,17 @@ enum kshark_filter_type { * filtered-out. */ KS_HIDE_TASK_FILTER, + + /** + * Identifier of the filter, used to specified the CPUs to be shown. + */ + KS_SHOW_CPU_FILTER, + + /** + * Identifier of the filter, used to specified the CPUs to be + * filtered-out. + */ + KS_HIDE_CPU_FILTER, }; void kshark_filter_add_id(struct kshark_context *kshark_ctx,