aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYordan Karadzhov <ykaradzhov@vmware.com>2019-04-19 16:50:29 +0300
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2019-04-19 12:13:02 -0400
commit7094701b4c112944de3903b7e0984753c8b71fc2 (patch)
treef83e364d4cc5f1df1dd916ec4f091bb5d8c0b77d
parentd8fbd7bf84a4079831e55fddaccbaf74f8d0816b (diff)
downloadtrace-cmd-7094701b4c112944de3903b7e0984753c8b71fc2.tar.gz
kernel-shark: Configuration information in ${HOME}/.cache/kernelshark
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. Link: http://lore.kernel.org/linux-trace-devel/20190419135036.19340-2-ykaradzhov@vmware.com Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--kernel-shark/src/KsMainWindow.cpp68
-rw-r--r--kernel-shark/src/KsMainWindow.hpp4
2 files changed, 63 insertions, 9 deletions
diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 7afb7218..c839acab 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(QDir::homePath()) +
+ "/.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 78cd4428..ec6506e9 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);
};