From patchwork Sat May 4 13:07:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10929709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4F911390 for ; Sat, 4 May 2019 13:07:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 887D9286F7 for ; Sat, 4 May 2019 13:07:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A08428817; Sat, 4 May 2019 13:07:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3016286F7 for ; Sat, 4 May 2019 13:07:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726672AbfEDNHQ (ORCPT ); Sat, 4 May 2019 09:07:16 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:32797 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbfEDNHQ (ORCPT ); Sat, 4 May 2019 09:07:16 -0400 Received: by mail-wr1-f65.google.com with SMTP id e28so11275378wra.0 for ; Sat, 04 May 2019 06:07:14 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=umEDmutCF5pi2/Wws4iRo0lTXpiFzOcDerbEKFuVe3M=; b=S7EpQpIs4jlgKLI8dvl/vTH1VYobI9Y3KGj+1O/YBfdIrhcpllmXt2wCtyOxuInktD ZapkfSCd5UcjVAJ8lTxQEoJ/KJgjXrCOW4CSMhTGG6SO5WZwaie05HDDvNikUXVANSME XVjsF2kPEmIoyiKTAWYbPPwuF/A86hMMtdYqXkcV6Isd5UGS3vyjbCPoEvx5V7Bn3ab+ w6UGS0orTjDgTfUuD7BCuMQW9iaQ7o5iOPSqdBtxb/7ENDikA08vfFzR9aJlxq/nK7vM Ik/c5cAWhzvXn+hqfp8XFsEx8vixmHwAUmiCZWk+N+jZ5e8QfDcIi1UsknD7p3JcSBz4 Ib9Q== X-Gm-Message-State: APjAAAXogH3t00LYB8+UbgJ167d8zBIsolxZe96SJhOr9lq3TEX+4Vh8 94Ngilz+KYVWz8bzVUS0gow= X-Google-Smtp-Source: APXvYqwgkNN3ngwJkgd6aamPi9hAH3nNIeOdydnKIB4p5FDFj4l16e/Y1yoHTYrk+eADPMreLCDkHg== X-Received: by 2002:a05:6000:ca:: with SMTP id q10mr3459795wrx.148.1556975233707; Sat, 04 May 2019 06:07:13 -0700 (PDT) Received: from localhost.localdomain ([84.40.104.204]) by smtp.gmail.com with ESMTPSA id z5sm8524891wre.70.2019.05.04.06.07.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 May 2019 06:07:13 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov , Slavomir Kaslev Subject: [PATCH v3 3/8] kernel-shark: Add logic for the plugins search path Date: Sat, 4 May 2019 16:07:02 +0300 Message-Id: <20190504130702.27755-1-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the application has not been started from its installation location and the directory app_file_path + "../../kernel-shark/lib" exists, all build-in plugins will be loaded from this directory. In any other case all build-in plugins will be loaded from _INSTALL_PREFIX/lib/kshark/plugins/ Suggested-by: Steven Rostedt (VMware) Reviewed-by: Slavomir Kaslev Signed-off-by: Yordan Karadzhov --- kernel-shark/src/KsUtils.cpp | 38 ++++++++++++++++++------- kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/plugins/CMakeLists.txt | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp index 8c42206..3e88d96 100644 --- a/kernel-shark/src/KsUtils.cpp +++ b/kernel-shark/src/KsUtils.cpp @@ -544,13 +544,12 @@ void KsPluginManager::_parsePluginList() */ void KsPluginManager::registerFromList(kshark_context *kshark_ctx) { - auto lamRegBuiltIn = [&kshark_ctx](const QString &plugin) + auto lamRegBuiltIn = [&kshark_ctx, this](const QString &plugin) { char *lib; int n; - n = asprintf(&lib, "%s/lib/plugin-%s.so", - KS_DIR, plugin.toStdString().c_str()); + lib = _pluginLibFromName(plugin, n); if (n <= 0) return; @@ -579,13 +578,12 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx) */ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) { - auto lamUregBuiltIn = [&kshark_ctx](const QString &plugin) + auto lamUregBuiltIn = [&kshark_ctx, this](const QString &plugin) { char *lib; int n; - n = asprintf(&lib, "%s/lib/plugin-%s.so", - KS_DIR, plugin.toStdString().c_str()); + lib = _pluginLibFromName(plugin, n); if (n <= 0) return; @@ -608,6 +606,26 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) lamUregUser); } +char *KsPluginManager::_pluginLibFromName(const QString &plugin, int &n) +{ + QString appPath = QCoreApplication::applicationDirPath(); + QString libPath = appPath + "/../../kernel-shark/lib"; + std::string pluginStr = plugin.toStdString(); + char *lib; + + libPath = QDir::cleanPath(libPath); + if (!KsUtils::isInstalled() && QDir(libPath).exists()) { + std::string pathStr = libPath.toStdString(); + n = asprintf(&lib, "%s/plugin-%s.so", + pathStr.c_str(), pluginStr.c_str()); + } else { + n = asprintf(&lib, "%s/lib/kshark/plugins/plugin-%s.so", + _INSTALL_PREFIX, pluginStr.c_str()); + } + + return lib; +} + /** * @brief Register a Plugin. * @@ -629,8 +647,7 @@ void KsPluginManager::registerPlugin(const QString &plugin) * The argument is the name of the plugin. From the * name get the library .so file. */ - n = asprintf(&lib, "%s/lib/plugin-%s.so", - KS_DIR, plugin.toStdString().c_str()); + lib = _pluginLibFromName(plugin, n); if (n > 0) { kshark_register_plugin(kshark_ctx, lib); _registeredKsPlugins[i] = true; @@ -691,8 +708,7 @@ void KsPluginManager::unregisterPlugin(const QString &plugin) * The argument is the name of the plugin. From the * name get the library .so file. */ - n = asprintf(&lib, "%s/lib/plugin-%s.so", KS_DIR, - plugin.toStdString().c_str()); + lib = _pluginLibFromName(plugin, n); if (n > 0) { kshark_unregister_plugin(kshark_ctx, lib); _registeredKsPlugins[i] = false; @@ -700,7 +716,7 @@ void KsPluginManager::unregisterPlugin(const QString &plugin) } return; - } else if (plugin.contains("/lib/plugin-" + + } else if (plugin.contains("/lib/plugin-" + _ksPluginList[i], Qt::CaseInsensitive)) { /* * The argument is the name of the library .so file. diff --git a/kernel-shark/src/KsUtils.hpp b/kernel-shark/src/KsUtils.hpp index 7b80b21..1c87271 100644 --- a/kernel-shark/src/KsUtils.hpp +++ b/kernel-shark/src/KsUtils.hpp @@ -241,6 +241,8 @@ signals: private: void _parsePluginList(); + char *_pluginLibFromName(const QString &plugin, int &n); + template void _forEachInList(const QStringList &pl, const QVector ®, diff --git a/kernel-shark/src/plugins/CMakeLists.txt b/kernel-shark/src/plugins/CMakeLists.txt index 6098275..64cf98d 100644 --- a/kernel-shark/src/plugins/CMakeLists.txt +++ b/kernel-shark/src/plugins/CMakeLists.txt @@ -29,6 +29,6 @@ BUILD_PLUGIN(NAME missed_events list(APPEND PLUGIN_LIST "missed_events default") # This plugin will be loaded by default install(TARGETS sched_events missed_events - LIBRARY DESTINATION ${_INSTALL_PREFIX}/lib/kshark/) + LIBRARY DESTINATION ${_INSTALL_PREFIX}/lib/kshark/plugins/) set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)