Skip to content

Commit

Permalink
Merge pull request #14293 from cjjdespres/time-zone-emission
Browse files Browse the repository at this point in the history
Use omrstr_current_time_zone in javadump, emit time zone in the jitserver verbose log
  • Loading branch information
keithc-ca authored Jan 20, 2022
2 parents 5e8d8ce + b8b1e5e commit 536acc0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
35 changes: 34 additions & 1 deletion runtime/compiler/runtime/Listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,42 @@ static int32_t J9THREAD_PROC listenerThreadProc(void * entryarg)
{
OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);
char timestamp[32];
char zoneName[32];
int32_t zoneSecondsEast = 0;
TR_VerboseLog::CriticalSection vlogLock;

omrstr_ftime_ex(timestamp, sizeof(timestamp), "%b %d %H:%M:%S %Y", j9time_current_time_millis(), OMRSTR_FTIME_FLAG_LOCAL);
TR_VerboseLog::writeLineLocked(TR_Vlog_INFO, "StartTime: %s", timestamp);
TR_VerboseLog::writeLine(TR_Vlog_INFO, "StartTime: %s", timestamp);

TR_VerboseLog::write(TR_Vlog_INFO, "TimeZone: ");
if (0 != omrstr_current_time_zone(&zoneSecondsEast, zoneName, sizeof(zoneName)))
{
TR_VerboseLog::write("(unavailable)");
}
else
{
/* Write UTC[+/-]hr:min (zoneName) to the log. */
TR_VerboseLog::write("UTC");

if (0 != zoneSecondsEast)
{
const char *format = (zoneSecondsEast > 0) ? "+%d" : "-%d";
int32_t offset = ((zoneSecondsEast > 0) ? zoneSecondsEast : -zoneSecondsEast) / 60;
int32_t hours = offset / 60;
int32_t minutes = offset % 60;

TR_VerboseLog::write(format, hours);
if (0 != minutes)
{
TR_VerboseLog::write(":%02d", minutes);
}
}
if ('\0' != *zoneName)
{
TR_VerboseLog::write(" (%s)", zoneName);
}
TR_VerboseLog::write("\n");
}
}

J9CompileDispatcher handler(jitConfig);
Expand Down
47 changes: 3 additions & 44 deletions runtime/rasdump/javadump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
*******************************************************************************/

/* Includes */
#if defined(J9ZOS390)
#define _LARGE_TIME_API
#endif /* defined(J9ZOS390) */
#include <time.h>
#if defined(AIXPPC)
#include <sys/time.h>
#endif /* defined(AIXPPC) */
Expand Down Expand Up @@ -654,48 +650,11 @@ JavaCoreDumpWriter::writeTitleSection(void)
_OutputStream.writeInteger(now % 1000, ":%03d"); /* add the milliseconds */
_OutputStream.writeCharacters("\n");

bool zoneAvailable = false;
int32_t zoneSecondsEast = 0;
const char *zoneName = NULL;

#if defined(WIN32)
/* until a reliable mechanism is found, don't report timezone */
#elif defined(J9ZOS390) /* defined(WIN32) */
time64_t timeNow = time64(NULL);
struct tm utc;
struct tm local;

if ((NULL != gmtime64_r(&timeNow, &utc)) && (NULL != localtime64_r(&timeNow, &local))) {
zoneAvailable = true;
zoneSecondsEast = (int32_t)difftime64(timeNow, mktime64(&utc));
if (0 == local.tm_isdst) {
zoneName = tzname[0];
} else if (local.tm_isdst > 0) {
zoneName = tzname[1];
/* compensate for DST because difftime64() doesn't appear to do so */
zoneSecondsEast += 60 * 60;
}
}
#else /* defined(WIN32) */
time_t timeNow = time(NULL);
struct tm utc;
struct tm local;

if ((NULL != gmtime_r(&timeNow, &utc)) && (NULL != localtime_r(&timeNow, &local))) {
zoneAvailable = true;
zoneSecondsEast = (int32_t)difftime(timeNow, mktime(&utc));
if (0 == local.tm_isdst) {
zoneName = tzname[0];
} else if (local.tm_isdst > 0) {
zoneName = tzname[1];
/* compensate for DST because difftime() doesn't appear to do so */
zoneSecondsEast += 60 * 60;
}
}
#endif /* defined(WIN32) */
char zoneName[32];

_OutputStream.writeCharacters("1TITIMEZONE Timezone: ");
if (!zoneAvailable) {
if (0 != omrstr_current_time_zone(&zoneSecondsEast, zoneName, sizeof(zoneName))) {
_OutputStream.writeCharacters("(unavailable)");
} else {
_OutputStream.writeCharacters("UTC");
Expand All @@ -710,7 +669,7 @@ JavaCoreDumpWriter::writeTitleSection(void)
_OutputStream.writeInteger(minutes, ":%02d");
}
}
if ((NULL != zoneName) && ('\0' != *zoneName)) {
if ('\0' != *zoneName) {
_OutputStream.writeCharacters(" (");
_OutputStream.writeCharacters(zoneName);
_OutputStream.writeCharacters(")");
Expand Down

0 comments on commit 536acc0

Please sign in to comment.