Skip to content

Commit be90296

Browse files
sraikund16facebook-github-bot
authored andcommitted
Get rid of fmt::localtime (pytorch#1092)
Summary: Pull Request resolved: pytorch#1092 fmt::localtime is deprecated. Use std for better compatability Reviewed By: malfet, ngimel Differential Revision: D75563129 fbshipit-source-id: 3ddf534878f25f48480fcd6e714bdd57ad27138d
1 parent 3a37788 commit be90296

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

libkineto/src/Config.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ const seconds Config::maxRequestAge() const {
296296

297297
static std::string getTimeStr(time_point<system_clock> t) {
298298
std::time_t t_c = system_clock::to_time_t(t);
299-
return fmt::format("{:%H:%M:%S}", fmt::localtime(t_c));
299+
std::tm tm{};
300+
localtime_r(&t_c, &tm);
301+
return fmt::format("{:%H:%M:%S}", tm);
300302
}
301303

302304
static time_point<system_clock> handleRequestTimestamp(int64_t ms) {
@@ -588,8 +590,9 @@ void Config::printActivityProfilerConfig(std::ostream& s) const {
588590
}
589591
} else if (hasProfileStartTime()) {
590592
std::time_t t_c = system_clock::to_time_t(requestTimestamp());
591-
s << " Trace start time: "
592-
<< fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(t_c));
593+
std::tm tm{};
594+
localtime_r(&t_c, &tm);
595+
s << " Trace start time: " << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm);
593596
s << " Trace duration: " << activitiesDuration().count() << "ms"
594597
<< std::endl;
595598
s << " Warmup duration: " << activitiesWarmupDuration().count() << "s"

libkineto/src/Logger.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ Logger::Logger(int severity, int line, const char* filePath, int errnum)
3939

4040
const auto tt =
4141
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
42+
std::tm tm_result;
43+
localtime_r(&tt, &tm_result);
4244
const char* file = strrchr(filePath, '/');
43-
buf_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(tt)) << " "
45+
buf_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm_result) << " "
4446
<< processId(false) << ":" << systemThreadId(false) << " "
4547
<< (file ? file + 1 : filePath) << ":" << line << "] ";
4648
}

libkineto/src/output_csv.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ void EventCSVLogger::handleSample(
5050
if (out_) {
5151
auto now = system_clock::now();
5252
auto time = system_clock::to_time_t(now);
53+
std::tm tm_result;
54+
localtime_r(&time, &tm_result);
5355
for (const Stat& s : sample.stats) {
5456
if (eventNames_.find(s.name) == eventNames_.end()) {
5557
continue;
5658
}
57-
*out_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(time)) << ",";
59+
*out_ << fmt::format("{:%Y-%m-%d %H:%M:%S}", tm_result) << ",";
5860
*out_ << sample.deltaMsec << ",";
5961
*out_ << device << ",";
6062
*out_ << s.name;

0 commit comments

Comments
 (0)