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 Crystal::Tracing for runtime tracing #14659

Merged
merged 19 commits into from
Jun 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b55d66c
Add Crystal::System::Thread.current_thread? + Thread#scheduler?
ysbaddaden May 27, 2024
824e2af
Initial Crystal.trace implementation
ysbaddaden May 27, 2024
eddc005
Line protocol with abstract metadata (named tuple)
ysbaddaden May 27, 2024
22f5aac
Trace: print to file (CRYSTAL_TRACE_FILE)
ysbaddaden May 27, 2024
d28e6ce
Fix: Crystal::Tracing.init shall return nil
ysbaddaden Jun 3, 2024
149f3d4
Prefer System.printf_error over LibC.dprintf
ysbaddaden Jun 4, 2024
c8fd378
Fix: no need to prefix the Crystal namespace
ysbaddaden Jun 4, 2024
cbb904f
Fix: remove unused @@startup_tick
ysbaddaden Jun 4, 2024
379b4a5
fixup! Trace: print to file (CRYSTAL_TRACE_FILE)
ysbaddaden Jun 4, 2024
a54c848
Merge branch 'master' into feature/tracing
straight-shoota Jun 6, 2024
5541f6e
Fix: leverage String.each_utf16_char instead of external C call
ysbaddaden Jun 13, 2024
11faaa3
Apply code review suggestion
ysbaddaden Jun 13, 2024
d214022
Replace macro with a couple methods
ysbaddaden Jun 13, 2024
9a9025c
fixup! Fix: leverage String.each_utf16_char instead of external C call
ysbaddaden Jun 13, 2024
9ce8adb
fixup! Replace macro with a couple methods
ysbaddaden Jun 13, 2024
34ee68d
Fix: don't overload Enum#to_s (use distinct method)
ysbaddaden Jun 13, 2024
e8648ef
Fix: use Pointer::Appender in print_error(Slice(UInt8))
ysbaddaden Jun 13, 2024
5b65aad
Fix: use ensure instead of tap so we still print the trace
ysbaddaden Jun 13, 2024
1dfe3c5
Refactor: Section.from_id(slice) and Section#to_id
ysbaddaden Jun 13, 2024
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
22 changes: 18 additions & 4 deletions src/crystal/system/print_error.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,25 @@ module Crystal::System
end

{% if flag?(:win32) %}
# Helper to print wide char slices (UTF-16) from the Win32 API as multibyte (UTF-8).
# Print a UTF-16 slice as multibyte (UTF-8).
def self.print_error(bytes : Slice(UInt16)) : Nil
utf8 = uninitialized UInt8[256]
len = LibC.WideCharToMultiByte(LibC::CP_UTF8, 0, bytes, bytes.size, utf8, utf8.size, nil, nil)
print_error utf8.to_slice[0...len]
utf8 = uninitialized UInt8[512]
len = 0

String.each_utf16_char(bytes) do |char|
# avoid buffer overun and splitting an unicode char
if len > utf8.size - char.bytesize
print_error utf8.to_slice
ysbaddaden marked this conversation as resolved.
Show resolved Hide resolved
len = 0
end

char.each_byte do |byte]
utf8.to_unsafe[len] = byte
len &+= 1
ysbaddaden marked this conversation as resolved.
Show resolved Hide resolved
end
end

print_error utf8.to_slice[0...len] if len > 0
end
{% end %}

Expand Down