aboutsummaryrefslogtreecommitdiff
path: root/tests/framework
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-01-05 10:59:12 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commit6db0ff5b4bb49f834c7caa532a7feab228df10f9 (patch)
tree36c32ab3e94a86752d6b73c4a3503b191431d586 /tests/framework
parentfde97fb84943d0328c2c532d117e9b875149f27e (diff)
downloadComputeLibrary-6db0ff5b4bb49f834c7caa532a7feab228df10f9.tar.gz
COMPMID-771 Allow examples to be profiled
Change-Id: I180281e796e1670b9ad391d82d66ecde0119ef78 Note: this is for internal use only which is why I think the hackiness of RunExample.cpp is acceptable. Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115154 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'tests/framework')
-rw-r--r--tests/framework/command_line/CommonOptions.cpp158
-rw-r--r--tests/framework/command_line/CommonOptions.h88
2 files changed, 246 insertions, 0 deletions
diff --git a/tests/framework/command_line/CommonOptions.cpp b/tests/framework/command_line/CommonOptions.cpp
new file mode 100644
index 0000000000..631981be3d
--- /dev/null
+++ b/tests/framework/command_line/CommonOptions.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "CommonOptions.h"
+
+#include "../Framework.h"
+#include "../printers/Printers.h"
+#include "CommandLineParser.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace framework
+{
+CommonOptions::CommonOptions(CommandLineParser &parser)
+ : help(parser.add_option<ToggleOption>("help")),
+ instruments(),
+ iterations(parser.add_option<SimpleOption<int>>("iterations", 1)),
+ threads(parser.add_option<SimpleOption<int>>("threads", 1)),
+ log_format(),
+ log_file(parser.add_option<SimpleOption<std::string>>("log-file")),
+ log_level(),
+ throw_errors(parser.add_option<ToggleOption>("throw-errors")),
+ color_output(parser.add_option<ToggleOption>("color-output", true)),
+ pretty_console(parser.add_option<ToggleOption>("pretty-console", false)),
+ json_file(parser.add_option<SimpleOption<std::string>>("json-file")),
+ pretty_file(parser.add_option<SimpleOption<std::string>>("pretty-file")),
+ log_streams()
+{
+ Framework &framework = Framework::get();
+ std::set<InstrumentsDescription> allowed_instruments
+ {
+ std::pair<InstrumentType, ScaleFactor>(InstrumentType::ALL, ScaleFactor::NONE),
+ std::pair<InstrumentType, ScaleFactor>(InstrumentType::NONE, ScaleFactor::NONE),
+ };
+
+ for(const auto &type : framework.available_instruments())
+ {
+ allowed_instruments.insert(type);
+ }
+
+ std::set<LogFormat> supported_log_formats
+ {
+ LogFormat::NONE,
+ LogFormat::PRETTY,
+ LogFormat::JSON,
+ };
+
+ std::set<LogLevel> supported_log_levels
+ {
+ LogLevel::NONE,
+ LogLevel::CONFIG,
+ LogLevel::TESTS,
+ LogLevel::ERRORS,
+ LogLevel::DEBUG,
+ LogLevel::MEASUREMENTS,
+ LogLevel::ALL,
+ };
+
+ instruments = parser.add_option<EnumListOption<InstrumentsDescription>>("instruments", allowed_instruments, std::initializer_list<InstrumentsDescription> { std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::NONE) });
+ log_format = parser.add_option<EnumOption<LogFormat>>("log-format", supported_log_formats, LogFormat::PRETTY);
+ log_level = parser.add_option<EnumOption<LogLevel>>("log-level", supported_log_levels, LogLevel::ALL);
+
+ help->set_help("Show this help message");
+ instruments->set_help("Set the profiling instruments to use");
+ iterations->set_help("Number of iterations per test case");
+ threads->set_help("Number of threads to use");
+ log_format->set_help("Output format for measurements and failures (affects only log-file)");
+ log_file->set_help("Write output to file instead of to the console (affected by log-format)");
+ log_level->set_help("Verbosity of the output");
+ throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
+ color_output->set_help("Produce colored output on the console");
+ pretty_console->set_help("Produce pretty output on the console");
+ json_file->set_help("Write output to a json file.");
+ pretty_file->set_help("Write output to a text file");
+}
+std::vector<std::unique_ptr<Printer>> CommonOptions::create_printers()
+{
+ std::vector<std::unique_ptr<Printer>> printers;
+
+ if(pretty_console->value() && (log_file->is_set() || log_format->value() != LogFormat::PRETTY))
+ {
+ auto pretty_printer = support::cpp14::make_unique<PrettyPrinter>();
+ pretty_printer->set_color_output(color_output->value());
+ printers.push_back(std::move(pretty_printer));
+ }
+
+ std::unique_ptr<Printer> printer;
+ switch(log_format->value())
+ {
+ case LogFormat::JSON:
+ printer = support::cpp14::make_unique<JSONPrinter>();
+ break;
+ case LogFormat::NONE:
+ break;
+ case LogFormat::PRETTY:
+ default:
+ auto pretty_printer = support::cpp14::make_unique<PrettyPrinter>();
+ // Don't use colours if we print to a file:
+ pretty_printer->set_color_output((!log_file->is_set()) && color_output->value());
+ printer = std::move(pretty_printer);
+ break;
+ }
+
+ if(log_file->is_set())
+ {
+ log_streams.push_back(std::make_shared<std::ofstream>(log_file->value()));
+ if(printer != nullptr)
+ {
+ printer->set_stream(*log_streams.back().get());
+ }
+ }
+
+ if(printer != nullptr)
+ {
+ printers.push_back(std::move(printer));
+ }
+
+ if(json_file->is_set())
+ {
+ printers.push_back(support::cpp14::make_unique<JSONPrinter>());
+ log_streams.push_back(std::make_shared<std::ofstream>(json_file->value()));
+ printers.back()->set_stream(*log_streams.back().get());
+ }
+
+ if(pretty_file->is_set())
+ {
+ printers.push_back(support::cpp14::make_unique<PrettyPrinter>());
+ log_streams.push_back(std::make_shared<std::ofstream>(pretty_file->value()));
+ printers.back()->set_stream(*log_streams.back().get());
+ }
+
+ return printers;
+}
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/framework/command_line/CommonOptions.h b/tests/framework/command_line/CommonOptions.h
new file mode 100644
index 0000000000..2da2c99874
--- /dev/null
+++ b/tests/framework/command_line/CommonOptions.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_TEST_COMMONOPTIONS
+#define ARM_COMPUTE_TEST_COMMONOPTIONS
+
+#include "../instruments/Instruments.h"
+#include "CommandLineOptions.h"
+#include <memory>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace framework
+{
+class CommandLineParser;
+class Printer;
+enum class LogFormat;
+enum class LogLevel;
+
+/** Common command line options used to configure the framework
+ *
+ * The options in this object get populated when "parse()" is called on the parser used to construct it.
+ * The expected workflow is:
+ *
+ * CommandLineParser parser;
+ * CommonOptions options( parser );
+ * parser.parse(argc, argv);
+ * if(options.log_level->value() > LogLevel::NONE) --> Use the options values
+ */
+class CommonOptions
+{
+public:
+ /** Constructor
+ *
+ * @param[in,out] parser A parser on which "parse()" hasn't been called yet.
+ */
+ CommonOptions(CommandLineParser &parser);
+ CommonOptions(const CommonOptions &) = delete;
+ CommonOptions &operator=(const CommonOptions &) = delete;
+ /** Create the printers based on parsed command line options
+ *
+ * @pre "parse()" has been called on the parser used to construct this object
+ *
+ * @return List of printers
+ */
+ std::vector<std::unique_ptr<Printer>> create_printers();
+
+ ToggleOption *help;
+ EnumListOption<InstrumentsDescription> *instruments;
+ SimpleOption<int> *iterations;
+ SimpleOption<int> *threads;
+ EnumOption<LogFormat> *log_format;
+ SimpleOption<std::string> *log_file;
+ EnumOption<LogLevel> *log_level;
+ ToggleOption *throw_errors;
+ ToggleOption *color_output;
+ ToggleOption *pretty_console;
+ SimpleOption<std::string> *json_file;
+ SimpleOption<std::string> *pretty_file;
+ std::vector<std::shared_ptr<std::ofstream>> log_streams;
+};
+
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_TEST_COMMONOPTIONS */