All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com,
	Yordan Karadzhov <ykaradzhov@vmware.com>
Subject: [PATCH v2 1/8] kernel-shark: Configuration information in ${HOME}/.cache/kernelshark
Date: Thu, 18 Apr 2019 18:21:39 +0300	[thread overview]
Message-ID: <20190418152146.27232-2-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20190418152146.27232-1-ykaradzhov@vmware.com>

By default the "Last session" configuration file will be saved in
${HOME}/.cache/kernelshark. If ${HOME}/.cache/kernelshark doesn't exist,
it will be created automatically. The user can select another directory
to be used to store the cached data. This can be done by setting the
environment variable KS_USER_CACHE_DIR. In this case if the path (the
value of KS_USER_CACHE_DIR) doesn't exist the user will be asked before
create it.

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsMainWindow.cpp | 68 +++++++++++++++++++++++++++----
 kernel-shark/src/KsMainWindow.hpp |  4 ++
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 7afb721..cf2db74 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -133,13 +133,15 @@ KsMainWindow::KsMainWindow(QWidget *parent)
 KsMainWindow::~KsMainWindow()
 {
 	kshark_context *kshark_ctx(nullptr);
-	QString file = KS_CONF_DIR;
+	QString file = lastSessionFile();
 
-	file += "/lastsession.json";
+	if (!file.isEmpty()) {
+		QByteArray fileBA = file.toLocal8Bit();
 
-	_updateSession();
-	kshark_save_config_file(file.toLocal8Bit().data(),
-				_session.getConfDocPtr());
+		_updateSession();
+		kshark_save_config_file(fileBA.data(),
+					_session.getConfDocPtr());
+	}
 
 	_data.clear();
 
@@ -368,12 +370,60 @@ void KsMainWindow::_open()
 		loadDataFile(fileName);
 }
 
-void KsMainWindow::_restoreSession()
+QString KsMainWindow::_getCacheDir()
+{
+	QString dir;
+
+	auto lamMakePath = [&] (bool ask) {
+		if (ask) {
+			QMessageBox::StandardButton reply;
+			QString err("KernelShark cache directory not found!\n");
+			QString question =
+				QString("Do you want to create %1").arg(dir);
+
+			reply = QMessageBox::question(this, "KernelShark",
+						      err + question,
+						      QMessageBox::Yes |
+						      QMessageBox::No);
+
+			if (reply == QMessageBox::No) {
+				dir.clear();
+				return;
+			}
+		}
+
+		QDir().mkpath(dir);
+	};
+
+	dir = getenv("KS_USER_CACHE_DIR");
+	if (!dir.isEmpty()) {
+		if (!QDir(dir).exists())
+			lamMakePath(true);
+	} else {
+		dir = QString(getpwuid(getuid())->pw_dir) +
+		      "/.cache/kernelshark";
+		if (!QDir(dir).exists())
+			lamMakePath(false);
+	}
+
+	return dir;
+}
+
+/** Get the description file of the last session. */
+QString KsMainWindow::lastSessionFile()
 {
-	QString file = KS_CONF_DIR;
-	file += "/lastsession.json";
+	QString file;
 
-	loadSession(file);
+	file = _getCacheDir();
+	if (!file.isEmpty())
+		file += "/lastsession.json";
+
+	return file;
+}
+
+void KsMainWindow::_restoreSession()
+{
+	loadSession(lastSessionFile());
 	_graph.updateGeom();
 }
 
diff --git a/kernel-shark/src/KsMainWindow.hpp b/kernel-shark/src/KsMainWindow.hpp
index 78cd442..ec6506e 100644
--- a/kernel-shark/src/KsMainWindow.hpp
+++ b/kernel-shark/src/KsMainWindow.hpp
@@ -37,6 +37,8 @@ public:
 
 	void loadSession(const QString &fileName);
 
+	QString lastSessionFile();
+
 	/**
 	 * @brief
 	 *
@@ -230,6 +232,8 @@ private:
 
 	void _filterSyncCBoxUpdate(kshark_context *kshark_ctx);
 
+	QString _getCacheDir();
+
 private slots:
 	void _captureFinished(int, QProcess::ExitStatus);
 };
-- 
2.19.1


  reply	other threads:[~2019-04-18 15:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 15:21 [PATCH v2 0/8] Various modifications and fixes toward KS 1.0 Yordan Karadzhov
2019-04-18 15:21 ` Yordan Karadzhov [this message]
2019-04-19  7:19   ` [PATCH v2 1/8] kernel-shark: Configuration information in ${HOME}/.cache/kernelshark Slavomir Kaslev
2019-04-19 18:18     ` Steven Rostedt
2019-04-18 15:21 ` [PATCH v2 2/8] kernel-shark: Remove the definition of KS_CONF_DIR Yordan Karadzhov
2019-04-18 15:21 ` [PATCH v2 3/8] kernel-shark: Add logic for the initial path of Open-File dialogs Yordan Karadzhov
2019-04-19  7:26   ` Slavomir Kaslev
2019-04-19 17:48     ` Steven Rostedt
2019-04-18 15:21 ` [PATCH v2 4/8] kernel-shark: Add logic for the plugins search path Yordan Karadzhov
2019-04-19  7:43   ` Slavomir Kaslev
2019-04-19 17:59     ` Steven Rostedt
2019-04-18 15:21 ` [PATCH v2 5/8] kernel-shark: Rename KS_DIR to KS_SOURCE_DIR Yordan Karadzhov
2019-04-18 15:21 ` [PATCH v2 6/8] kernel-shark: Load Last Session from command line Yordan Karadzhov
2019-04-18 15:21 ` [PATCH v2 7/8] kernel-shark: Use proper searching condition when the dataset is small Yordan Karadzhov
2019-04-18 15:21 ` [PATCH v2 8/8] kernel-shark: Handle the case when the marker points to a filtered entry Yordan Karadzhov
2019-04-19  7:29   ` Slavomir Kaslev
2019-04-19  7:46     ` Yordan Karadzhov
2019-04-19  7:55       ` Slavomir Kaslev
2019-04-19  8:07       ` Slavomir Kaslev
2019-04-19 18:03       ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190418152146.27232-2-ykaradzhov@vmware.com \
    --to=ykaradzhov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=y.karadz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.