Command line options for selecting plots
cover Command line options for selecting plots
The patch-set implements new commandline options for KernelShark that can be used to pre-select the CPU and Task plots to be shown, before opening the GUI. The idea was suggested by Julia Lawall.
Yordan Karadzhov (VMware) (2):
kernel-shark: Add methods for selecting the plots to be shown
kernel-shark: Add command line options for selecting plots to be shown
kernel-shark/src/KsGLWidget.cpp | 6 ++--- kernel-shark/src/KsMainWindow.cpp | 39 +++++++++++++++++++++++++++++++ kernel-shark/src/KsMainWindow.hpp | 4 ++++ kernel-shark/src/KsUtils.cpp | 24 +++++++++++++++++++ kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/kernelshark.cpp | 32 ++++++++++++++++++++++--- 6 files changed, 101 insertions(+), 6 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 kernel-shark: Add methods for selecting the plots to be shown
The methods are added to the public interface of the KsMainWindow class and can be used to pre-select the CPU and Task plots to be shown, before opening the GUI.
--- kernel-shark/src/KsGLWidget.cpp | 6 ++--- kernel-shark/src/KsMainWindow.cpp | 39 +++++++++++++++++++++++++++++++ kernel-shark/src/KsMainWindow.hpp | 4 ++++ 3 files changed, 46 insertions(+), 3 deletions(-)
kernel-shark/src/KsGLWidget.cpp +3 -3
@@ -369,9 +369,9 @@ void KsGLWidget::loadData(KsDataStore *data) _model.fill(_data->rows(), _data->size()); /* Make a default CPU list. All CPUs will be plotted. */ - _cpuList = {}; - for (int i = 0; i < nCPUs; ++i) - _cpuList.append(i); + if (_cpuList.isEmpty()) + for (int i = 0; i < nCPUs; ++i) + _cpuList.append(i); /* Make a default task list. No tasks will be plotted. */ _taskList = {};
kernel-shark/src/KsMainWindow.cpp +39 -0
@@ -172,6 +172,45 @@ KsMainWindow::~KsMainWindow() kshark_free(kshark_ctx); } +/** Set the list ot CPU cores to be plotted. */ +void KsMainWindow::setCPUPlots(QVector<int> cpus) +{ + int nCPUs = tep_get_cpus(_data.tep()); + auto lamCPUCheck = [=] (int cpu) { + if (cpu >= nCPUs) { + qWarning() << "Warning: No CPU" << cpu << "found in the data."; + return true; + } + + return false; + }; + + cpus.erase(std::remove_if(cpus.begin(), cpus.end(), lamCPUCheck), + cpus.end()); + + _graph.cpuReDraw(cpus); +} + +/** Set the list ot tasks (pids) to be plotted. */ +void KsMainWindow::setTaskPlots(QVector<int> pids) +{ + QVector<int> allPids = KsUtils::getPidList(); + auto lamPidCheck = [=] (int pid) { + int i = allPids.indexOf(pid); + if (i < 0) { + qWarning() << "Warning: No Pid" << pid << "found in the data."; + return true; + } + + return false; + }; + + pids.erase(std::remove_if(pids.begin(), pids.end(), lamPidCheck), + pids.end()); + + _graph.taskReDraw(pids); +} + /** * Reimplemented event handler used to update the geometry of the window on * resize events.
kernel-shark/src/KsMainWindow.hpp +4 -0
@@ -61,6 +61,10 @@ public: _plugins.unregisterPlugin(plugin); } + void setCPUPlots(QVector<int> cpus); + + void setTaskPlots(QVector<int> pids); + void resizeEvent(QResizeEvent* event); /** Set the Full Screen mode. */
Signature · 1 line
2.20.1
PATCH 2/2 kernel-shark: Add command line options for selecting plots to be shown
In reply to Yordan Karadzhov (VMware)Example:
kernelshark -i mytrace.dat --cpu '1 4-7' --pid 11
This will show CPUs: 1, 4, 5, 6, 7 and task(PID): 11.
--- kernel-shark/src/KsUtils.cpp | 24 ++++++++++++++++++++++++ kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/kernelshark.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-)
kernel-shark/src/KsUtils.cpp +24 -0
@@ -298,6 +298,30 @@ QStringList splitArguments(QString cmd) return argv; } +/** Parse a string containing Ids. The string can be of the form "1 4-7 9". */ +QVector<int> parseIdList(QString v_str) +{ + QStringList list = v_str.split(" ", QString::SkipEmptyParts); + QVector<int> v; + + for (auto item: list) { + int i = item.indexOf('-'); + if (i > 0) { + /* This item is an interval. */ + int from = item.left(i).toInt(); + int n = item.right(i).toInt() - from + 1; + int size = v.size(); + + v.resize(size + n); + std::iota(v.begin() + size, v.end(), from); + } else { + v.append(item.toInt()); + } + } + + return v; +} + }; // KsUtils /** A stream operator for converting QColor into KsPlot::Color. */
kernel-shark/src/KsUtils.hpp +2 -0
@@ -132,6 +132,8 @@ QString getSaveFile(QWidget *parent, QStringList splitArguments(QString cmd); +QVector<int> parseIdList(QString v_str); + }; // KsUtils /** Identifier of the Dual Marker active state. */
kernel-shark/src/kernelshark.cpp +29 -3
@@ -29,20 +29,43 @@ void usage(const char *prog) printf(" -u unregister plugin, use plugin name or absolute path\n"); printf(" -s import a session\n"); printf(" -l import the last session\n"); + puts(" --cpu show plots for CPU cores, default is \"show all\""); + puts(" --pid show plots for tasks, default is \"do not show\""); + puts("\n example:"); + puts(" kernelshark -i mytrace.dat --cpu \'1 4-7\' --pid 11 -p path/to/my/plugin/myplugin.so\n"); } +#define KS_LONG_OPTS 0 +static option longOptions[] = { + {"help", no_argument, nullptr, 'h'}, + {"pid", required_argument, nullptr, KS_LONG_OPTS}, + {"cpu", required_argument, nullptr, KS_LONG_OPTS}, + {nullptr, 0, nullptr, 0} +}; + int main(int argc, char **argv) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); + QVector<int> cpuPlots, taskPlots; + bool fromSession = false; + int optionIndex = 0; KsMainWindow ks; - int c; - bool fromSession = false; - while ((c = getopt(argc, argv, "hvi:p:u:s:l")) != -1) { + while ((c = getopt_long(argc, argv, "hvi:p:u:s:l", + longOptions, + &optionIndex)) != -1) { switch(c) { + case KS_LONG_OPTS: + if (strcmp(longOptions[optionIndex].name, "cpu") == 0) + cpuPlots = KsUtils::parseIdList(QString(optarg)); + else if (strcmp(longOptions[optionIndex].name, "pid") == 0) + taskPlots = KsUtils::parseIdList(QString(optarg)); + + break; + case 'h': usage(argv[0]); return 0;
@@ -95,6 +118,9 @@ int main(int argc, char **argv) ks.loadDataFile(QString(input_file)); } + ks.setCPUPlots(cpuPlots); + ks.setTaskPlots(taskPlots); + ks.show(); return a.exec(); }
Signature · 1 line
2.20.1
Re: [PATCH 2/2] kernel-shark: Add command line options for selecting plots to be shown
Quoted 2 lines · On Fri, 24 Apr 2020 16:25:42 +0300 "Yordan Karadzhov (VMware)"…
Example:
kernelshark -i mytrace.dat --cpu '1 4-7' --pid 11
Can we change this to use a comma instead of a space. Then we don't need to worry about quotes.
kernelshark -i mytrace.dat --cpu 1,4-7
That's the common format for other unix command lines. See taskset for instance.
-- Steve
Quoted 12 lines
This will show CPUs: 1, 4, 5, 6, 7 and task(PID): 11.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>Suggested-by Julia Lawall <[email protected]>--- kernel-shark/src/KsUtils.cpp | 24 ++++++++++++++++++++++++ kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/kernelshark.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-)
Re: [PATCH 2/2] kernel-shark: Add command line options for selecting plots to be shown
Quoted 8 lines · Steven Rostedt
Quoted 2 lines · On Fri, 24 Apr 2020 16:25:42 +0300 "Yordan Karadzhov (VMware)"…
Example:
kernelshark -i mytrace.dat --cpu '1 4-7' --pid 11Can we change this to use a comma instead of a space. Then we don't need to worry about quotes.
This seems like a good idea. I was away from it a few days, and my first intuition was to use a comma.
julia
Quoted 22 lines
kernelshark -i mytrace.dat --cpu 1,4-7That's the common format for other unix command lines. See taskset for instance.
-- Steve
Quoted 12 lines
This will show CPUs: 1, 4, 5, 6, 7 and task(PID): 11.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>Suggested-by Julia Lawall <[email protected]>--- kernel-shark/src/KsUtils.cpp | 24 ++++++++++++++++++++++++ kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/kernelshark.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-)
Re: [PATCH 2/2] kernel-shark: Add command line options for selecting plots to be shown
Quoted 10 lines · Julia Lawall
Quoted 6 lines · Steven Rostedt
Quoted 2 lines · On Fri, 24 Apr 2020 16:25:42 +0300 "Yordan Karadzhov (VMware)"…
Example:
kernelshark -i mytrace.dat --cpu '1 4-7' --pid 11
Quoted 8 lines
Quoted 2 lines
Can we change this to use a comma instead of a space. Then we don't need to worry about quotes.
This seems like a good idea. I was away from it a few days, and my first intuition was to use a comma.
julia
OK, I will send new version of the patches.
Thanks a lot!
Yordan
Quoted 22 lines
Quoted 22 lines
kernelshark -i mytrace.dat --cpu 1,4-7That's the common format for other unix command lines. See taskset for instance.
-- Steve
Quoted 12 lines
This will show CPUs: 1, 4, 5, 6, 7 and task(PID): 11.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>Suggested-by Julia Lawall <[email protected]>--- kernel-shark/src/KsUtils.cpp | 24 ++++++++++++++++++++++++ kernel-shark/src/KsUtils.hpp | 2 ++ kernel-shark/src/kernelshark.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-)