-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1837780
commit 610d1c3
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <faabric/proto/faabric.pb.h> | ||
|
||
#include <list> | ||
#include <map> | ||
|
||
namespace faabric::util::tracing { | ||
enum RecordType | ||
{ | ||
MpiPerRankMessageCount | ||
}; | ||
|
||
class CallRecords | ||
{ | ||
public: | ||
void startRecording(const faabric::Message& msg); | ||
|
||
void stopRecording(faabric::Message& msg); | ||
|
||
void addRecord(int msgId, RecordType recordType, int idToIncrement); | ||
|
||
private: | ||
std::shared_ptr<faabric::Message> linkedMsg = nullptr; | ||
|
||
std::list<RecordType> onGoingRecordings; | ||
|
||
void loadRecordsToMessage(faabric::CallRecords& callRecords, | ||
const RecordType& recordType); | ||
|
||
// ----- Per record type data structures ----- | ||
|
||
std::map<int, int> perRankMsgCount; | ||
}; | ||
|
||
CallRecords& getCallRecords(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ faabric_lib(util | |
snapshot.cpp | ||
state.cpp | ||
string_tools.cpp | ||
tracing.cpp | ||
timing.cpp | ||
testing.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include <faabric/util/logging.h> | ||
#include <faabric/util/tracing.h> | ||
|
||
namespace faabric::util::tracing { | ||
void CallRecords::startRecording(const faabric::Message& msg) | ||
{ | ||
#ifndef NDEBUG | ||
if (linkedMsg != nullptr && linkedMsg->id() != msg.id()) { | ||
SPDLOG_ERROR("CallRecords already linked to a different message: (linked: {} != provided: {})", | ||
linkedMsg->id(), msg.id()); | ||
throw std::runtime_error("CallRecords linked to a different message"); | ||
} else if (linkedMsg == nullptr) { | ||
linkedMsg = std::make_shared<faabric::Message>(msg); | ||
} | ||
#else | ||
; | ||
#endif | ||
} | ||
|
||
void CallRecords::stopRecording(faabric::Message& msg) | ||
{ | ||
#ifndef NDEBUG | ||
if (linkedMsg == nullptr || linkedMsg->id() != msg.id()) { | ||
SPDLOG_ERROR("CallRecords not linked to the right message: (linked: {} != provided: {})", | ||
linkedMsg->id(), msg.id()); | ||
throw std::runtime_error("CallRecords linked to a different message"); | ||
} | ||
|
||
linkedMsg = nullptr; | ||
|
||
// Update the actual faabric message | ||
faabric::CallRecords recordsMsg; | ||
for (const auto& recordType : onGoingRecordings) { | ||
loadRecordsToMessage(recordsMsg, recordType); | ||
} | ||
|
||
// Update the original message | ||
*msg.mutable_records() = recordsMsg; | ||
#else | ||
; | ||
#endif | ||
} | ||
|
||
void CallRecords::loadRecordsToMessage(faabric::CallRecords& callRecords, | ||
const RecordType& recordType) | ||
{ | ||
#ifndef NDEBUG | ||
switch (recordType) { | ||
case (faabric::util::tracing::RecordType::MpiPerRankMessageCount): { | ||
faabric::MpiPerRankMessageCount msgCount; | ||
|
||
for (const auto& it : perRankMsgCount) { | ||
msgCount.add_ranks(it.first); | ||
msgCount.add_nummessages(it.second); | ||
} | ||
|
||
*callRecords.mutable_mpimsgcount() = msgCount; | ||
break; | ||
} | ||
default: { | ||
SPDLOG_ERROR("Unsupported record type: {}", recordType); | ||
throw std::runtime_error("Unsupported record type"); | ||
} | ||
} | ||
#else | ||
; | ||
#endif | ||
} | ||
|
||
void CallRecords::addRecord(int msgId, RecordType recordType, int idToIncrement) | ||
{ | ||
#ifndef NDEBUG | ||
// Check message id | ||
if (linkedMsg == nullptr || linkedMsg->id() != msgId) { | ||
SPDLOG_ERROR("CallRecords not linked to the right message: (linked: {} != provided: {})", | ||
linkedMsg->id(), msgId); | ||
throw std::runtime_error("CallRecords linked to a different message"); | ||
} | ||
|
||
// Add the record to the list of on going records if it is not there | ||
bool mustInit = false; | ||
auto it = std::find(onGoingRecordings.begin(), onGoingRecordings.end(), recordType); | ||
if (it == onGoingRecordings.end()) { | ||
onGoingRecordings.push_back(recordType); | ||
mustInit = true; | ||
} | ||
|
||
// Finally increment the corresponding record list | ||
switch (recordType) { | ||
case (faabric::util::tracing::RecordType::MpiPerRankMessageCount): { | ||
if (mustInit) { | ||
for (int i = 0; i < linkedMsg->mpiworldsize(); i++) { | ||
perRankMsgCount[i] = 0; | ||
} | ||
} | ||
|
||
++perRankMsgCount.at(idToIncrement); | ||
break; | ||
} | ||
default: { | ||
SPDLOG_ERROR("Unsupported record type: {}", recordType); | ||
throw std::runtime_error("Unsupported record type"); | ||
} | ||
} | ||
#else | ||
; | ||
#endif | ||
} | ||
|
||
|
||
CallRecords& getCallRecords() | ||
{ | ||
static thread_local CallRecords callRecords; | ||
return callRecords; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <catch.hpp> | ||
|
||
#include "faabric_utils.h" | ||
|
||
#include <faabric/proto/faabric.pb.h> | ||
#include <faabric/scheduler/MpiWorld.h> | ||
#include <faabric/util/logging.h> // DELETE MEE | ||
#include <faabric/util/macros.h> | ||
#include <faabric/util/tracing.h> | ||
|
||
namespace tests { | ||
TEST_CASE_METHOD(MpiTestFixture, | ||
"Test tracing the number of MPI messages", | ||
"[util][tracing]") | ||
{ | ||
faabric::util::tracing::getCallRecords().startRecording(msg); | ||
|
||
// Send one message | ||
int rankA1 = 0; | ||
int rankA2 = 1; | ||
MPI_Status status{}; | ||
|
||
std::vector<int> messageData = { 0, 1, 2 }; | ||
auto buffer = new int[messageData.size()]; | ||
|
||
world.send( | ||
rankA1, rankA2, BYTES(messageData.data()), MPI_INT, messageData.size()); | ||
world.recv( | ||
rankA1, rankA2, BYTES(buffer), MPI_INT, messageData.size(), &status); | ||
|
||
// Stop recording and check we have only recorded one message | ||
faabric::util::tracing::getCallRecords().stopRecording(msg); | ||
REQUIRE(msg.has_records()); | ||
REQUIRE(msg.records().has_mpimsgcount()); | ||
REQUIRE(msg.records().mpimsgcount().ranks_size() == worldSize); | ||
for (int i = 0; i < worldSize; i++) { | ||
if (i == rankA2) { | ||
REQUIRE(msg.records().mpimsgcount().nummessages(i) == 1); | ||
} else { | ||
REQUIRE(msg.records().mpimsgcount().nummessages(i) == 0); | ||
} | ||
} | ||
} | ||
} |