Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions projects/miopen/docs/how-to/debug-log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ environmental variables to control logging. Both variables are disabled by defau
* ``MIOPEN_ENABLE_LOGGING_ELAPSED_TIME``: Adds a timestamp to each log line that indicates the
time elapsed (in milliseconds) since the previous log message.

* ``MIOPEN_ENABLE_LOGGING_DATE_TIME``: Adds a timestamp to each log line that indicates the
system time (with milliseconds).

.. note::

If you require technical support, include the console log that is produced from these settings:
Expand Down
27 changes: 27 additions & 0 deletions projects/miopen/src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_ENABLE_LOGGING_MPMT)
/// Add timestamps to each log line.
/// Not useful with multi-process/multi-threaded apps.
MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_ENABLE_LOGGING_ELAPSED_TIME)
/// Add timestamps to each log line.
MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_ENABLE_LOGGING_DATE_TIME)
Comment thread
JonathanLichtnerAMD marked this conversation as resolved.

/// See LoggingLevel in the header.
MIOPEN_DECLARE_ENV_VAR_UINT64(MIOPEN_LOG_LEVEL)
Expand Down Expand Up @@ -117,6 +119,27 @@ inline float GetTimeDiff()
return rv;
}

inline std::string GetDateTimeMs()
{
auto now = std::chrono::system_clock::now();
Comment thread
cderb marked this conversation as resolved.
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
auto now_t = std::chrono::system_clock::to_time_t(now);

std::tm local_time{};
#if defined(_WIN32)
if(localtime_s(&local_time, &now_t) != 0)
return std::string{};
#else
if(localtime_r(&now_t, &local_time) == nullptr)
return std::string{};
#endif

std::ostringstream time_s;
time_s << std::put_time(&local_time, "%Y-%m-%dT%H:%M:%S");
time_s << "." << std::setfill('0') << std::setw(3) << ms.count() << "Z";
return time_s.str();
}

} // namespace

bool IsLoggingDebugQuiet()
Expand Down Expand Up @@ -195,6 +218,10 @@ std::string LoggingPrefix()
{
ss << std::fixed << std::setprecision(3) << std::setw(8) << GetTimeDiff();
}
if(env::enabled(MIOPEN_ENABLE_LOGGING_DATE_TIME))
{
ss << " (" << GetDateTimeMs() << ")";
Comment thread
cderb marked this conversation as resolved.
}
ss << ": ";
return ss.str();
}
Expand Down
Loading