Skip to content

Commit 70f735c

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: a1592484333e42f33fbe0805803cf91fa83b52b9
1 parent fda47c7 commit 70f735c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

libkineto/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ target_include_directories(kineto_base PUBLIC
112112
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>)
113113

114114
target_include_directories(kineto_api PUBLIC
115+
$<BUILD_INTERFACE:${FMT_INCLUDE_DIR}>
115116
$<BUILD_INTERFACE:${LIBKINETO_INCLUDE_DIR}>)
116117

117118
if(KINETO_LIBRARY_TYPE STREQUAL "default")

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

libkineto/libkineto_defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def get_libkineto_public_headers():
5353
return [
5454
"include/ActivityProfilerInterface.h",
5555
"include/ActivityType.h",
56+
"include/ClientTraceActivity.h",
5657
"include/ClientInterface.h",
5758
"include/TraceActivity.h",
5859
"include/TraceSpan.h",

0 commit comments

Comments
 (0)