From patchwork Fri Apr 19 13:50:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10909653 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 2DE0F14DB for ; Fri, 19 Apr 2019 19:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2146C28A2E for ; Fri, 19 Apr 2019 19:19:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154AA28A5F; Fri, 19 Apr 2019 19:19:49 +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 905EC28A2E for ; Fri, 19 Apr 2019 19:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbfDSTTs (ORCPT ); Fri, 19 Apr 2019 15:19:48 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55068 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfDSTTs (ORCPT ); Fri, 19 Apr 2019 15:19:48 -0400 Received: by mail-wm1-f65.google.com with SMTP id c1so7142927wml.4 for ; Fri, 19 Apr 2019 12:19:46 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0UuVyUaj6gRC5oVMlVkfjA3JGzFPAwr7A83t9IIslI=; b=OYdrnUFsLMLTw29zsGtbl0XGNTayvTWEjoCqL3YwIwlhFQ5BUQAoG1JoYtx4JsEIkS 3wkl/SttHThDOtLV8jPxoK5g5ng7nIH45oRrsHP1B6t4zNbQ8/FSB5xZN+zbxoRycV31 Ryy0BA+h8dtq4fo1eNkyLhNoqtqk1Cv3gQpKVfE4YFkZRwv+LeAGAX/t4BpHNmx0YqTb baYOxD9q65A1LtYi0A9ZByZXIuTFaUi+4+48Gdj2Ls5Xl193/tTngiNiwRO3/SdWkL8s fR/neICfuKqjiygPdk4FCKnAQW8w4w2Dv4CW32R5ebzCkDaoZm5T1rlau9YwFA6NqI1h SSOQ== X-Gm-Message-State: APjAAAU4dHHSGy8DpIk9QWYjv+4xsBYUFqEvvi+d0wR0mOQjxjCSD4lz 6IECkfHHn6DM4MJ1THvJetEQI2jK X-Google-Smtp-Source: APXvYqzsKmhQd4pOkE6TH3zt4PrEKH0XWWDiKNFh6I4AiEpITAwYt6Of9RvL62lSP3KtMvu+pXW1tw== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr2900033wmj.41.1555681860670; Fri, 19 Apr 2019 06:51:00 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id g132sm4120496wme.3.2019.04.19.06.51.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 06:51:00 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov Subject: [PATCH v3 4/8] kernel-shark: Add logic for the plugins search path Date: Fri, 19 Apr 2019 16:50:32 +0300 Message-Id: <20190419135036.19340-5-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419135036.19340-1-ykaradzhov@vmware.com> References: <20190419135036.19340-1-ykaradzhov@vmware.com> 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 been started from the source code directory, all build-in plugins will be loaded from kernel-shark/lib/ If the application has been started from its installation location, all build-in plugins will be loaded from INSTALL_PREFIX/lib/kshark/plugins/ Signed-off-by: Yordan Karadzhov --- kernel-shark/build/deff.h.cmake | 3 +++ kernel-shark/src/KsUtils.cpp | 35 +++++++++++++++++-------- kernel-shark/src/KsUtils.hpp | 1 + kernel-shark/src/plugins/CMakeLists.txt | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/kernel-shark/build/deff.h.cmake b/kernel-shark/build/deff.h.cmake index 8041cfc..ba211f4 100644 --- a/kernel-shark/build/deff.h.cmake +++ b/kernel-shark/build/deff.h.cmake @@ -14,6 +14,9 @@ /** KernelShark source code path. */ #cmakedefine KS_DIR "@KS_DIR@" +/** KernelShark installation prefix path. */ +#cmakedefine _INSTALL_PREFIX "@_INSTALL_PREFIX@" + /** Location of the trace-cmd executable. */ #cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@" diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp index 6af0c66..b05c0dc 100644 --- a/kernel-shark/src/KsUtils.cpp +++ b/kernel-shark/src/KsUtils.cpp @@ -423,13 +423,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; @@ -458,13 +457,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; @@ -487,6 +485,23 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) lamUregUser); } +char *KsPluginManager::_pluginLibFromName(const QString &plugin, int &n) +{ + QString path = QCoreApplication::applicationFilePath(); + std::string pluginStr = plugin.toStdString(); + char *lib; + + if (path.contains(KS_DIR)) { + n = asprintf(&lib, "%s/lib/plugin-%s.so", + KS_DIR, 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. * @@ -508,8 +523,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; @@ -570,8 +584,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; @@ -579,7 +592,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 77048ab..019bde8 100644 --- a/kernel-shark/src/KsUtils.hpp +++ b/kernel-shark/src/KsUtils.hpp @@ -238,6 +238,7 @@ signals: private: void _parsePluginList(); + char *_pluginLibFromName(const QString &plugin, int &n); template void _forEachInList(const QStringList &pl, 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)