Closed ysbaddaden closed 2 weeks ago
the
Thread#current_thread?
commit could be extracted into a distinct PR.
Then let's do that, please 🙏
@straight-shoota following your review, I made the following changes:
I replaced the Crystal.trace
macro with a couple def methods (one that yield and one that don't), which led to:
operation
arg is now always a String :+1: I replaced the LibC.WideCharToMultiByte
call with a pure Crystal alternative that leverages String.each_utf16_char(slice, &)
and loops to avoid a buffer overflow and splitting a multibyte char across multiple prints.
Thanks @straight-shoota. I applied all your suggestions!
I noticed that one macro used constant.downcase
while the other used lowerscore
in a completely different place, so I grouped the logic into the Tracing::Section enum as a couple methods: .from_id(slice)
and #to_id
(instead of #id
) and now both are using lowerscore
.
Implements tracing of the garbage collector and the scheduler as per #14618
Tracing is enabled by compiling with
-Dtracing
then individual tracing must be enabled at runtime with theCRYSTAL_TRACE
environment variable that is a comma separated list of sections to enable, for example:none
to disable everything (by default)gc
sched
gc,sched
all
to enable everythingThe traces are printed to the standard error by default, but this can be changed at runtime with the
CRYSTAL_TRACE_FILE
environment variable. For exampletrace.log
. You can also redirect the standard error to a file (e.g.2> trace.log
on UNIX shell).Technical note: tracing happens before the stdlib is initialized, so the implementation must rely on some
LibC
methods directly (i.e. read environment variable, write to file descriptor) and can't use the core/stdlib abstractions.Note: theDone: #14660Thread#current_thread?
commit could be extracted into a distinct PR.