From patchwork Tue Apr 23 13:27:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10912963 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 680401390 for ; Tue, 23 Apr 2019 13:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 553B8286F2 for ; Tue, 23 Apr 2019 13:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48AC828715; Tue, 23 Apr 2019 13:28:07 +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 C3A56286F2 for ; Tue, 23 Apr 2019 13:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727762AbfDWN2G (ORCPT ); Tue, 23 Apr 2019 09:28:06 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39429 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727467AbfDWN2G (ORCPT ); Tue, 23 Apr 2019 09:28:06 -0400 Received: by mail-wm1-f68.google.com with SMTP id n25so48691wmk.4 for ; Tue, 23 Apr 2019 06:28:04 -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=MQ5bu7Q2HlDV1Agt/54R/VPmV4hl5vSOySDWLM7upn8=; b=cNqGyH0TArqG5RET/AFBx+cJScFJS6b9mxovX/cYHX4MAT8uZkTSj/pqHWa5pz+5oB wotUeR1xwxIRyt7TpdOyk17mY/fdM95gBV9x8QLr38HW64ChPLk0GOCWCE2+WgZupFcY bEOeGGbv9pQ2zcZDVcZAET+XgstzqKo0AJqfpDe0ez/5WB7qXfcR339NuuiLXOkf5k9h 8tmY1EPh/3FIxBupNdtiDM1BSXoSD3irk6aotVKxpkKBBtDUdmD9rOwG2ujUPEVkSwVJ UEts7BmVfAxjvteMwNFp3D85RKJ5X9PTt0BQv4COEvW6TQHlXgq3k8s4LiBcMGh6QWzH b4MQ== X-Gm-Message-State: APjAAAWI26l3h1HhaQXMBOOdMSgafw6nVVLApYcY2YsOQ/MQlAcnvusL oGu97dqF041f+I+XnaruL6o= X-Google-Smtp-Source: APXvYqw9YwJ08jGF5pxA9s86Bz8iw/5T4DcwE3+z9+jsxH8hl5blhk7t37kUtri+g6SaExhynwtTlQ== X-Received: by 2002:a1c:6889:: with SMTP id d131mr2347449wmc.114.1556026084156; Tue, 23 Apr 2019 06:28:04 -0700 (PDT) Received: from mamba.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id w11sm31222231wre.15.2019.04.23.06.28.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 06:28:03 -0700 (PDT) From: Yordan Karadzhov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com, Yordan Karadzhov Subject: [PATCH 3/5] kernel-shark: Add logic for the plugins search path Date: Tue, 23 Apr 2019 16:27:39 +0300 Message-Id: <20190423132741.17864-4-ykaradzhov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190423132741.17864-1-ykaradzhov@vmware.com> References: <20190423132741.17864-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 not been started from its installation location and the 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) Signed-off-by: Yordan Karadzhov --- kernel-shark/src/KsUtils.cpp | 40 ++++++++++++++++++------- kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/plugins/CMakeLists.txt | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp index 8c42206..f62e53a 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,28 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) lamUregUser); } +char *KsPluginManager::_pluginLibFromName(const QString &plugin, int &n) +{ + QString execPath = QCoreApplication::applicationFilePath(); + QString path = QFileInfo(execPath).path(); + std::string pluginStr = plugin.toStdString(); + char *lib; + QDir dir; + + dir.setCurrent(path); + if (!KsUtils::isInstalled() && dir.cd("../../kernel-shark/lib")) { + std::string pathStr = dir.path().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 +649,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 +710,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 +718,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)