From c725c042b8ba9dce30d76ad7deb0b474a6ebb8a8 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 7 Aug 2023 14:19:34 +0100 Subject: [PATCH] Add method to log scheduling decision (#348) * decisions: add method to debug print a decision * tests: test print function in tests --- .../batch-scheduler/SchedulingDecision.h | 2 ++ src/batch-scheduler/SchedulingDecision.cpp | 19 +++++++++++++++++++ .../test_scheduling_decisions.cpp | 3 +++ 3 files changed, 24 insertions(+) diff --git a/include/faabric/batch-scheduler/SchedulingDecision.h b/include/faabric/batch-scheduler/SchedulingDecision.h index d28475a10..5a1da6745 100644 --- a/include/faabric/batch-scheduler/SchedulingDecision.h +++ b/include/faabric/batch-scheduler/SchedulingDecision.h @@ -100,6 +100,8 @@ class SchedulingDecision int32_t groupIdx); std::set uniqueHosts(); + + void print(); }; } diff --git a/src/batch-scheduler/SchedulingDecision.cpp b/src/batch-scheduler/SchedulingDecision.cpp index d98e41b1e..4467732e3 100644 --- a/src/batch-scheduler/SchedulingDecision.cpp +++ b/src/batch-scheduler/SchedulingDecision.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace faabric::batch_scheduler { @@ -57,4 +58,22 @@ std::set SchedulingDecision::uniqueHosts() { return std::set(hosts.begin(), hosts.end()); } + +void SchedulingDecision::print() +{ + SPDLOG_DEBUG("-------------- Decision for App: {} ----------------", appId); + SPDLOG_DEBUG("MsgId\tAppId\tGroupId\tGrIdx\tHostIp"); + // Modulo a big number so that we can get the UUIDs to fit within one tab + int formatBase = 1e6; + for (int i = 0; i < hosts.size(); i++) { + SPDLOG_DEBUG("{}\t{}\t{}\t{}\t{}", + messageIds.at(i) % formatBase, + appId % formatBase, + groupId % formatBase, + groupIdxs.at(i), + hosts.at(i)); + } + SPDLOG_DEBUG("------------- End Decision for App {} ---------------", + appId); +} } diff --git a/tests/test/batch-scheduler/test_scheduling_decisions.cpp b/tests/test/batch-scheduler/test_scheduling_decisions.cpp index fe8ddb5c6..e36694812 100644 --- a/tests/test/batch-scheduler/test_scheduling_decisions.cpp +++ b/tests/test/batch-scheduler/test_scheduling_decisions.cpp @@ -88,6 +88,9 @@ TEST_CASE_METHOD(ConfFixture, "Test building scheduling decisions", "[util]") REQUIRE(newDecision == decision); newDecision.groupId = 1338; REQUIRE(newDecision != decision); + + // We can print scheduling decisions + REQUIRE_NOTHROW(decision.print()); } TEST_CASE("Test converting point-to-point mappings to scheduling decisions",