Skip to content

Commit 6f35365

Browse files
committed
forward port #1229
1 parent 72538a4 commit 6f35365

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

ocaml/runtime/caml/osdeps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ extern char_os *caml_secure_getenv(char_os const *var);
103103
cannot be determined, return -1. */
104104
extern int caml_num_rows_fd(int fd);
105105

106+
/* Print a timestamp for verbose GC logs */
107+
extern void caml_print_timestamp(FILE* channel, int formatted);
108+
106109
/* Memory management platform-specific operations */
107110

108111
void *caml_plat_mem_map(uintnat, uintnat, int);

ocaml/runtime/misc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ void caml_gc_message (int level, char *msg, ...)
9797
if ((atomic_load_relaxed(&caml_verb_gc) & level) != 0){
9898
va_list ap;
9999
va_start(ap, msg);
100+
if (caml_verb_gc & 0x1000) {
101+
caml_print_timestamp(stderr, caml_verb_gc & 0x2000);
102+
}
100103
vfprintf (stderr, msg, ap);
101104
va_end(ap);
102105
fflush (stderr);

ocaml/runtime/unix.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,35 @@ int caml_num_rows_fd(int fd)
476476
#endif
477477
}
478478

479+
void caml_print_timestamp(FILE* channel, int formatted)
480+
{
481+
struct timeval tv;
482+
gettimeofday(&tv, NULL);
483+
if (!formatted) {
484+
fprintf(channel, "%ld.%06d ", (long)tv.tv_sec, (int)tv.tv_usec);
485+
} else {
486+
struct tm tm;
487+
char tz[10] = "Z";
488+
localtime_r(&tv.tv_sec, &tm);
489+
if (tm.tm_gmtoff != 0) {
490+
long tzhour = tm.tm_gmtoff / 60 / 60;
491+
long tzmin = (tm.tm_gmtoff / 60) % 60;
492+
if (tzmin < 0) {tzmin += 60; tzhour--;}
493+
sprintf(tz, "%+03ld:%02ld", tzhour, tzmin);
494+
}
495+
fprintf(channel,
496+
"[%04d-%02d-%02d %02d:%02d:%02d.%06d%s] ",
497+
1900 + tm.tm_year,
498+
tm.tm_mon + 1,
499+
tm.tm_mday,
500+
tm.tm_hour,
501+
tm.tm_min,
502+
tm.tm_sec,
503+
(int)tv.tv_usec,
504+
tz);
505+
}
506+
}
507+
479508
void caml_init_os_params(void)
480509
{
481510
caml_plat_mmap_alignment = caml_plat_pagesize = sysconf(_SC_PAGESIZE);

ocaml/runtime/win32.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,11 @@ int caml_num_rows_fd(int fd)
11071107
return -1;
11081108
}
11091109

1110+
void caml_print_timestamp(FILE* channel, int formatted)
1111+
{
1112+
/* unimplemented */
1113+
}
1114+
11101115
/* UCRT clock function returns wall-clock time */
11111116
CAMLexport clock_t caml_win32_clock(void)
11121117
{

0 commit comments

Comments
 (0)