Skip to content

Commit cd7cc03

Browse files
chaekitfacebook-github-bot
authored andcommitted
add JSON-formatted metadata for ClientTraceActivity (#164)
Summary: Pull Request resolved: #164 Plan is to deprecate ClientTraceActivity and use a single concrete data structure to log all client side activities :`GenericTraceActivity`. CTA has a lot of explicit fields for metadata that are rarely used which results in sparse definition of activities. Instead of adding a new field, encode the key/value as a string. Note, more type-safe and rich alternative is `std::map` but we are not using it for performance reason. Reviewed By: gdankel Differential Revision: D27298829 fbshipit-source-id: ee7380db1b5c9f6dbb5ff65acf96b0cc08efc311
1 parent fda47c7 commit cd7cc03

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

libkineto/include/ClientTraceActivity.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
#pragma once
99

10+
#include <fmt/format.h>
1011
#include <string>
1112
#include <thread>
13+
#include <vector>
1214

1315
#include "TraceActivity.h"
1416

@@ -56,6 +58,16 @@ struct ClientTraceActivity : TraceActivity {
5658
// Unimplemented by default
5759
}
5860

61+
// Encode client side metadata as a key/value string.
62+
void addMetadata(const std::string& key, const std::string& value) {
63+
auto kv = fmt::format("\"{}\": {}", key, value);
64+
metadata_.push_back(std::move(kv));
65+
}
66+
67+
[[nodiscard]] const std::string getMetadata() const {
68+
return fmt::format("{}", fmt::join(metadata_, ", "));
69+
}
70+
5971
int64_t startTime{0};
6072
int64_t endTime{0};
6173
int64_t correlation{0};
@@ -72,6 +84,9 @@ struct ClientTraceActivity : TraceActivity {
7284
std::string inputNames;
7385
std::string outputNames;
7486
std::string callStack;
87+
88+
private:
89+
std::vector<std::string> metadata_;
7590
};
7691

7792
} // namespace libkineto

0 commit comments

Comments
 (0)