Skip to content

Commit d9ffed7

Browse files
sraikund16facebook-github-bot
authored andcommitted
Omit Non Human Readable Names in Kineto (#1027)
Summary: When running with_stack there are instances where the JSON output is configured improperly because certain values are non-human readable. We should at least patch this by omitting such values until we find a long-term solution. Reviewed By: aaronenyeshi, mkyybx Differential Revision: D67923913
1 parent 4276833 commit d9ffed7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libkineto/src/output_json.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ void ChromeTraceLogger::sanitizeStrForJSON(std::string& value) {
7979
value.erase(std::remove(value.begin(), value.end(), '\n'), value.end());
8080
}
8181

82+
static void sanitizeForNonReadableChars(std::string& value) {
83+
for (auto& c : value) {
84+
if (!std::isprint(c)) {
85+
LOG(WARNING) << "Non JSON compliant character found in string: " << value
86+
<< " Replacing with 'unknown'";
87+
value = "unknown";
88+
break;
89+
}
90+
}
91+
}
92+
8293
static inline int32_t sanitizeTid(int32_t tid) {
8394
// Convert all negative tids to its positive value. Create a specific case
8495
// for INT_MIN so it is obvious how it is being handled.
@@ -521,6 +532,7 @@ void ChromeTraceLogger::handleActivity(const libkineto::ITraceActivity& op) {
521532
// TODO: Remove this once legacy tools are updated.
522533
std::string op_name = op.name() == "kernel" ? "Kernel" : op.name();
523534
sanitizeStrForJSON(op_name);
535+
sanitizeForNonReadableChars(op_name);
524536

525537
// clang-format off
526538
ts = transToRelativeTime(ts);

0 commit comments

Comments
 (0)