From 9bcb822963fc96c94dbe7dcc4134dcd2dac454ff Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 16:06:01 +0200 Subject: Prepared sinksh trace --- sinksh/CMakeLists.txt | 1 + sinksh/sinksh_utils.cpp | 14 ++++--- sinksh/sinksh_utils.h | 1 + sinksh/syntax_modules/sink_trace.cpp | 72 ++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 sinksh/syntax_modules/sink_trace.cpp (limited to 'sinksh') diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt index e7d3b6e..f0e2f6c 100644 --- a/sinksh/CMakeLists.txt +++ b/sinksh/CMakeLists.txt @@ -15,6 +15,7 @@ set(sink_cli_SRCS syntax_modules/sink_stat.cpp syntax_modules/sink_sync.cpp syntax_modules/sink_show.cpp + syntax_modules/sink_trace.cpp sinksh_utils.cpp repl/repl.cpp repl/replStates.cpp diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 091eb38..2a6f628 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -113,6 +113,14 @@ QStringList resourceIds(State &state) return resources; } +QStringList debugareaCompleter(const QStringList &, const QString &fragment, State &state) +{ + QStringList list; + list << "foo.bar" << "tar.war" << "bluub"; + // return Utils::filteredCompletions(debugAreas(state), fragment); + return Utils::filteredCompletions(list, fragment); +} + QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) { return Utils::filteredCompletions(resourceIds(state), fragment); @@ -120,11 +128,7 @@ QStringList resourceCompleter(const QStringList &, const QString &fragment, Stat QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) { - static QStringList types = QStringList() << "resource" - << "folder" - << "mail" - << "event" - << "account"; + static QStringList types = s_types; if (commands.count() == 1) { return Utils::filteredCompletions(s_types, fragment); } diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h index b5b6f3c..0a47661 100644 --- a/sinksh/sinksh_utils.h +++ b/sinksh/sinksh_utils.h @@ -40,6 +40,7 @@ QStringList resourceIds(); QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); +QStringList debugareaCompleter(const QStringList &, const QString &fragment, State &state); QMap keyValueMapFromArgs(const QStringList &args); /** diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp new file mode 100644 index 0000000..e7b92de --- /dev/null +++ b/sinksh/syntax_modules/sink_trace.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include // tr() +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkTrace +{ + +bool trace(const QStringList &args, State &state) +{ + // if (args.isEmpty()) { + // state.printError(QObject::tr("Specifiy a debug area to trace.")); + // return false; + // } + // + // + qDebug() << "Trace arguments: " << args; + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + // Sink::Log::setDebugOutputFilter(Sink::Log::FilterType::Area, "filter"); + + return true; +} + +bool traceOff(const QStringList &args, State &state) +{ + Sink::Log::setDebugOutputLevel(Sink::Log::Log); + qDebug() << "Turned trace off: " << args; + return true; +} + +Syntax::List syntax() +{ + Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive); + trace.completer = &SinkshUtils::debugareaCompleter; + + trace.children << Syntax("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); + + return Syntax::List() << trace; +} + +REGISTER_SYNTAX(SinkTrace) + +} -- cgit v1.2.3 From 3c05b5816aa0fb978686b0ed16a02336e0981a0e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 23:40:52 +0200 Subject: sinksh trace command including autocompletion The sinksh command allows to easily turn tracing for certain areas on or off. --- sinksh/sinksh_utils.cpp | 6 ++--- sinksh/syntax_modules/sink_trace.cpp | 44 +++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 20 deletions(-) (limited to 'sinksh') diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 2a6f628..14b0aab 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -21,6 +21,7 @@ #include "sinksh_utils.h" #include "common/store.h" +#include "common/log.h" #include "utils.h" @@ -115,10 +116,7 @@ QStringList resourceIds(State &state) QStringList debugareaCompleter(const QStringList &, const QString &fragment, State &state) { - QStringList list; - list << "foo.bar" << "tar.war" << "bluub"; - // return Utils::filteredCompletions(debugAreas(state), fragment); - return Utils::filteredCompletions(list, fragment); + return Utils::filteredCompletions(Sink::Log::debugAreas().toList(), fragment); } QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp index e7b92de..d480254 100644 --- a/sinksh/syntax_modules/sink_trace.cpp +++ b/sinksh/syntax_modules/sink_trace.cpp @@ -35,34 +35,46 @@ namespace SinkTrace { -bool trace(const QStringList &args, State &state) +bool traceOff(const QStringList &args, State &state) { - // if (args.isEmpty()) { - // state.printError(QObject::tr("Specifiy a debug area to trace.")); - // return false; - // } - // - // - qDebug() << "Trace arguments: " << args; - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); - // Sink::Log::setDebugOutputFilter(Sink::Log::FilterType::Area, "filter"); - + Sink::Log::setDebugOutputLevel(Sink::Log::Log); + qDebug() << "Turned trace off: " << args; return true; } -bool traceOff(const QStringList &args, State &state) +bool traceOn(const QStringList &args, State &state) { - Sink::Log::setDebugOutputLevel(Sink::Log::Log); - qDebug() << "Turned trace off: " << args; + if (args.isEmpty()) { + state.printError(QObject::tr("Specifiy a debug area to trace: ") + Sink::Log::debugAreas().toList().join(", ")); + return false; + } + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + QByteArrayList filter; + for (const auto &arg : args) { + filter << arg.toLatin1(); + } + Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); return true; } +bool trace(const QStringList &args, State &state) +{ + return traceOn(args, state); +} + + Syntax::List syntax() { Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive); - trace.completer = &SinkshUtils::debugareaCompleter; + trace.completer = &SinkshUtils::debugareaCompleter; + + Syntax traceOff("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); + traceOff.completer = &SinkshUtils::debugareaCompleter; + trace.children << traceOff; - trace.children << Syntax("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); + Syntax traceOn("on", QObject::tr("Turns on trace output."), &SinkTrace::traceOn, Syntax::NotInteractive); + traceOn.completer = &SinkshUtils::debugareaCompleter; + trace.children << traceOn; return Syntax::List() << trace; } -- cgit v1.2.3 From 9317fbffeab4a8c258acb1116eb12fbded7053d8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 8 Jul 2016 11:01:48 +0200 Subject: Control debugoutput during tests with sinksh. --- sinksh/syntax_modules/sink_trace.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'sinksh') diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp index d480254..8bd52a0 100644 --- a/sinksh/syntax_modules/sink_trace.cpp +++ b/sinksh/syntax_modules/sink_trace.cpp @@ -31,6 +31,7 @@ #include "sinksh_utils.h" #include "state.h" #include "syntaxtree.h" +#include "iostream" namespace SinkTrace { @@ -38,22 +39,24 @@ namespace SinkTrace bool traceOff(const QStringList &args, State &state) { Sink::Log::setDebugOutputLevel(Sink::Log::Log); - qDebug() << "Turned trace off: " << args; + std::cout << "Turned trace off." << std::endl; return true; } bool traceOn(const QStringList &args, State &state) { - if (args.isEmpty()) { - state.printError(QObject::tr("Specifiy a debug area to trace: ") + Sink::Log::debugAreas().toList().join(", ")); - return false; - } Sink::Log::setDebugOutputLevel(Sink::Log::Trace); - QByteArrayList filter; - for (const auto &arg : args) { - filter << arg.toLatin1(); + if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) { + Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList()); + std::cout << "Set trace filter to: *" << std::endl; + } else { + QByteArrayList filter; + for (const auto &arg : args) { + filter << arg.toLatin1(); + } + Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); + std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl; } - Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); return true; } -- cgit v1.2.3 From ce2fd2666f084eebe443598f6f3740a02913091e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 11 Jul 2016 08:25:30 +0200 Subject: Read resources synchronously --- sinksh/sinksh_utils.cpp | 28 +++++++--------------------- sinksh/syntax_modules/sink_clear.cpp | 2 +- sinksh/syntax_modules/sink_remove.cpp | 2 +- sinksh/syntax_modules/sink_stat.cpp | 29 +++++------------------------ sinksh/syntax_modules/sink_sync.cpp | 2 +- 5 files changed, 15 insertions(+), 48 deletions(-) (limited to 'sinksh') diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 14b0aab..0e26c5a 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -89,28 +89,14 @@ QSharedPointer loadModel(const QString &type, Sink::Query qu return model; } -QStringList resourceIds(State &state) +QStringList resourceIds() { - QStringList resources; Sink::Query query; query.liveQuery = false; - auto model = SinkshUtils::loadModel("resource", query); - - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources](const QModelIndex &index, int start, int end) mutable { - for (int i = start; i <= end; i++) { - auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); - resources << object->identifier(); - } - }); - - QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { - if (roles.contains(Sink::Store::ChildrenFetchedRole)) { - state.commandFinished(); - } - }); - - state.commandStarted(); - + QStringList resources; + for (const auto &r : getStore("resource").read(query)) { + resources << r.identifier(); + } return resources; } @@ -121,7 +107,7 @@ QStringList debugareaCompleter(const QStringList &, const QString &fragment, Sta QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) { - return Utils::filteredCompletions(resourceIds(state), fragment); + return Utils::filteredCompletions(resourceIds(), fragment); } QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) @@ -131,7 +117,7 @@ QStringList resourceOrTypeCompleter(const QStringList &commands, const QString & return Utils::filteredCompletions(s_types, fragment); } - return Utils::filteredCompletions(resourceIds(state), fragment); + return Utils::filteredCompletions(resourceIds(), fragment); } QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) diff --git a/sinksh/syntax_modules/sink_clear.cpp b/sinksh/syntax_modules/sink_clear.cpp index 72d9a14..1537ecd 100644 --- a/sinksh/syntax_modules/sink_clear.cpp +++ b/sinksh/syntax_modules/sink_clear.cpp @@ -50,7 +50,7 @@ bool clear(const QStringList &args, State &state) Syntax::List syntax() { - Syntax clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &SinkClear::clear); + Syntax clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &SinkClear::clear, Syntax::NotInteractive); clear.completer = &SinkshUtils::resourceCompleter; return Syntax::List() << clear; diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp index b374824..d474518 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp @@ -98,7 +98,7 @@ bool resource(const QStringList &args, State &state) Syntax::List syntax() { Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); - Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource);//, Syntax::EventDriven); + Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); resource.completer = &SinkshUtils::resourceCompleter; remove.children << resource; diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index 06586d9..9f0fe44 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp @@ -70,30 +70,11 @@ bool statAllResources(State &state) { Sink::Query query; query.liveQuery = false; - auto model = SinkshUtils::loadModel("resource", query); - - //SUUUPER ugly, but can't think of a better way with 2 glasses of wine in me on Christmas day - static QStringList resources; - resources.clear(); - - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) mutable { - for (int i = start; i <= end; i++) { - auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); - resources << object->identifier(); - } - }); - - QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { - if (roles.contains(Sink::Store::ChildrenFetchedRole)) { - statResources(resources, state); - state.commandFinished(); - } - }); - - if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { - return true; + QStringList resources; + for (const auto &r : SinkshUtils::getStore("resource").read(query)) { + resources << r.identifier(); } - + statResources(resources, state); return false; } @@ -109,7 +90,7 @@ bool stat(const QStringList &args, State &state) Syntax::List syntax() { - Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::EventDriven); + Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::NotInteractive); state.completer = &SinkshUtils::resourceCompleter; return Syntax::List() << state; diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index 3006202..208b869 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp @@ -56,7 +56,7 @@ bool sync(const QStringList &args, State &state) Syntax::List syntax() { - Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven ); + Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven); sync.completer = &SinkshUtils::resourceCompleter; return Syntax::List() << sync; -- cgit v1.2.3