From: Yordan Karadzhov <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
Yordan Karadzhov <ykaradzhov@vmware.com>,
Yordan Karadzhov <y.karadz@gmail.com>
Subject: [PATCH 4/4] kernel-shark-qt: Add widget demo example.
Date: Mon, 8 Oct 2018 18:16:29 +0300 [thread overview]
Message-ID: <20181008151629.13973-5-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181008151629.13973-1-ykaradzhov@vmware.com>
From: Yordan Karadzhov <ykaradzhov@vmware.com>
This patch introduces a basic example, showing how to use KsUtils and
KsWidgetsLib.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
kernel-shark-qt/examples/CMakeLists.txt | 4 +
kernel-shark-qt/examples/widgetdemo.cpp | 159 ++++++++++++++++++++++++
2 files changed, 163 insertions(+)
create mode 100644 kernel-shark-qt/examples/widgetdemo.cpp
diff --git a/kernel-shark-qt/examples/CMakeLists.txt b/kernel-shark-qt/examples/CMakeLists.txt
index 0c83293..e16216e 100644
--- a/kernel-shark-qt/examples/CMakeLists.txt
+++ b/kernel-shark-qt/examples/CMakeLists.txt
@@ -19,3 +19,7 @@ target_link_libraries(confio kshark)
message(STATUS "dataplot")
add_executable(dplot dataplot.cpp)
target_link_libraries(dplot kshark-plot)
+
+message(STATUS "widgetdemo")
+add_executable(widgetdemo widgetdemo.cpp)
+target_link_libraries(widgetdemo kshark-gui)
diff --git a/kernel-shark-qt/examples/widgetdemo.cpp b/kernel-shark-qt/examples/widgetdemo.cpp
new file mode 100644
index 0000000..c9ce86b
--- /dev/null
+++ b/kernel-shark-qt/examples/widgetdemo.cpp
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (C) 2017 VMware Inc, Yordan Karadzhov <y.karadz@gmail.com>
+ */
+
+// C
+#include <sys/stat.h>
+#include <getopt.h>
+#include <unistd.h>
+
+// C++
+#include <iostream>
+
+// Qt
+#include <QtWidgets>
+
+// KernelShark
+#include "KsUtils.hpp"
+#include "KsWidgetsLib.hpp"
+
+#define default_input_file (char*)"trace.dat"
+
+static char *input_file = nullptr;
+
+using namespace std;
+
+void usage(const char *prog)
+{
+ cout << "Usage: " << prog << endl
+ << " -h Display this help message\n"
+ << " -v Display version and exit\n"
+ << " -i input_file, default is " << default_input_file << endl
+ << " -p register plugin, use plugin name, absolute or relative path\n"
+ << " -u unregister plugin, use plugin name or absolute path\n";
+}
+
+struct TaskPrint : public QObject
+{
+ tep_handle *_pevent;
+
+ void print(QVector<int> pids)
+ {
+ for (auto const &pid: pids)
+ cout << "task: "
+ << tep_data_comm_from_pid(_pevent, pid)
+ << " pid: " << pid << endl;
+ }
+};
+
+int main(int argc, char **argv)
+{
+ kshark_context *kshark_ctx(nullptr);
+ QApplication a(argc, argv);
+ KsPluginManager plugins;
+ KsDataStore data;
+ size_t nRows(0);
+ int c;
+
+ if (!kshark_instance(&kshark_ctx))
+ return 1;
+
+ while ((c = getopt(argc, argv, "hvi:p:u:")) != -1) {
+ switch(c) {
+ case 'v':
+ printf("kshark-gui %s\n", KS_VERSION_STRING);
+ return 0;
+
+ case 'i':
+ input_file = optarg;
+ break;
+
+ case 'p':
+ plugins.registerPlugin(QString(optarg));
+ break;
+
+ case 'u':
+ plugins.unregisterPlugin(QString(optarg));
+ break;
+
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (!input_file) {
+ struct stat st;
+ if (stat(default_input_file, &st) == 0)
+ input_file = default_input_file;
+ }
+
+ if (input_file) {
+ data.loadDataFile(input_file);
+ nRows = data.size();
+ } else {
+ cerr << "No input file is provided.\n";
+ }
+
+ cout << nRows << " entries loaded\n";
+
+ auto lamPrintPl = [&] ()
+ {
+ kshark_plugin_list *pl;
+ for (pl = kshark_ctx->plugins; pl; pl = pl->next)
+ cout << pl->file << endl;
+ };
+
+ cout << "\n\n";
+ lamPrintPl();
+ sleep(1);
+
+ QVector<bool> registeredPlugins;
+ QStringList pluginsList;
+
+ pluginsList << plugins._ksPluginList
+ << plugins._userPluginList;
+
+ registeredPlugins << plugins._registeredKsPlugins
+ << plugins._registeredUserPlugins;
+
+ KsCheckBoxWidget *pluginCBD
+ = new KsPluginCheckBoxWidget(pluginsList);
+
+ pluginCBD->set(registeredPlugins);
+
+ KsCheckBoxDialog *dialog1 = new KsCheckBoxDialog(pluginCBD);
+ QObject::connect(dialog1, &KsCheckBoxDialog::apply,
+ &plugins, &KsPluginManager::updatePlugins);
+
+ dialog1->show();
+ a.exec();
+
+ cout << "\n\nYou selected\n";
+ lamPrintPl();
+ sleep(1);
+
+ if (!nRows)
+ return 1;
+
+ KsCheckBoxWidget *tasks_cbd =
+ new KsTasksCheckBoxWidget(data.pevent(), true);
+
+ tasks_cbd->setDefault(false);
+
+ TaskPrint p;
+ p._pevent = data.pevent();
+
+ KsCheckBoxDialog *dialog2 = new KsCheckBoxDialog(tasks_cbd);
+ QObject::connect(dialog2, &KsCheckBoxDialog::apply,
+ &p, &TaskPrint::print);
+
+ cout << "\n\nYou selected\n";
+ dialog2->show();
+ a.exec();
+
+ return 0;
+}
--
2.17.1
next prev parent reply other threads:[~2018-10-08 22:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 15:16 [PATCH 0/4] Add basic components to be used by the Qt GUI Yordan Karadzhov
2018-10-08 15:16 ` [PATCH 1/4] kernel-shark-qt: Add Qt as a third party dependency Yordan Karadzhov
2018-10-08 15:16 ` [PATCH 2/4] kernel-shark-qt: Add KernalShark Utils Yordan Karadzhov
2018-10-09 16:34 ` Steven Rostedt
2018-10-10 14:12 ` Yordan Karadzhov
2018-10-10 15:22 ` Steven Rostedt
2018-10-10 15:25 ` Yordan Karadzhov
2018-10-10 19:02 ` Steven Rostedt
2018-10-10 15:27 ` Yordan Karadzhov
2018-10-10 15:27 ` Yordan Karadzhov
2018-10-10 19:04 ` Steven Rostedt
2018-10-08 15:16 ` [PATCH 3/4] kernel-shark-qt: Add Widgets Lib Yordan Karadzhov
2018-10-09 16:42 ` Steven Rostedt
2018-10-08 15:16 ` Yordan Karadzhov [this message]
2018-10-09 16:45 ` [PATCH 4/4] kernel-shark-qt: Add widget demo example 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=20181008151629.13973-5-ykaradzhov@vmware.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=ykaradzhov@vmware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).