Skip to content

Commit d3db4d6

Browse files
committed
Added option to query whether a metadatum is known, and only emit warning if it is, but could not be created
1 parent 02daee6 commit d3db4d6

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

graph/include/metadata/MetaData.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MCGManager;
3030
* A class *must* implement a static constexpr const char *key that contains the class
3131
* name as a string. This is used for registration in the MetaData field of the CgNode.
3232
*/
33-
template <class CRTPBase>
33+
template <class CRTPBase=void>
3434
class MetaDataFactory {
3535
public:
3636
template <class... T>
@@ -64,6 +64,22 @@ class MetaDataFactory {
6464

6565
friend CRTPBase;
6666

67+
/**
68+
* Checks whether a metadatas key is registered
69+
*
70+
* @param metadataKey the key of the metadat to search for
71+
* @return true if the key is known
72+
*/
73+
static bool isRegistered(const std::string& metadataKey) {
74+
for (const auto& [registeredMetadataName, _] : data()) {
75+
if (registeredMetadataName == metadataKey)
76+
return true;
77+
}
78+
return false;
79+
}
80+
81+
82+
6783
private:
6884
class Key {
6985
Key() = default;

graph/src/io/VersionFourMCGReader.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ std::unique_ptr<metacg::Callgraph> metacg::io::VersionFourMCGReader::read() {
178178
if (auto md = metacg::MetaData::create<>(mdKey, mdValJ, strToNode); md) {
179179
cg->addEdgeMetaData({nodeData.nodeId, calleeNode->getId()}, std::move(md));
180180
} else {
181-
errConsole->debug("Could not create edge metadata of type {} for edge {} to {}", mdKey, nodeData.nodeId, calleeNode->getId());
181+
if (MetaDataFactory<>::isRegistered(mdKey)) {
182+
errConsole->warn("Could not create edge metadata of type {} for edge {} to {}", mdKey, nodeData.nodeId,
183+
calleeNode->getId());
184+
}
182185
if (failedMetadataCb) {
183186
(*failedMetadataCb)(nodeData.nodeId, mdKey, mdValJ);
184187
}
@@ -193,7 +196,9 @@ std::unique_ptr<metacg::Callgraph> metacg::io::VersionFourMCGReader::read() {
193196
if (auto md = metacg::MetaData::create<>(mdKey, mdVal, strToNode); md) {
194197
node->addMetaData(std::move(md));
195198
} else {
196-
errConsole->debug("Could not create metadata of type {} for node {}", mdKey, node->getFunctionName());
199+
if (MetaDataFactory<>::isRegistered(mdKey)) {
200+
errConsole->warn("Could not create metadata of type {} for node {}", mdKey, node->getFunctionName());
201+
}
197202
if (failedMetadataCb) {
198203
(*failedMetadataCb)(node->getId(), mdKey, mdVal);
199204
}
@@ -209,7 +214,9 @@ std::unique_ptr<metacg::Callgraph> metacg::io::VersionFourMCGReader::read() {
209214
if (auto md = metacg::MetaData::create<>(mdKey, mdValJ, strToNode); md) {
210215
cg->addMetaData(std::move(md));
211216
} else {
212-
errConsole->debug("Could not create global metadata of type {}", mdKey);
217+
if (MetaDataFactory<>::isRegistered(mdKey)) {
218+
errConsole->warn("Could not create global metadata of type {}", mdKey);
219+
}
213220
if (failedMetadataCb) {
214221
(*failedMetadataCb)(std::nullopt, mdKey, mdValJ);
215222
}

0 commit comments

Comments
 (0)