From c900307ca2db204572bde2c02c471ec954ec8c1a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 31 Mar 2015 15:27:36 +0200 Subject: pass variable number of arguments to --profile-perf The option --profile-perf now takes a comma-separated list of arguments that will be passed directly to perf. Commas can be escaped by doubling them. Change-Id: Ifdb982122b15c0771634adf9c81bcb5e195a2cdf Reviewed-by: Ulf Hermann Reviewed-by: Rainer Keller --- main.cpp | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 741523c..fb52564 100644 --- a/main.cpp +++ b/main.cpp @@ -238,6 +238,30 @@ static bool makeDefault(const QString &filepath) return true; } +static QStringList extractPerfParams(QString s) +{ + QStringList lst; + int h = 0; + int i = 0; + for (;;) { + i = s.indexOf(QLatin1Char(','), i); + if (i >= 0) { + if (i + 1 < s.length() && s.at(i + 1) == QLatin1Char(',')) { + s.remove(i, 1); + i++; + continue; + } + lst << s.mid(h, i - h); + i++; + h = i; + } else { + lst << s.mid(h); + break; + } + } + return lst; +} + int main(int argc, char **argv) { // Save arguments before QCoreApplication handles them @@ -281,13 +305,14 @@ int main(int argc, char **argv) } else if (arg == "--debug-qml") { useQML = true; } else if (arg == "--profile-perf") { - if (args.isEmpty() || - (perfParams = args.takeFirst().split(QLatin1Char(','))).length() != 3) { - fprintf(stderr, "--profile-perf requires a parameter specification of" - " \",,\" where can be \"fp\" or " - " \"dwarf\", amd and are integers."); + if (args.isEmpty()) { + fprintf(stderr, "--profile-perf requires comma-separated list of parameters that " + "get passed to \"perf record\". Arguments \"-o -\" are " + "automatically appended to capture the output as stream. " + "Escape commas by doubling them."); return 1; } + perfParams = extractPerfParams(args.takeFirst()); } else if (arg == "--stop") { stop(); return 0; @@ -418,14 +443,10 @@ int main(int argc, char **argv) process.setDebug(); process.setSocketNotifier(new QSocketNotifier(serverSocket, QSocketNotifier::Read, &process)); - if (perfParams.length() == 3) { + if (!perfParams.isEmpty()) { QStringList allArgs; - allArgs << QLatin1String("perf") << QLatin1String("record") << QLatin1String("--call-graph"); - if (perfParams[0] == QLatin1String("dwarf")) - allArgs << QString(QLatin1String("dwarf,%1")).arg(perfParams[1]); - else - allArgs << perfParams[0]; - allArgs << QLatin1String("-F") << perfParams[2] << QLatin1String("-o") << QLatin1String("-") + allArgs << QLatin1String("perf") << QLatin1String("record") + << perfParams << QLatin1String("-o") << QLatin1String("-") << QLatin1String("--") << defaultArgs.join(QLatin1Char(' ')); PerfProcessHandler *server = new PerfProcessHandler(&process, allArgs); -- cgit v1.2.3