Skip to content

Commit

Permalink
flambda-backend: Add timestamp to GC log (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn authored Nov 18, 2023
1 parent 9a94e8f commit 7917f60
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions runtime/caml/osdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ extern char_os *caml_secure_getenv(char_os const *var);
cannot be determined, return -1. */
extern int caml_num_rows_fd(int fd);

/* Print a timestamp for verbose GC logs */
extern void caml_print_timestamp(FILE* channel, int formatted);

/* Memory management platform-specific operations */

void *caml_plat_mem_map(uintnat, uintnat, int);
Expand Down
3 changes: 3 additions & 0 deletions runtime/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ void caml_gc_message (int level, char *msg, ...)
if ((atomic_load_relaxed(&caml_verb_gc) & level) != 0){
va_list ap;
va_start(ap, msg);
if (caml_verb_gc & 0x1000) {
caml_print_timestamp(stderr, caml_verb_gc & 0x2000);
}
vfprintf (stderr, msg, ap);
va_end(ap);
fflush (stderr);
Expand Down
32 changes: 30 additions & 2 deletions runtime/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
#ifdef HAS_POSIX_MONOTONIC_CLOCK
#include <time.h>
#elif HAS_MACH_ABSOLUTE_TIME
#ifdef HAS_MACH_ABSOLUTE_TIME
#include <mach/mach_time.h>
#endif
#ifdef HAS_DIRENT
Expand Down Expand Up @@ -476,6 +475,35 @@ int caml_num_rows_fd(int fd)
#endif
}

void caml_print_timestamp(FILE* channel, int formatted)
{
struct timeval tv;
gettimeofday(&tv, NULL);
if (!formatted) {
fprintf(channel, "%ld.%06d ", (long)tv.tv_sec, (int)tv.tv_usec);
} else {
struct tm tm;
char tz[10] = "Z";
localtime_r(&tv.tv_sec, &tm);
if (tm.tm_gmtoff != 0) {
long tzhour = tm.tm_gmtoff / 60 / 60;
long tzmin = (tm.tm_gmtoff / 60) % 60;
if (tzmin < 0) {tzmin += 60; tzhour--;}
sprintf(tz, "%+03ld:%02ld", tzhour, tzmin);
}
fprintf(channel,
"[%04d-%02d-%02d %02d:%02d:%02d.%06d%s] ",
1900 + tm.tm_year,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
(int)tv.tv_usec,
tz);
}
}

void caml_init_os_params(void)
{
caml_plat_mmap_alignment = caml_plat_pagesize = sysconf(_SC_PAGESIZE);
Expand Down
5 changes: 5 additions & 0 deletions runtime/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ int caml_num_rows_fd(int fd)
return -1;
}

void caml_print_timestamp(FILE* channel, int formatted)
{
/* unimplemented */
}

/* UCRT clock function returns wall-clock time */
CAMLexport clock_t caml_win32_clock(void)
{
Expand Down

0 comments on commit 7917f60

Please sign in to comment.