Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libkineto/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ const seconds Config::maxRequestAge() const {

static std::string getTimeStr(time_point<system_clock> t) {
std::time_t t_c = system_clock::to_time_t(t);
return fmt::format("{:%H:%M:%S}", fmt::localtime(t_c));
std::tm tm{};
localtime_r(&t_c, &tm);
return fmt::format("{:%H:%M:%S}", tm);
}

static time_point<system_clock> handleRequestTimestamp(int64_t ms) {
Expand Down Expand Up @@ -588,8 +590,9 @@ void Config::printActivityProfilerConfig(std::ostream& s) const {
}
} else if (hasProfileStartTime()) {
std::time_t t_c = system_clock::to_time_t(requestTimestamp());
s << " Trace start time: "
<< fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(t_c));
std::tm tm{};
localtime_r(&t_c, &tm);
s << " Trace start time: " << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm);
s << " Trace duration: " << activitiesDuration().count() << "ms"
<< std::endl;
s << " Warmup duration: " << activitiesWarmupDuration().count() << "s"
Expand Down
4 changes: 3 additions & 1 deletion libkineto/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ Logger::Logger(int severity, int line, const char* filePath, int errnum)

const auto tt =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm tm_result;
localtime_r(&tt, &tm_result);
const char* file = strrchr(filePath, '/');
buf_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(tt)) << " "
buf_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm_result) << " "
<< processId(false) << ":" << systemThreadId(false) << " "
<< (file ? file + 1 : filePath) << ":" << line << "] ";
}
Expand Down
4 changes: 3 additions & 1 deletion libkineto/src/output_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ void EventCSVLogger::handleSample(
if (out_) {
auto now = system_clock::now();
auto time = system_clock::to_time_t(now);
std::tm tm_result;
localtime_r(&time, &tm_result);
for (const Stat& s : sample.stats) {
if (eventNames_.find(s.name) == eventNames_.end()) {
continue;
}
*out_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(time)) << ",";
*out_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm_result) << ",";
*out_ << sample.deltaMsec << ",";
*out_ << device << ",";
*out_ << s.name;
Expand Down
Loading