From patchwork Thu Feb 11 10:31:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12082749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AFA7C433E6 for ; Thu, 11 Feb 2021 10:39:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0761D64E9A for ; Thu, 11 Feb 2021 10:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230311AbhBKKit (ORCPT ); Thu, 11 Feb 2021 05:38:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbhBKKfs (ORCPT ); Thu, 11 Feb 2021 05:35:48 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7C4C061221 for ; Thu, 11 Feb 2021 02:32:41 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id v7so6371367eds.10 for ; Thu, 11 Feb 2021 02:32:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0qe5EANYiV0g2mhPh7z4awjgB9+F2mKtrWrK20/JraI=; b=gRGhi3QQ+XCH9yJ5EJguGq3sF4G45sgTrRgLhi52nL17I1mGDgNlOqnO/YjqfQ3Omt Ro5OrbHKioPBDfVPkkA7beqf7XHhw/HBWHCOgNG4zXeuHutc+bcXABLpjZU+71+cW2Uo gKLgIzZ25ertKSp0RhSp8v/ZKeV8i+IOxKaa58NC9nf8lDxa09zFSdsuIBJzzvVkUbmP 3Exz1a2z4fIkuAbUXbFXe+Zvowqgl/tAULGm52xg53jDAiPDEaK+I6lim2U8GUNE7zfQ E5pykEbGLlWlGqEwsQ/p96VBy7QV4NONxRbFDLHBdBgn0aZRVdm3MOguaz9TbuatCuWk a1Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0qe5EANYiV0g2mhPh7z4awjgB9+F2mKtrWrK20/JraI=; b=DG/5kz7mr16Sd/zMQl+SU2ewhtA6QZA/gdYi84XmAmrC7UmHw8LWwZLzMw4MI3fC1s Oi2G3tIohu7108JKzN2OGAqGzTu6yQu2BhYVAI6km2f9A4+Lv8M+qiJFSHvKk7y/wGe/ 4oohVGHF33oJAdlVfmRrJJAmnskc2SAbCUFg+2E3ewQS7AGqkOM0sefHB0JRcEP+Smud JMCyyZygR/Le4bWXIdxsZ6/rN7xK/ideC1HG4KhNe1/IYaulJrOVA25VS3XqF5d/EEaL EAW23dsF0PKxYe94wvT/32fJsisU2Ksg7oCEc8wi81Ral1aGuJhZSFwkuHxkEE4cofE6 wUWw== X-Gm-Message-State: AOAM532hh3zbZ9xDdZq+ag++pMP6DR56aserT3gTQmb+6t57ffBGaJG2 L4WOeSxX4faZm9hDChqp7Rg= X-Google-Smtp-Source: ABdhPJzVDEBwrAs8swYHH3Fkbm4p6mHkXDg44I2nFWIyjcRXA0tfZWtG2klyeh9/Asxi+CGfJ00irQ== X-Received: by 2002:aa7:de82:: with SMTP id j2mr7731059edv.313.1613039559955; Thu, 11 Feb 2021 02:32:39 -0800 (PST) Received: from localhost.localdomain (212-39-89-223.ip.btc-net.bg. [212.39.89.223]) by smtp.gmail.com with ESMTPSA id bd27sm3514031edb.37.2021.02.11.02.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 02:32:39 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 19/27] kernel-shark: Update KsAdvFilteringDialog Date: Thu, 11 Feb 2021 12:31:57 +0200 Message-Id: <20210211103205.418588-20-y.karadz@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211103205.418588-1-y.karadz@gmail.com> References: <20210211103205.418588-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The compilation ofKsAdvFilteringDialog .cpp is re-enabled and all functionalities are made compatible with the new version of the C API of libkshark (KernelShark 2.0). Signed-off-by: Yordan Karadzhov (VMware) --- src/CMakeLists.txt | 8 +- src/KsAdvFilteringDialog.cpp | 200 ++++++++++++++++++++++------------- src/KsAdvFilteringDialog.hpp | 16 ++- 3 files changed, 144 insertions(+), 80 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e09deb7..6bb94d6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,8 +76,8 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND AND TT_FONT_FILE) KsTraceViewer.hpp # KsMainWindow.hpp # KsCaptureDialog.hpp - KsQuickContextMenu.hpp) -# KsAdvFilteringDialog.hpp) + KsQuickContextMenu.hpp + KsAdvFilteringDialog.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr}) @@ -92,8 +92,8 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND AND TT_FONT_FILE) KsTraceViewer.cpp # KsMainWindow.cpp # KsCaptureDialog.cpp - KsQuickContextMenu.cpp) -# KsAdvFilteringDialog.cpp) + KsQuickContextMenu.cpp + KsAdvFilteringDialog.cpp) target_link_libraries(kshark-gui kshark-plot Qt5::Widgets diff --git a/src/KsAdvFilteringDialog.cpp b/src/KsAdvFilteringDialog.cpp index 8dc53bb..2fdb624 100644 --- a/src/KsAdvFilteringDialog.cpp +++ b/src/KsAdvFilteringDialog.cpp @@ -9,10 +9,16 @@ * @brief GUI Dialog for Advanced filtering settings. */ +// trace-cmd +#include "trace-cmd/trace-cmd.h" + // KernelShark -#include "KsAdvFilteringDialog.hpp" #include "libkshark.h" +#include "libkshark-tepdata.h" #include "KsUtils.hpp" +#include "KsAdvFilteringDialog.hpp" + +using namespace KsWidgetsLib; /** Create dialog for Advanced Filtering. */ KsAdvFilteringDialog::KsAdvFilteringDialog(QWidget *parent) @@ -71,6 +77,9 @@ KsAdvFilteringDialog::KsAdvFilteringDialog(QWidget *parent) lamAddLine(); + _topLayout.addWidget(&_streamComboBox); + _getFtraceStreams(kshark_ctx); + _getFilters(kshark_ctx); if (_filters.count()) { @@ -149,23 +158,38 @@ KsAdvFilteringDialog::KsAdvFilteringDialog(QWidget *parent) this, &QWidget::close); } -void KsAdvFilteringDialog::_setSystemCombo(struct kshark_context *kshark_ctx) +kshark_data_stream * +KsAdvFilteringDialog::_getCurrentStream(kshark_context *kshark_ctx) { + int sd = _streamComboBox.currentData().toInt(); + + return kshark_get_data_stream(kshark_ctx, sd); +} + +void KsAdvFilteringDialog::_setSystemCombo(kshark_context *kshark_ctx) +{ + kshark_data_stream *stream; + QVector eventIds; QStringList sysList; - tep_event **events; - int i(0), nEvts(0); + int i(0); - if (kshark_ctx->pevent) { - nEvts = tep_get_events_count(kshark_ctx->pevent); - events = tep_list_events(kshark_ctx->pevent, - TEP_EVENT_SORT_SYSTEM); - } + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return; + + eventIds = KsUtils::getEventIdList(stream->stream_id); + + auto lamGetSysName = [&stream] (int eventId) { + QStringList name = KsUtils::getTepEvtName(stream->stream_id, + eventId); + return name[0]; + }; - while (i < nEvts) { - QString sysName(events[i]->system); + while (i < stream->n_events) { + QString sysName = lamGetSysName(eventIds[i]); sysList << sysName; - while (sysName == events[i]->system) { - if (++i == nEvts) + while (sysName == lamGetSysName(eventIds[i])) { + if (++i == stream->n_events) break; } } @@ -202,24 +226,48 @@ QStringList KsAdvFilteringDialog::_operators() return OpsList; } -void KsAdvFilteringDialog::_getFilters(struct kshark_context *kshark_ctx) +void KsAdvFilteringDialog::_getFtraceStreams(kshark_context *kshark_ctx) { - tep_event **events; - char *str; + kshark_data_stream *stream; + QVector streamIds; + + _streamComboBox.clear(); + streamIds = KsUtils::getStreamIdList(kshark_ctx); + for (auto const &sd: streamIds) { + stream = kshark_ctx->stream[sd]; + if (kshark_is_tep(stream)) + _streamComboBox.addItem(KsUtils::streamDescription(stream), sd); + } - events = tep_list_events(kshark_ctx->pevent, TEP_EVENT_SORT_SYSTEM); + if (!_streamComboBox.count()) + _streamComboBox.addItem("No FTRACE data loaded", -1); +} - for (int i = 0; events[i]; i++) { - str = tep_filter_make_string(kshark_ctx->advanced_event_filter, - events[i]->id); - if (!str) +void KsAdvFilteringDialog::_getFilters(kshark_context *kshark_ctx) +{ + kshark_data_stream *stream; + QVector eventIds; + QStringList eventName; + char *filterStr; + + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return; + + eventIds = KsUtils::getEventIdList(stream->stream_id); + for (int i = 0; i < stream->n_events; ++i) { + eventName = KsUtils::getTepEvtName(stream->stream_id, eventIds[i]); + filterStr = kshark_tep_filter_make_string(stream, eventIds[i]); + if (!filterStr) continue; - _filters.insert(events[i]->id, - QString("%1/%2:%3").arg(events[i]->system, - events[i]->name, str)); + _filters.insert(eventIds[i], + QString("%1:%2/%3:%4").arg(QString::number(stream->stream_id), + eventName[0], + eventName[1], + filterStr)); - free(str); + free(filterStr); } } @@ -232,7 +280,7 @@ void KsAdvFilteringDialog::_makeFilterTable(struct kshark_context *kshark_ctx) _table = new KsCheckBoxTable(this); _table->setSelectionMode(QAbstractItemView::SingleSelection); - headers << "Delete" << "Event" << " Id" << "Filter"; + headers << "Delete" << "Stream" << "Event" << " Id" << "Filter"; _table->init(headers, _filters.count()); for(auto f : _filters.keys()) { @@ -241,11 +289,14 @@ void KsAdvFilteringDialog::_makeFilterTable(struct kshark_context *kshark_ctx) i1 = new QTableWidgetItem(thisFilter[0]); _table->setItem(count, 1, i1); + i1 = new QTableWidgetItem(thisFilter[1]); + _table->setItem(count, 2, i1); + i2 = new QTableWidgetItem(tr("%1").arg(f)); - _table->setItem(count, 2, i2); + _table->setItem(count, 3, i2); - i3 = new QTableWidgetItem(thisFilter[1]); - _table->setItem(count, 3, i3); + i3 = new QTableWidgetItem(thisFilter[2]); + _table->setItem(count, 4, i3); ++count; } @@ -275,20 +326,25 @@ void KsAdvFilteringDialog::_help() void KsAdvFilteringDialog::_systemChanged(const QString &sysName) { kshark_context *kshark_ctx(NULL); - QStringList evtsList; - tep_event **events; - int i, nEvts; + kshark_data_stream *stream; + QStringList evtsList, name; + QVector eventIds; + int i; - _eventComboBox.clear(); - if (!kshark_instance(&kshark_ctx) || !kshark_ctx->pevent) + if (!kshark_instance(&kshark_ctx)) return; - nEvts = tep_get_events_count(kshark_ctx->pevent); - events = tep_list_events(kshark_ctx->pevent, TEP_EVENT_SORT_SYSTEM); + _eventComboBox.clear(); + + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return; - for (i = 0; i < nEvts; ++i) { - if (sysName == events[i]->system) - evtsList << events[i]->name; + eventIds = KsUtils::getEventIdList(stream->stream_id); + for (i = 0; i < stream->n_events; ++i) { + name = KsUtils::getTepEvtName(stream->stream_id, eventIds[i]); + if (sysName == name[0]) + evtsList << name[1]; } std::sort(evtsList.begin(), evtsList.end()); @@ -300,15 +356,20 @@ void KsAdvFilteringDialog::_systemChanged(const QString &sysName) } QStringList -KsAdvFilteringDialog::_getEventFormatFields(struct tep_event *event) +KsAdvFilteringDialog::_getEventFields(int eventId) { - tep_format_field *field, **fields = tep_event_fields(event); + kshark_context *kshark_ctx(NULL); + kshark_data_stream *stream; QStringList fieldList; - for (field = *fields; field; field = field->next) - fieldList << field->name; + if (!kshark_instance(&kshark_ctx)) + return {}; + + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return {}; - free(fields); + fieldList = KsUtils::getEventFieldsList(stream->stream_id, eventId); std::sort(fieldList.begin(), fieldList.end()); return fieldList; @@ -317,22 +378,24 @@ KsAdvFilteringDialog::_getEventFormatFields(struct tep_event *event) void KsAdvFilteringDialog::_eventChanged(const QString &evtName) { QString sysName = _systemComboBox.currentText(); + QStringList fieldList, eventName; kshark_context *kshark_ctx(NULL); - QStringList fieldList; - tep_event **events; - int nEvts; + kshark_data_stream *stream; + QVector eventIds; _fieldComboBox.clear(); - if (!kshark_instance(&kshark_ctx) || !kshark_ctx->pevent) + if (!kshark_instance(&kshark_ctx)) return; - nEvts = tep_get_events_count(kshark_ctx->pevent); - events = tep_list_events(kshark_ctx->pevent, TEP_EVENT_SORT_SYSTEM); + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return; - for (int i = 0; i < nEvts; ++i) { - if (evtName == events[i]->name && - sysName == events[i]->system) { - fieldList = _getEventFormatFields(events[i]); + eventIds = KsUtils::getEventIdList(stream->stream_id); + for (int i = 0; i < stream->n_events; ++i) { + eventName = KsUtils::getTepEvtName(stream->stream_id, eventIds[i]); + if (sysName == eventName[0] && evtName == eventName[1]) { + fieldList = _getEventFields(eventIds[i]); _fieldComboBox.addItems(fieldList); return; @@ -384,20 +447,28 @@ void KsAdvFilteringDialog::_applyPress() { QMapIterator f(_filters); kshark_context *kshark_ctx(NULL); + kshark_data_stream *stream; const char *text; - tep_errno ret; char *filter; int i(0); if (!kshark_instance(&kshark_ctx)) return; + stream = _getCurrentStream(kshark_ctx); + if (!stream || !kshark_is_tep(stream)) + return; + while (f.hasNext()) { f.next(); if (_table->_cb[i]->checkState() == Qt::Checked) { - tep_filter_remove_event(kshark_ctx->advanced_event_filter, - f.key()); + kshark_data_stream *filter_stream; + int sd = f.value().split(":").at(0).toInt(); + + filter_stream = kshark_get_data_stream(kshark_ctx, sd); + kshark_tep_filter_remove_event(filter_stream, f.key()); } + ++i; } @@ -419,20 +490,7 @@ void KsAdvFilteringDialog::_applyPress() filter = (char*) malloc(strlen(text) + 1); strcpy(filter, text); - ret = tep_filter_add_filter_str(kshark_ctx->advanced_event_filter, - filter); - - if (ret < 0) { - char error_str[200]; - - tep_strerror(kshark_ctx->pevent, ret, error_str, - sizeof(error_str)); - - fprintf(stderr, "filter failed due to: %s\n", error_str); - free(filter); - - return; - } + kshark_tep_add_filter_str(stream, filter); free(filter); diff --git a/src/KsAdvFilteringDialog.hpp b/src/KsAdvFilteringDialog.hpp index 2a534d0..a1db90b 100644 --- a/src/KsAdvFilteringDialog.hpp +++ b/src/KsAdvFilteringDialog.hpp @@ -36,7 +36,7 @@ private: QMap _filters; - KsCheckBoxTable *_table; + KsWidgetsLib::KsCheckBoxTable *_table; QVBoxLayout _topLayout; @@ -46,6 +46,8 @@ private: QLabel _descrLabel, _sysEvLabel, _opsLabel, _fieldLabel; + QComboBox _streamComboBox; + QComboBox _systemComboBox, _eventComboBox; QComboBox _opsComboBox, _fieldComboBox; @@ -74,13 +76,17 @@ private: QStringList _operators(); - void _getFilters(struct kshark_context *kshark_ctx); + void _getFtraceStreams(kshark_context *kshark_ctx); + + void _getFilters(kshark_context *kshark_ctx); + + void _makeFilterTable(kshark_context *kshark_ctx); - void _makeFilterTable(struct kshark_context *kshark_ctx); + QStringList _getEventFields(int eventId); - QStringList _getEventFormatFields(struct tep_event *event); + void _setSystemCombo(kshark_context *kshark_ctx); - void _setSystemCombo(struct kshark_context *kshark_ctx); + kshark_data_stream *_getCurrentStream(kshark_context *kshark_ctx); private slots: void _systemChanged(const QString&);