Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp to GC log #2032

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 ocaml/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 ocaml/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 ocaml/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 ocaml/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
Loading