diff options
Diffstat (limited to 'tests/ingen_bench.cpp')
-rw-r--r-- | tests/ingen_bench.cpp | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/tests/ingen_bench.cpp b/tests/ingen_bench.cpp index 99abee97..ee890401 100644 --- a/tests/ingen_bench.cpp +++ b/tests/ingen_bench.cpp @@ -14,62 +14,61 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Atom.hpp" -#include "ingen/Clock.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/EngineBase.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Parser.hpp" -#include "ingen/World.hpp" -#include "ingen/runtime_paths.hpp" -#include "ingen/types.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Clock.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/EngineBase.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Parser.hpp> +#include <ingen/World.hpp> +#include <ingen/runtime_paths.hpp> #include <chrono> #include <cstdint> #include <cstdio> #include <cstdlib> +#include <exception> #include <iostream> #include <memory> #include <string> -using namespace std; -using namespace ingen; +namespace ingen::bench { +namespace { -unique_ptr<World> world; +std::unique_ptr<ingen::World> world; -static void +void ingen_try(bool cond, const char* msg) { if (!cond) { - cerr << "ingen: Error: " << msg << endl; + std::cerr << "ingen: Error: " << msg << "\n"; world.reset(); exit(EXIT_FAILURE); } } -static std::string +std::string real_path(const char* path) { char* const c_real_path = realpath(path, nullptr); - const std::string result(c_real_path ? c_real_path : ""); + std::string result(c_real_path ? c_real_path : ""); free(c_real_path); return result; } int -main(int argc, char** argv) +run(int argc, char** argv) { - set_bundle_path_from_code((void*)&ingen_try); - // Create world try { - world = unique_ptr<World>{new World(nullptr, nullptr, nullptr)}; + world = std::make_unique<ingen::World>(nullptr, nullptr, nullptr); + world->conf().add( "output", "output", 'O', "File to write benchmark output", ingen::Configuration::SESSION, world->forge().String, Atom()); world->load_configuration(argc, argv); } catch (std::exception& e) { - cout << "ingen: " << e.what() << endl; + std::cout << "ingen: " << e.what() << "\n"; return EXIT_FAILURE; } @@ -77,17 +76,19 @@ main(int argc, char** argv) const Atom& load = world->conf().option("load"); const Atom& out = world->conf().option("output"); if (!load.is_valid() || !out.is_valid()) { - cerr << "Usage: ingen_bench --load START_GRAPH --output OUT_FILE" << endl; + std::cerr << "Usage: ingen_bench --load START_GRAPH --output OUT_FILE\n"; return EXIT_FAILURE; } // Get start graph and output file options - const std::string start_graph = real_path((const char*)load.get_body()); - const std::string out_file = (const char*)out.get_body(); + const std::string start_graph = + real_path(static_cast<const char*>(load.get_body())); + + const std::string out_file = static_cast<const char*>(out.get_body()); if (start_graph.empty()) { - cerr << "error: initial graph '" - << ((const char*)load.get_body()) - << "' does not exist" << endl; + std::cerr << "error: initial graph '" + << static_cast<const char*>(load.get_body()) + << "' does not exist\n"; return EXIT_FAILURE; } @@ -96,24 +97,26 @@ main(int argc, char** argv) "Unable to load server module"); // Initialise engine - ingen_try(bool(world->engine()), + ingen_try(!!world->engine(), "Unable to create engine"); world->engine()->init(48000.0, 4096, 4096); world->engine()->activate(); // Load graph if (!world->parser()->parse_file(*world, *world->interface(), start_graph)) { - cerr << "error: failed to load initial graph " << start_graph << endl; + std::cerr << "error: failed to load initial graph " << start_graph + << "\n"; + return EXIT_FAILURE; } world->engine()->flush_events(std::chrono::milliseconds(20)); // Run benchmark // TODO: Set up real-time scheduling for this and worker threads - ingen::Clock clock; - const uint32_t n_test_frames = 1 << 20; - const uint32_t block_length = 4096; - const uint64_t t_start = clock.now_microseconds(); + const ingen::Clock clock; + const uint32_t n_test_frames = 1 << 20; + const uint32_t block_length = 4096; + const uint64_t t_start = clock.now_microseconds(); for (uint32_t i = 0; i < n_test_frames; i += block_length) { world->engine()->advance(block_length); world->engine()->run(block_length); @@ -122,14 +125,14 @@ main(int argc, char** argv) const uint64_t t_end = clock.now_microseconds(); // Write log output - std::unique_ptr<FILE, decltype(&fclose)> log{fopen(out_file.c_str(), "a"), - &fclose}; + const std::unique_ptr<FILE, int (*)(FILE*)> log{fopen(out_file.c_str(), "a"), + &fclose}; if (ftell(log.get()) == 0) { fprintf(log.get(), "# n_threads\trun_time\treal_time\n"); } - fprintf(log.get(), "%u\t%f\t%f\n", + fprintf(log.get(), "%d\t%f\t%f\n", world->conf().option("threads").get<int32_t>(), - (t_end - t_start) / 1000000.0, + static_cast<double>(t_end - t_start) / 1000000.0, (n_test_frames / 48000.0)); // Shut down @@ -137,3 +140,15 @@ main(int argc, char** argv) return EXIT_SUCCESS; } + +} // namespace +} // namespace ingen::bench + +int +main(int argc, char** argv) +{ + ingen::set_bundle_path_from_code( + reinterpret_cast<void (*)()>(&ingen::bench::ingen_try)); + + return ingen::bench::run(argc, argv); +} |